diff --git a/adapter/khdf/linux/manager/src/hdf_kevent.c b/adapter/khdf/linux/manager/src/hdf_kevent.c index ba03f7365a87dcd964f5961b75ea23412b31d98f..bc55bcf4e3fce7e71178d8c58617a17bd1ab9bff 100644 --- a/adapter/khdf/linux/manager/src/hdf_kevent.c +++ b/adapter/khdf/linux/manager/src/hdf_kevent.c @@ -237,7 +237,7 @@ static int32_t KeventPmNotifierFn(struct notifier_block *nb, unsigned long actio ret = SendKevent(keventModule, HDF_SYSEVENT_CLASS_POWER, powerEvent, NULL, sync); if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: failed to notify userspace pm status"); + HDF_LOGE("%s: failed to notify userspace pm status", __func__); } return KernalSpacePmNotify(powerEvent); @@ -278,7 +278,7 @@ static int32_t KeventFbNotifierFn(struct notifier_block *nb, unsigned long event ret = SendKevent(keventModule, HDF_SYSEVENT_CLASS_POWER, powerEvent, NULL, sync); if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: failed to notify userspace pm status"); + HDF_LOGE("%s: failed to notify userspace pm status", __func__); } return KernalSpacePmNotify(powerEvent); diff --git a/adapter/khdf/linux/model/usb/host/src/usb_pnp_notify.c b/adapter/khdf/linux/model/usb/host/src/usb_pnp_notify.c index df7c366cd50cc3b4d4f752ef35835f47dda95e2f..eed4be0256cb8ea299676628c806df66cc4552f6 100644 --- a/adapter/khdf/linux/model/usb/host/src/usb_pnp_notify.c +++ b/adapter/khdf/linux/model/usb/host/src/usb_pnp_notify.c @@ -3,7 +3,7 @@ * * usb pnp notify adapter of linux * - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * Copyright (c) 2020-2022 Huawei Device Co., Ltd. * * This software is licensed under the terms of the GNU General Public * License version 2, as published by the Free Software Foundation, and @@ -34,6 +34,9 @@ #ifndef USB_GADGET_REMOVE #define USB_GADGET_REMOVE 0x0006 #endif +#ifndef BASE_CLASS_HUB +#define BASE_CLASS_HUB 0x09 +#endif static wait_queue_head_t g_usbPnpNotifyReportWait; static wait_queue_head_t g_gadgetPnpNotifyReportWait; @@ -51,12 +54,12 @@ struct DListHead g_usbPnpInfoListHead; #if USB_PNP_NOTIFY_TEST_MODE == true struct UsbPnpNotifyMatchInfoTable *g_testUsbPnpInfo = NULL; #endif +static int32_t g_isGadgetAdd = 0; static struct UsbPnpDeviceInfo *UsbPnpNotifyCreateInfo(void) { struct UsbPnpDeviceInfo *infoTemp = NULL; static int32_t idNum = 1; - int32_t ret; infoTemp = (struct UsbPnpDeviceInfo *)OsalMemCalloc(sizeof(struct UsbPnpDeviceInfo)); if (infoTemp == NULL) { @@ -79,15 +82,14 @@ static struct UsbPnpDeviceInfo *UsbPnpNotifyCreateInfo(void) static struct UsbPnpDeviceInfo *UsbPnpNotifyFindInfo(struct UsbInfoQueryPara queryPara) { - struct UsbPnpDeviceInfo *infoPos = NULL; - struct UsbPnpDeviceInfo *infoTemp = NULL; - bool findFlag = false; - if (DListIsEmpty(&g_usbPnpInfoListHead) == true) { HDF_LOGE("%s:%d usb pnp list head is empty.", __func__, __LINE__); return NULL; } + struct UsbPnpDeviceInfo *infoPos = NULL; + struct UsbPnpDeviceInfo *infoTemp = NULL; + bool findFlag = false; DLIST_FOR_EACH_ENTRY_SAFE(infoPos, infoTemp, &g_usbPnpInfoListHead, struct UsbPnpDeviceInfo, list) { switch (queryPara.type) { case USB_INFO_NORMAL_TYPE: @@ -214,10 +216,7 @@ OUT: static void UsbPnpNotifyAddInterfaceInitInfo(struct UsbPnpDeviceInfo *deviceInfo, union UsbPnpDeviceInfoData infoData, struct UsbPnpNotifyMatchInfoTable *infoTable) { - uint8_t i; - uint8_t j; - - for (i = 0; i < deviceInfo->info.numInfos; i++) { + for (uint8_t i = 0; i < deviceInfo->info.numInfos; i++) { if ((infoData.infoData->interfaceClass == deviceInfo->info.interfaceInfo[i].interfaceClass) && (infoData.infoData->interfaceSubClass == deviceInfo->info.interfaceInfo[i].interfaceSubClass) && (infoData.infoData->interfaceProtocol == deviceInfo->info.interfaceInfo[i].interfaceProtocol) && @@ -237,6 +236,7 @@ static void UsbPnpNotifyAddInterfaceInitInfo(struct UsbPnpDeviceInfo *deviceInfo infoTable->interfaceInfo[0].interfaceProtocol = infoData.infoData->interfaceProtocol; infoTable->interfaceInfo[0].interfaceNumber = infoData.infoData->interfaceNumber; } else { + uint8_t i, j; for (i = 0, j = 0; i < deviceInfo->info.numInfos; i++) { if (deviceInfo->interfaceRemoveStatus[i] == true) { HDF_LOGI("%s:%d j=%hhu deviceInfo->interfaceRemoveStatus[%hhu] is true!", __func__, __LINE__, j, i); @@ -341,9 +341,7 @@ static int32_t UsbPnpNotifyGetDeviceInfo( static int32_t UsbPnpNotifyHdfSendEvent(const struct HdfDeviceObject *deviceObject, void *eventData) { - int32_t ret; struct UsbPnpDeviceInfo *deviceInfo = NULL; - struct HdfSBuf *data = NULL; union UsbPnpDeviceInfoData pnpInfoData; if ((deviceObject == NULL) || (eventData == NULL)) { @@ -351,13 +349,13 @@ static int32_t UsbPnpNotifyHdfSendEvent(const struct HdfDeviceObject *deviceObje return HDF_ERR_INVALID_PARAM; } - data = HdfSbufObtainDefaultSize(); + struct HdfSBuf *data = HdfSbufObtainDefaultSize(); if (data == NULL) { HDF_LOGE("%s:%d InitDataBlock failed", __func__, __LINE__); return HDF_FAILURE; } - ret = UsbPnpNotifyGetDeviceInfo(eventData, &pnpInfoData, &deviceInfo); + int32_t ret = UsbPnpNotifyGetDeviceInfo(eventData, &pnpInfoData, &deviceInfo); if (ret != HDF_SUCCESS) { HDF_LOGE("%s:%d UsbPnpNotifyGetDeviceInfo failed, ret=%d", __func__, __LINE__, ret); goto ERROR_DEVICE_INFO; @@ -398,6 +396,36 @@ ERROR_DEVICE_INFO: return ret; } +static int32_t UsbPnpNotifyFirstGetDevice(struct usb_device *usbDev, void *data) +{ + int32_t ret; + struct UsbPnpDeviceInfo *deviceInfo = NULL; + union UsbPnpDeviceInfoData pnpInfoData; + void *eventData = (void *)usbDev; + if (usbDev->descriptor.bDeviceClass == BASE_CLASS_HUB) { + return HDF_SUCCESS; + } + + ret = UsbPnpNotifyGetDeviceInfo(eventData, &pnpInfoData, &deviceInfo); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s:%d UsbPnpNotifyGetDeviceInfo failed, ret=%d", __func__, __LINE__, ret); + return ret; + } + ret = UsbPnpNotifyAddInitInfo(deviceInfo, pnpInfoData); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s:%d UsbPnpNotifyAddInitInfo failed, ret=%d", __func__, __LINE__, ret); + return ret; + } + + HDF_LOGI("%s:%d device information, %d usbDevAddr=%llu, devNum=%d, busNum=%d, infoTable=%d-0x%x-0x%x!", + __func__, __LINE__, USB_PNP_DRIVER_GETDEVICES, deviceInfo->info.usbDevAddr, + deviceInfo->info.devNum, deviceInfo->info.busNum, deviceInfo->info.numInfos, + deviceInfo->info.deviceInfo.vendorId, deviceInfo->info.deviceInfo.productId); + deviceInfo->status = USB_PNP_DEVICE_ADD_STATUS; + + return ret; +} + #if USB_PNP_NOTIFY_TEST_MODE == true static void TestReadPnpInfo(struct HdfSBuf *data) { @@ -415,8 +443,6 @@ static void TestReadPnpInfo(struct HdfSBuf *data) static void TestPnpNotifyFillInfoTable(struct UsbPnpNotifyMatchInfoTable *infoTable) { - int8_t i; - infoTable->usbDevAddr = g_testUsbPnpInfo->usbDevAddr; infoTable->devNum = g_testUsbPnpInfo->devNum; if (g_usbPnpNotifyCmdType == USB_PNP_NOTIFY_REMOVE_TEST) { @@ -437,7 +463,7 @@ static void TestPnpNotifyFillInfoTable(struct UsbPnpNotifyMatchInfoTable *infoTa if (g_usbPnpNotifyCmdType != USB_PNP_NOTIFY_REMOVE_TEST) { infoTable->numInfos = g_testUsbPnpInfo->numInfos; - for (i = 0; i < infoTable->numInfos; i++) { + for (int8_t i = 0; i < infoTable->numInfos; i++) { infoTable->interfaceInfo[i].interfaceClass = g_testUsbPnpInfo->interfaceInfo[i].interfaceClass; infoTable->interfaceInfo[i].interfaceSubClass = g_testUsbPnpInfo->interfaceInfo[i].interfaceSubClass; infoTable->interfaceInfo[i].interfaceProtocol = g_testUsbPnpInfo->interfaceInfo[i].interfaceProtocol; @@ -495,17 +521,18 @@ static int32_t GadgetPnpNotifyHdfSendEvent(const struct HdfDeviceObject *deviceO return HDF_ERR_INVALID_PARAM; } - struct HdfSBuf *data = NULL; - data = HdfSbufObtainDefaultSize(); + struct HdfSBuf *data = HdfSbufObtainDefaultSize(); if (data == NULL) { HDF_LOGE("%s:%d InitDataBlock failed", __func__, __LINE__); return HDF_FAILURE; } + if (!HdfSbufWriteUint8(data, g_gadgetPnpNotifyType)) { HDF_LOGE("%s, UsbEcmRead HdfSbufWriteInt8 error", __func__); HdfSbufRecycle(data); return HDF_FAILURE; } + int32_t ret = HdfDeviceSendEvent(deviceObject, g_gadgetPnpNotifyType, data); if (ret != HDF_SUCCESS) { HDF_LOGE("%s:%d HdfDeviceSendEvent ret = %d", __func__, __LINE__, ret); @@ -534,9 +561,8 @@ static int32_t UsbPnpNotifyFirstReport(struct usb_device *usbDev, void *data) static int32_t UsbPnpNotifyReportThread(void *arg) { - int32_t ret; struct HdfDeviceObject *deviceObject = (struct HdfDeviceObject *)arg; - + int32_t ret; while (!kthread_should_stop()) { #if USB_PNP_NOTIFY_TEST_MODE == false ret = wait_event_interruptible(g_usbPnpNotifyReportWait, g_usbDevice != NULL); @@ -583,12 +609,11 @@ static int32_t UsbPnpNotifyReportThread(void *arg) static int32_t GadgetPnpNotifyReportThread(void *arg) { - int32_t ret; struct HdfDeviceObject *deviceObject = (struct HdfDeviceObject *)arg; while (!kthread_should_stop()) { - ret = wait_event_interruptible(g_gadgetPnpNotifyReportWait, (g_gadgetPnpNotifyType != 0)); - if (!ret) { + int32_t ret = wait_event_interruptible(g_gadgetPnpNotifyReportWait, (g_gadgetPnpNotifyType != 0)); + if (ret == HDF_SUCCESS) { HDF_LOGI("%s: GadgetPnpNotifyReportThread start!", __func__); } OsalMutexLock(&g_gadgetSendEventLock); @@ -609,7 +634,6 @@ static int32_t GadgetPnpNotifyReportThread(void *arg) static int32_t UsbPnpNotifyCallback(struct notifier_block *self, unsigned long action, void *dev) { (void)self; - int32_t ret; struct UsbInfoQueryPara infoQueryPara; struct UsbPnpDeviceInfo *deviceInfo = NULL; union UsbPnpDeviceInfoData pnpInfoData; @@ -622,8 +646,7 @@ static int32_t UsbPnpNotifyCallback(struct notifier_block *self, unsigned long a if (deviceInfo == NULL) { HDF_LOGE("%s:%d USB_DEVICE_ADD create info failed", __func__, __LINE__); } else { - ret = UsbPnpNotifyAddInitInfo(deviceInfo, pnpInfoData); - if (ret != HDF_SUCCESS) { + if (UsbPnpNotifyAddInitInfo(deviceInfo, pnpInfoData) != HDF_SUCCESS) { HDF_LOGE("%s:%d USB_DEVICE_ADD UsbPnpNotifyAddInitInfo error", __func__, __LINE__); } else { OsalMutexLock(&g_usbSendEventLock); @@ -664,8 +687,10 @@ static int32_t UsbPnpNotifyCallback(struct notifier_block *self, unsigned long a break; } if (action == USB_GADGET_ADD) { + g_isGadgetAdd = 1; g_gadgetPnpNotifyType = USB_PNP_DRIVER_GADGET_ADD; } else { + g_isGadgetAdd = 0; g_gadgetPnpNotifyType = USB_PNP_DRIVER_GADGET_REMOVE; } OsalMutexUnlock(&g_gadgetSendEventLock); @@ -731,45 +756,35 @@ static void UsbPnpNotifyReadPnpInfo(struct HdfSBuf *data) static int32_t UsbPnpGetDevices(struct HdfSBuf *reply) { - int32_t ret = HDF_SUCCESS; struct UsbPnpDeviceInfo *infoPos = NULL; struct UsbPnpDeviceInfo *infoTemp = NULL; + if (!HdfSbufWriteInt32(reply, DListGetCount(&g_usbPnpInfoListHead))) { + HDF_LOGE("%s write list count failed", __func__); + return HDF_ERR_IO; + } if (DListIsEmpty(&g_usbPnpInfoListHead) == true) { - return ret; + return HDF_SUCCESS; } DLIST_FOR_EACH_ENTRY_SAFE(infoPos, infoTemp, &g_usbPnpInfoListHead, struct UsbPnpDeviceInfo, list) { - if (!HdfSbufWriteInt32(reply, infoPos->info.busNum)) { - break; - } - if (!HdfSbufWriteInt32(reply, infoPos->info.devNum)) { - break; - } - if (!HdfSbufWriteUint8(reply, infoPos->info.deviceInfo.deviceClass)) { - break; - } - if (!HdfSbufWriteUint8(reply, infoPos->info.deviceInfo.deviceSubClass)) { - break; - } - if (!HdfSbufWriteUint8(reply, infoPos->info.deviceInfo.deviceProtocol)) { - break; - } - if (!HdfSbufWriteUint8(reply, infoPos->status)) { - break; + if (!HdfSbufWriteBuffer(reply, &infoPos->info, sizeof(struct UsbPnpNotifyMatchInfoTable))) { + HDF_LOGE("%s write buffer failed", __func__); + return HDF_ERR_IO; } } - return ret; + return HDF_SUCCESS; } static int32_t UsbPnpNotifyDispatch( struct HdfDeviceIoClient *client, int32_t cmd, struct HdfSBuf *data, struct HdfSBuf *reply) { int32_t ret = HDF_SUCCESS; + static int32_t isFirstGetDevice = 0; HDF_LOGI("%s: received cmd = %d", __func__, cmd); OsalMutexLock(&g_usbSendEventLock); - if (USB_PNP_DRIVER_GETDEVICES != cmd) { + if (cmd != USB_PNP_DRIVER_GETDEVICES || cmd != USB_PNP_DRIVER_GET_GADGET_LINK_STATUS) { g_usbPnpNotifyCmdType = cmd; } @@ -798,8 +813,15 @@ static int32_t UsbPnpNotifyDispatch( break; #endif case USB_PNP_DRIVER_GETDEVICES: + if (isFirstGetDevice == 0) { + usb_for_each_dev(NULL, UsbPnpNotifyFirstGetDevice); + isFirstGetDevice = 1; + } UsbPnpGetDevices(reply); break; + case USB_PNP_DRIVER_GET_GADGET_LINK_STATUS: + HdfSbufWriteInt32(reply, g_isGadgetAdd); + break; default: ret = HDF_ERR_NOT_SUPPORT; break; diff --git a/adapter/khdf/linux/platform/adc/adc_iio_adapter.c b/adapter/khdf/linux/platform/adc/adc_iio_adapter.c index b6442bbcb02f63d2af016d158f4abdfd2e4a5c78..72529641cf38664e0aeb7fbd4cc11a66bb57e7b6 100644 --- a/adapter/khdf/linux/platform/adc/adc_iio_adapter.c +++ b/adapter/khdf/linux/platform/adc/adc_iio_adapter.c @@ -81,7 +81,7 @@ static int32_t AdcIioRead(struct AdcDevice *device, uint32_t channel, uint32_t * static int32_t AdcIioStop(struct AdcDevice *device) { - int ret = HDF_FAILURE; + int ret; uint32_t i; struct AdcIioDevice *adcDevice = NULL; @@ -143,7 +143,6 @@ static int32_t AdcIioReadDrs(struct AdcIioDevice *adcDevice, const struct Device int32_t ret; const char *drName = NULL; char channelName[ADC_CHANNEL_NAME_LEN] = {0}; - int32_t drNameLen; struct DeviceResourceIface *drsOps = NULL; uint32_t i; diff --git a/adapter/khdf/linux/platform/fwk/platform_trace.c b/adapter/khdf/linux/platform/fwk/platform_trace.c index f1f3970fd7884f934a6c97e392b430dfa99c392c..dc888c4a202b5f8cfff881f95f4398baee67943d 100644 --- a/adapter/khdf/linux/platform/fwk/platform_trace.c +++ b/adapter/khdf/linux/platform/fwk/platform_trace.c @@ -65,7 +65,7 @@ void PlatformTraceAddUintMsg(int module, int moduleFun, const uint infos[], uint return; } - if ((size <= 0) || (size > PLATFORM_TRACE_UINT_PARAM_SIZE_MAX)) { + if (size > PLATFORM_TRACE_UINT_PARAM_SIZE_MAX) { HDF_LOGE("PlatformTraceAddUintMsg %hhu size illegal", size); return; } diff --git a/adapter/khdf/linux/platform/mipi_dsi/mipi_tx_hi35xx.c b/adapter/khdf/linux/platform/mipi_dsi/mipi_tx_hi35xx.c index c57c4b665511afa123917c49d4d239cb1ed16136..17d3475c407cd161e4eea47e56e857abc791262d 100644 --- a/adapter/khdf/linux/platform/mipi_dsi/mipi_tx_hi35xx.c +++ b/adapter/khdf/linux/platform/mipi_dsi/mipi_tx_hi35xx.c @@ -129,7 +129,7 @@ static void MipiTxDrvGetPhyPllSet1Set5(unsigned int phyDataRate, { int dataRateClk; int pllRef; - uint64_t int_multiplication; + int64_t int_multiplication; dataRateClk = (int)(phyDataRate + MIPI_TX_REF_CLK - 1) / MIPI_TX_REF_CLK; diff --git a/adapter/khdf/linux/platform/regulator/regulator_adapter_consumer.h b/adapter/khdf/linux/platform/regulator/regulator_adapter_consumer.h index 5030267c396d1e260fa6202b4e5dfb811be36e36..e4ba946d309b2b1ab3ff3dfff595bbd002dbfab8 100755 --- a/adapter/khdf/linux/platform/regulator/regulator_adapter_consumer.h +++ b/adapter/khdf/linux/platform/regulator/regulator_adapter_consumer.h @@ -15,6 +15,7 @@ #ifndef REGULATOR_ADAPTER_CONSUMER_H #define REGULATOR_ADAPTER_CONSUMER_H #include "hdf_base.h" + int RegulatorAdapterConsumerInit(void); #endif /* REGULATOR_ADAPTER_CONSUMER_H */ diff --git a/adapter/khdf/linux/platform/uart/uart_adapter.c b/adapter/khdf/linux/platform/uart/uart_adapter.c index 4ebbdde988ea6b4194888f9b5d83df9bf08a271b..aeaac417b296c1970197eaaf59eacc51c8993d86 100644 --- a/adapter/khdf/linux/platform/uart/uart_adapter.c +++ b/adapter/khdf/linux/platform/uart/uart_adapter.c @@ -32,7 +32,7 @@ #define HDF_LOG_TAG hdf_uart_adapter #define UART_NAME_LEN 20 -#define UART_PATHNAME_LEN (UART_NAME_LEN + 15) +#define UART_PATHNAME_LEN (UART_NAME_LEN + 20) static char g_driverName[UART_NAME_LEN]; @@ -290,14 +290,20 @@ static int32_t UartAdapterSetBaud(struct UartHost *host, uint32_t baudRate) termios.c_cflag |= BaudRateToCflag(baudRate); termios.c_cc[VMIN] = 0; termios.c_cc[VTIME] = 0; - ret = UartAdapterIoctlInner(fp, TCSETS, (unsigned long)&termios); + if (UartAdapterIoctlInner(fp, TCSETS, (unsigned long)&termios) < 0) { + HDF_LOGE("tcgets fail"); + return HDF_FAILURE; + } /* Set low latency */ if (UartAdapterIoctlInner(fp, TIOCGSERIAL, (unsigned long)&serial) < 0) { - HDF_LOGE("tiocgserial fail"); + HDF_LOGE("tiocgserial fail %d", __LINE__); return HDF_FAILURE; } serial.flags |= ASYNC_LOW_LATENCY; ret = UartAdapterIoctlInner(fp, TIOCSSERIAL, (unsigned long)&serial); + if (ret < 0) { + HDF_LOGE("tiocgserial fail %d", __LINE__); + } return ret; } diff --git a/adapter/khdf/liteos/model/bus/usb/hdf_usb.c b/adapter/khdf/liteos/model/bus/usb/hdf_usb.c index 816b11fd9a6b245c08e910bebf59f9c94d074010..ea74b36bb5b817006583a542301061fc77badde2 100644 --- a/adapter/khdf/liteos/model/bus/usb/hdf_usb.c +++ b/adapter/khdf/liteos/model/bus/usb/hdf_usb.c @@ -99,13 +99,10 @@ static int GetUsbControllerParam(const struct DeviceResourceIface *instance, con static int ProcControllorParam(const struct DeviceResourceIface *instance, const struct DeviceResourceNode *node, const char *name, add_res_callback_t callback, struct UsbInfo *info) { - int32_t ret; - const struct DeviceResourceNode *subNode = NULL; const char *ctrlName = NULL; uint32_t index = 0; - struct UsbConfig *cfg = NULL; - subNode = node->child; + const struct DeviceResourceNode *subNode = node->child; if (subNode == NULL) { return HDF_FAILURE; } @@ -115,8 +112,8 @@ static int ProcControllorParam(const struct DeviceResourceIface *instance, const break; } - cfg = &(info->cfg[index]); - ret = instance->GetString(subNode, "controller", &ctrlName, NULL); + struct UsbConfig *cfg = &(info->cfg[index]); + int32_t ret = instance->GetString(subNode, "controller", &ctrlName, NULL); if (ret != HDF_SUCCESS) { HDF_LOGE("%s: read res_type fail", __func__); return HDF_FAILURE; @@ -141,34 +138,28 @@ static int ProcControllorParam(const struct DeviceResourceIface *instance, const static void HdfUsbInitParam(device_t dev, add_res_callback_t callback) { - const struct DeviceResourceIface *devResInstance = NULL; - const struct DeviceResourceNode *hdfUsbNode = NULL; - const char *ctrlName = NULL; - int32_t ret; - int32_t count; - int32_t i; - struct UsbInfo info = {0}; - - devResInstance = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE); + const struct DeviceResourceIface *devResInstance = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE); if (devResInstance == NULL) { HDF_LOGE("%s get devResInstance node is null", __func__); return; } - hdfUsbNode = GetHdfUsbNode(devResInstance); + const struct DeviceResourceNode *hdfUsbNode = GetHdfUsbNode(devResInstance); if (hdfUsbNode == NULL) { HDF_LOGE("%s get hdf usb node is null", __func__); return; } - count = devResInstance->GetElemNum(hdfUsbNode, USB_CONTROLLER_LIST_NAME); + int32_t count = devResInstance->GetElemNum(hdfUsbNode, USB_CONTROLLER_LIST_NAME); if ((count <= 0) || (count > USB_MAX_CFG_LEN / USB_CFG_UNIT)) { HDF_LOGE("%s get elemnum failed", __func__); return; } + struct UsbInfo info = {0}; info.len = USB_MAX_CFG_LEN; - for (i = 0; i < count; i++) { - ret = devResInstance->GetStringArrayElem(hdfUsbNode, USB_CONTROLLER_LIST_NAME, i, &ctrlName, NULL); + const char *ctrlName = NULL; + for (int32_t i = 0; i < count; i++) { + int32_t ret = devResInstance->GetStringArrayElem(hdfUsbNode, USB_CONTROLLER_LIST_NAME, i, &ctrlName, NULL); if (ret != HDF_SUCCESS) { HDF_LOGE("%s get hdf usb list name fail", __func__); return; diff --git a/adapter/khdf/liteos/model/usb/host/src/usb_pnp_notify.c b/adapter/khdf/liteos/model/usb/host/src/usb_pnp_notify.c index 8aa5b9e239242ba47f4f9d1e099a1e949c830a58..0abe233e8c365ca69efbb383475205d7a7196e3e 100644 --- a/adapter/khdf/liteos/model/usb/host/src/usb_pnp_notify.c +++ b/adapter/khdf/liteos/model/usb/host/src/usb_pnp_notify.c @@ -119,15 +119,14 @@ static struct UsbPnpDeviceInfo *UsbPnpNotifyCreateInfo(void) static struct UsbPnpDeviceInfo *UsbPnpNotifyFindInfo(struct UsbInfoQueryPara queryPara) { - struct UsbPnpDeviceInfo *infoPos = NULL; - struct UsbPnpDeviceInfo *infoTemp = NULL; - bool findFlag = false; - if (DListIsEmpty(&g_usbPnpInfoListHead) == true) { HDF_LOGE("%s:%d usb pnp list head is empty.", __func__, __LINE__); return NULL; } + struct UsbPnpDeviceInfo *infoPos = NULL; + struct UsbPnpDeviceInfo *infoTemp = NULL; + bool findFlag = false; DLIST_FOR_EACH_ENTRY_SAFE(infoPos, infoTemp, &g_usbPnpInfoListHead, struct UsbPnpDeviceInfo, list) { switch (queryPara.type) { case USB_INFO_NORMAL_TYPE: @@ -249,10 +248,7 @@ OUT: static void UsbPnpNotifyAddInterfaceInitInfo(struct UsbPnpDeviceInfo *deviceInfo, union UsbPnpDeviceInfoData infoData, struct UsbPnpNotifyMatchInfoTable *infoTable) { - uint8_t i; - uint8_t j; - - for (i = 0; i < deviceInfo->info.numInfos; i++) { + for (uint8_t i = 0; i < deviceInfo->info.numInfos; i++) { if ((infoData.infoData->interfaceClass == deviceInfo->info.interfaceInfo[i].interfaceClass) && (infoData.infoData->interfaceSubClass == deviceInfo->info.interfaceInfo[i].interfaceSubClass) && (infoData.infoData->interfaceProtocol == deviceInfo->info.interfaceInfo[i].interfaceProtocol) @@ -272,6 +268,7 @@ static void UsbPnpNotifyAddInterfaceInitInfo(struct UsbPnpDeviceInfo *deviceInfo infoTable->interfaceInfo[0].interfaceProtocol = infoData.infoData->interfaceProtocol; infoTable->interfaceInfo[0].interfaceNumber = infoData.infoData->interfaceNumber; } else { + uint8_t i, j; for (i = 0, j = 0; i < deviceInfo->info.numInfos; i++) { if (deviceInfo->interfaceRemoveStatus[i] == true) { HDF_LOGI("%s:%d j = %hhu deviceInfo->interfaceRemoveStatus[%hhu] is true!", __func__, __LINE__, j, i); @@ -476,8 +473,6 @@ static void TestReadPnpInfo(struct HdfSBuf *data) static void TestPnpNotifyFillInfoTable(struct UsbPnpNotifyMatchInfoTable *infoTable) { - int8_t i; - infoTable->usbDevAddr = g_testUsbPnpInfo->usbDevAddr; infoTable->devNum = g_testUsbPnpInfo->devNum; if (g_usbPnpNotifyCmdType == USB_PNP_NOTIFY_REMOVE_TEST) { @@ -498,7 +493,7 @@ static void TestPnpNotifyFillInfoTable(struct UsbPnpNotifyMatchInfoTable *infoTa if (g_usbPnpNotifyCmdType != USB_PNP_NOTIFY_REMOVE_TEST) { infoTable->numInfos = g_testUsbPnpInfo->numInfos; - for (i = 0; i < infoTable->numInfos; i++) { + for (int8_t i = 0; i < infoTable->numInfos; i++) { infoTable->interfaceInfo[i].interfaceClass = g_testUsbPnpInfo->interfaceInfo[i].interfaceClass; infoTable->interfaceInfo[i].interfaceSubClass = g_testUsbPnpInfo->interfaceInfo[i].interfaceSubClass; infoTable->interfaceInfo[i].interfaceProtocol = g_testUsbPnpInfo->interfaceInfo[i].interfaceProtocol; @@ -552,21 +547,18 @@ OUT: static int32_t UsbPnpNotifyFirstReportDevice(struct HdfDeviceIoClient *client) { - struct UsbPnpNotifyDeviceList *pnpNotifyDevicePos = NULL; - struct UsbPnpNotifyDeviceList *pnpNotifyDeviceTemp = NULL; - int32_t ret; - dprintf("%s:%d Enter!\n", __func__, __LINE__); - if (DListIsEmpty(&g_usbPnpDeviceListHead) == true) { dprintf("%s:%d device list is empty\n", __func__, __LINE__); return HDF_SUCCESS; } + struct UsbPnpNotifyDeviceList *pnpNotifyDevicePos = NULL; + struct UsbPnpNotifyDeviceList *pnpNotifyDeviceTemp = NULL; OsalMutexLock(&g_usbPnpNotifyDevicelistLock); DLIST_FOR_EACH_ENTRY_SAFE(pnpNotifyDevicePos, pnpNotifyDeviceTemp, &g_usbPnpDeviceListHead, struct UsbPnpNotifyDeviceList, deviceList) { - ret = UsbPnpNotifyHdfSendEvent(client->device, pnpNotifyDevicePos->device); + int32_t ret = UsbPnpNotifyHdfSendEvent(client->device, pnpNotifyDevicePos->device); if (ret != HDF_SUCCESS) { HDF_LOGE("%{public}s:%{public}d UsbPnpNotifyHdfSendEvent failed, ret=%{public}d", __func__, __LINE__, ret); } @@ -649,16 +641,13 @@ static void UsbPnpNotifyCreateDeviceList(struct usb_device *udev) static void UsbPnpNotifyAddDevice(struct usb_device *udev) { - int32_t ret; - struct UsbPnpDeviceInfo *deviceInfo = NULL; union UsbPnpDeviceInfoData pnpInfoData; - pnpInfoData.usbDev = udev; - deviceInfo = UsbPnpNotifyCreateInfo(); + struct UsbPnpDeviceInfo *deviceInfo = UsbPnpNotifyCreateInfo(); if (deviceInfo == NULL) { DPRINTFN(0, "%s:%d USB_DEVICE_ADD create info failed\n", __func__, __LINE__); } else { - ret = UsbPnpNotifyAddInitInfo(deviceInfo, pnpInfoData); + int32_t ret = UsbPnpNotifyAddInitInfo(deviceInfo, pnpInfoData); if (ret != HDF_SUCCESS) { PRINTK("%s:%d USB_DEVICE_ADD UsbPnpNotifyAddInitInfo error\n", __func__, __LINE__); } else { diff --git a/adapter/khdf/liteos/platform/src/platform_trace.c b/adapter/khdf/liteos/platform/src/platform_trace.c index c525beae24b45373aa1564e944ee322a46182510..52b1625da5746a2d33af751619de0f7e8d2abe1d 100644 --- a/adapter/khdf/liteos/platform/src/platform_trace.c +++ b/adapter/khdf/liteos/platform/src/platform_trace.c @@ -89,7 +89,7 @@ void PlatformTraceInfoDump(void) void PlatformTraceAddUintMsg(int module, int moduleFun, const uint infos[], uint8_t size) { #ifdef LOSCFG_KERNEL_TRACE - if ((size <= 0) || (size > PLATFORM_TRACE_UINT_PARAM_SIZE_MAX)) { + if (size > PLATFORM_TRACE_UINT_PARAM_SIZE_MAX) { HDF_LOGE("PlatformTraceAddUintMsg %hhu size illegal", size); return; } diff --git a/adapter/platform/can/can_virtual.c b/adapter/platform/can/can_virtual.c index 1dbcf9994ab81a34c35f2bc20b2896bb8f702433..9b944695e001647ae407307c99a97754cfdbfc5b 100644 --- a/adapter/platform/can/can_virtual.c +++ b/adapter/platform/can/can_virtual.c @@ -201,12 +201,14 @@ static int32_t VirtualCanSetCfg(struct CanCntlr *cntlr, const struct CanConfig * } virtualCan->busState = CAN_BUS_RESET; - if ((ret = VirtualCanSetBitRate(virtualCan, cfg->speed) != HDF_SUCCESS)) { + ret = VirtualCanSetBitRate(virtualCan, cfg->speed); + if (ret != HDF_SUCCESS) { HDF_LOGE("%s: set speed failed", __func__); return ret; } - if ((ret = VirtualCanSetMode(virtualCan, cfg->mode) != HDF_SUCCESS)) { + ret = VirtualCanSetMode(virtualCan, cfg->mode); + if (ret != HDF_SUCCESS) { HDF_LOGE("%s: set mode failed", __func__); return ret; } @@ -268,12 +270,14 @@ static int32_t VirtualCanInit(struct VirtualCanCntlr *virtualCan) HDF_LOGW("VirtualUartInit: read hcs config failed"); } - if ((ret = VirtualCanSetBitRate(virtualCan, virtualCan->bitRate) != HDF_SUCCESS)) { + ret = VirtualCanSetBitRate(virtualCan, virtualCan->bitRate); + if (ret != HDF_SUCCESS) { HDF_LOGE("%s: set bit rate failed", __func__); return ret; } - if ((ret = VirtualCanSetMode(virtualCan, virtualCan->workMode) != HDF_SUCCESS)) { + ret = VirtualCanSetMode(virtualCan, virtualCan->workMode); + if (ret != HDF_SUCCESS) { HDF_LOGE("%s: set mode failed", __func__); return ret; } diff --git a/adapter/platform/gpio/gpio_gr5xx.c b/adapter/platform/gpio/gpio_gr5xx.c index 57463a43195c19d597fab640db8886f4a42b1ca1..0e60ac199db9205f522c781fcc05ff3eeb548737 100644 --- a/adapter/platform/gpio/gpio_gr5xx.c +++ b/adapter/platform/gpio/gpio_gr5xx.c @@ -20,7 +20,7 @@ #define IO_NUM_MSIO 5 #define IO_NUM_MAX (IO_NUM_GPIO + IO_NUM_AON + IO_NUM_MSIO) -#define IO_BASE_GPIO 0 +#define IO_BASE_GPIO 0U #define IO_BASE_AON IO_NUM_GPIO #define IO_BASE_MSIO (IO_NUM_GPIO + IO_NUM_AON) @@ -315,6 +315,11 @@ static uint16_t GetGpioResourceData(const struct DeviceResourceNode *node, const uint16_t resData; struct DeviceResourceIface *drsOps = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE); + if (drsOps == NULL || drsOps->GetUint16ArrayElem == NULL) { + HDF_LOGE("%s: invalid drsOps!", __func__); + return HDF_FAILURE; + } + ret = drsOps->GetUint16ArrayElem(node, resName, index, &resData, 0); if (ret != HDF_SUCCESS) { HDF_LOGE("%s: read %s fail!", __func__, resName); diff --git a/adapter/platform/gpio/gpio_stm32f4xx.c b/adapter/platform/gpio/gpio_stm32f4xx.c index 6fd2c6021770c3f592259f6492f3decdbd0fb7c1..a2cd8a86eadf9e7b028730e102164388911673db 100644 --- a/adapter/platform/gpio/gpio_stm32f4xx.c +++ b/adapter/platform/gpio/gpio_stm32f4xx.c @@ -326,7 +326,6 @@ static uint32_t GetGpioDeviceResource(GpioDevice *device) #else static int32_t GetGpioDeviceResource(GpioDevice *device, const struct DeviceResourceNode *resourceNode) { - int32_t ret; struct DeviceResourceIface *dri = NULL; if (device == NULL || resourceNode == NULL) { HDF_LOGE("%s: device is NULL", __func__); diff --git a/adapter/platform/gpio/gpio_wm.c b/adapter/platform/gpio/gpio_wm.c index b0f67fdb3c96caa2efcba8b5d4b3d23129c72b28..c51ffb30b10978cd645f3adfe4c7c2d75c9d700a 100755 --- a/adapter/platform/gpio/gpio_wm.c +++ b/adapter/platform/gpio/gpio_wm.c @@ -116,12 +116,14 @@ struct GpioMethod g_GpioCntlrMethod = { /* dev api */ static int32_t GpioDevWrite(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t val) { + uint16_t wmGpio; + (void)cntlr; - uint16_t wmGpio = g_gpioPinReflectionMap[gpio]; - if ((enum tls_io_name)wmGpio > WM_IO_MAX_GPIO_PIN_NUM) { - HDF_LOGE("%s %d, error wmGpio:%d", __func__, __LINE__, wmGpio); + if (gpio > WM_IO_MAX_GPIO_PIN_NUM) { + HDF_LOGE("%s %d, error gpio:%hu", __func__, __LINE__, gpio); return HDF_ERR_NOT_SUPPORT; } + wmGpio= g_gpioPinReflectionMap[gpio]; tls_gpio_write((enum tls_io_name)wmGpio, val); return HDF_SUCCESS; @@ -129,13 +131,15 @@ static int32_t GpioDevWrite(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t val static int32_t GpioDevRead(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t *val) { - (void)cntlr; uint16_t value; - uint16_t wmGpio = g_gpioPinReflectionMap[gpio]; - if ((enum tls_io_name)wmGpio > WM_IO_MAX_GPIO_PIN_NUM) { - HDF_LOGE("%s %d, error wmGpio:%d", __func__, __LINE__, wmGpio); + uint16_t wmGpio; + + (void)cntlr; + if (gpio > WM_IO_MAX_GPIO_PIN_NUM) { + HDF_LOGE("%s %d, error gpio:%hu", __func__, __LINE__, gpio); return HDF_ERR_NOT_SUPPORT; } + wmGpio = g_gpioPinReflectionMap[gpio]; value = tls_gpio_read((enum tls_io_name)wmGpio); *val = value; @@ -144,12 +148,14 @@ static int32_t GpioDevRead(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t *val static int32_t GpioDevSetDir(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t dir) { + uint16_t wmGpio; + (void)cntlr; - uint16_t wmGpio = g_gpioPinReflectionMap[gpio]; - if ((enum tls_io_name)wmGpio > WM_IO_MAX_GPIO_PIN_NUM) { - HDF_LOGE("%s %d, error wmGpio:%d", __func__, __LINE__, wmGpio); + if (gpio > WM_IO_MAX_GPIO_PIN_NUM) { + HDF_LOGE("%s %d, error gpio:%hu", __func__, __LINE__, gpio); return HDF_ERR_NOT_SUPPORT; } + wmGpio = g_gpioPinReflectionMap[gpio]; switch (dir) { case GPIO_DIR_OUT: @@ -170,12 +176,14 @@ static int32_t GpioDevSetDir(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t di static int32_t GpioDevSetIrq(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t mode) { + uint16_t wmGpio; + (void)cntlr; - uint16_t wmGpio = g_gpioPinReflectionMap[gpio]; - if ((enum tls_io_name)wmGpio > WM_IO_MAX_GPIO_PIN_NUM) { - HDF_LOGE("%s %d, error wmGpio:%d", __func__, __LINE__, wmGpio); + if (gpio > WM_IO_MAX_GPIO_PIN_NUM) { + HDF_LOGE("%s %d, error gpio:%hu", __func__, __LINE__, gpio); return HDF_ERR_NOT_SUPPORT; } + wmGpio= g_gpioPinReflectionMap[gpio]; g_wmGpioIrqHandler[wmGpio].port = gpio; tls_gpio_isr_register((enum tls_io_name)wmGpio, (tls_gpio_irq_callback)GpioIrqHdl, NULL); @@ -203,23 +211,27 @@ static int32_t GpioDevSetIrq(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t mo static int32_t GpioDevUnSetIrq(struct GpioCntlr *cntlr, uint16_t gpio) { + uint16_t wmGpio; + (void)cntlr; - uint16_t wmGpio = g_gpioPinReflectionMap[gpio]; - if ((enum tls_io_name)wmGpio > WM_IO_MAX_GPIO_PIN_NUM) { - HDF_LOGE("%s %d, error wmGpio:%d", __func__, __LINE__, wmGpio); + if (gpio > WM_IO_MAX_GPIO_PIN_NUM) { + HDF_LOGE("%s %d, error gpio:%hu", __func__, __LINE__, gpio); return HDF_ERR_NOT_SUPPORT; } + wmGpio= g_gpioPinReflectionMap[gpio]; return HDF_SUCCESS; } static int32_t GpioDevEnableIrq(struct GpioCntlr *cntlr, uint16_t gpio) { + uint16_t wmGpio; + (void)cntlr; - uint16_t wmGpio = g_gpioPinReflectionMap[gpio]; - if ((enum tls_io_name)wmGpio > WM_IO_MAX_GPIO_PIN_NUM) { - HDF_LOGE("%s %d, error pin:%d", __func__, __LINE__, wmGpio); + if (gpio > WM_IO_MAX_GPIO_PIN_NUM) { + HDF_LOGE("%s %d, error gpio:%hu", __func__, __LINE__, gpio); return HDF_ERR_NOT_SUPPORT; } + wmGpio= g_gpioPinReflectionMap[gpio]; // config gpio interrupt tls_gpio_irq_enable((enum tls_io_name)wmGpio, g_gpioIrqCfg[wmGpio]); @@ -228,24 +240,24 @@ static int32_t GpioDevEnableIrq(struct GpioCntlr *cntlr, uint16_t gpio) static int32_t GpioDevDisableIrq(struct GpioCntlr *cntlr, uint16_t gpio) { + uint16_t wmGpio; + (void)cntlr; - uint16_t wmGpio = g_gpioPinReflectionMap[gpio]; - if ((enum tls_io_name)wmGpio > WM_IO_MAX_GPIO_PIN_NUM) { - HDF_LOGE("%s %d, error pin:%d", __func__, __LINE__, wmGpio); + if (gpio > WM_IO_MAX_GPIO_PIN_NUM) { + HDF_LOGE("%s %d, error gpio:%hu", __func__, __LINE__, gpio); return HDF_ERR_NOT_SUPPORT; } + wmGpio= g_gpioPinReflectionMap[gpio]; tls_gpio_irq_disable((enum tls_io_name)wmGpio); return HDF_SUCCESS; } -static uint32_t GetGpioDeviceResource(struct GpioDevice *device, - const struct DeviceResourceNode *resourceNode) +static uint32_t GetGpioDeviceResource(struct GpioDevice *device, const struct DeviceResourceNode *resourceNode) { - uint32_t relPin; - int32_t ret; struct GpioResource *resource = NULL; struct DeviceResourceIface *dri = NULL; + if (device == NULL || resourceNode == NULL) { HDF_LOGE("%s: device is NULL", __func__); return HDF_ERR_INVALID_PARAM; @@ -256,7 +268,7 @@ static uint32_t GetGpioDeviceResource(struct GpioDevice *device, return HDF_ERR_INVALID_OBJECT; } dri = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE); - if (dri == NULL || dri->GetUint32 == NULL) { + if (dri == NULL || dri->GetUint32 == NULL || dri->GetUint32ArrayElem == NULL) { HDF_LOGE("DeviceResourceIface is invalid"); return HDF_ERR_INVALID_OBJECT; } diff --git a/adapter/platform/i2c/i2c_wm.c b/adapter/platform/i2c/i2c_wm.c index 4d496b702cf8f8db693160b75f045a962d426a29..88e663e1c91f74abdaf06c4d65d52b5809123423 100755 --- a/adapter/platform/i2c/i2c_wm.c +++ b/adapter/platform/i2c/i2c_wm.c @@ -61,7 +61,6 @@ struct I2cMethod g_i2cHostMethod = { static int32_t InitI2cDevice(struct I2cDevice *device) { - int32_t ret = -1; uint32_t i2cPort; struct I2cResource *resource = NULL; @@ -104,7 +103,6 @@ static int32_t InitI2cDevice(struct I2cDevice *device) static int32_t HostRestI2cDevice(struct I2cDevice *device) { - int32_t ret = -1; struct I2cResource *resource = NULL; uint32_t i2cPort; @@ -278,7 +276,7 @@ static int32_t i2c_send(struct I2cMsg *msg) len = msg->len; ifstop = 0; if (msg->flags & I2C_FLAG_READ) { - ifack = msg->flags & I2C_FLAG_READ_NO_ACK ? 0 : 1; + ifack = (msg->flags & I2C_FLAG_READ_NO_ACK) ? 0 : 1; for (int32_t j = 0; j < len; j++) { if (((msg->flags & I2C_FLAG_STOP) && j) == (len - 1)) { ifstop = 1; @@ -286,7 +284,7 @@ static int32_t i2c_send(struct I2cMsg *msg) msg->buf[j] = tls_i2c_read_byte(ifack, ifstop); } } else { - ifack = msg->flags & I2C_FLAG_IGNORE_NO_ACK ? 0 : 1; + ifack = (msg->flags & I2C_FLAG_IGNORE_NO_ACK) ? 0 : 1; for (int32_t j = 0; j < len; j++) { if (((msg->flags & I2C_FLAG_NO_START) == 0) && (j == 0)) { ifstart = 1; @@ -301,7 +299,6 @@ static int32_t i2c_send(struct I2cMsg *msg) static int32_t i2c_transfer(struct I2cDevice *device, struct I2cMsg *msgs, int16_t count) { - int ret; struct I2cMsg *msg = NULL; uint32_t i2cPort; diff --git a/adapter/platform/pwm/pwm_stm32f4xx.c b/adapter/platform/pwm/pwm_stm32f4xx.c index 3ae15c617930c87683fe53b2276da1e944ff80c4..5b6d3e046a3c256a0d65157f25627932445e74da 100644 --- a/adapter/platform/pwm/pwm_stm32f4xx.c +++ b/adapter/platform/pwm/pwm_stm32f4xx.c @@ -330,6 +330,7 @@ static int32_t PwmDriverBind(struct HdfDeviceObject *device) devService = (struct PwmDev *)OsalMemCalloc(sizeof(struct PwmDev)); if (devService == NULL) { HDF_LOGE("malloc pwmDev failed\n"); + return HDF_ERR_MALLOC_FAIL; } device->service = &devService->service; devService->device = device; diff --git a/adapter/platform/pwm/pwm_wm.c b/adapter/platform/pwm/pwm_wm.c index f43d12b840933ed04efa38087467fdcd42a84318..abb0e57189b887694adb4b91c13e8d925a9925b3 100755 --- a/adapter/platform/pwm/pwm_wm.c +++ b/adapter/platform/pwm/pwm_wm.c @@ -64,7 +64,6 @@ static int32_t PwmDevSetConfig(struct PwmDev *pwm, struct PwmConfig *config) static uint32_t GetPwmDeviceResource( struct PwmDevice *device, const struct DeviceResourceNode *resourceNode) { - uint32_t tempPin = 0; struct DeviceResourceIface *dri = NULL; struct PwmResource *resource = NULL; if (device == NULL || resourceNode == NULL) { diff --git a/adapter/platform/spi/spi_stm32f4xx.c b/adapter/platform/spi/spi_stm32f4xx.c index c09acc1fe34316e3fe7be58f523614d4ea032874..7b116ac8f53c019b956b4810be79e964f43e0441 100644 --- a/adapter/platform/spi/spi_stm32f4xx.c +++ b/adapter/platform/spi/spi_stm32f4xx.c @@ -665,9 +665,8 @@ static int32_t SpiDevGetCfg(struct SpiCntlr *spiCntlr, struct SpiCfg *spiCfg) spiCfg->maxSpeedHz = spiDevice->resource.baudRate; spiCfg->mode = spiDevice->resource.clkMode; spiCfg->transferMode = spiDevice->resource.transMode; - spiCfg->bitsPerWord = spiDevice->resource.dataWidth; - if (spiDevice->resource.dataWidth) { + if (spiDevice->resource.dataWidth == SPI_DATA_WIDTH_16) { spiCfg->bitsPerWord = BITWORD_SIXTEEN; } else { spiCfg->bitsPerWord = BITWORD_EIGHT; diff --git a/adapter/platform/spi/spi_wm.c b/adapter/platform/spi/spi_wm.c index 67ac1eff1b7098bd28852e0017b2b2ff9391ecf0..d8319fef5ce326d03c54119672e9bb1559735af4 100755 --- a/adapter/platform/spi/spi_wm.c +++ b/adapter/platform/spi/spi_wm.c @@ -224,7 +224,6 @@ static int32_t InitSpiDevice(struct SpiDevice *spiDevice) /* get spi config from hcs file */ static int32_t GetSpiDeviceResource(struct SpiDevice *spiDevice, const struct DeviceResourceNode *resourceNode) { - uint32_t relPin; struct SpiResource *resource = NULL; struct DeviceResourceIface *dri = NULL; if (spiDevice == NULL || resourceNode == NULL) { @@ -394,7 +393,6 @@ static void SpiDriverRelease(struct HdfDeviceObject *device) static int32_t SpiDevOpen(struct SpiCntlr *spiCntlr) { HDF_LOGI("Enter %s\r\n", __func__); - int ret; struct SpiDevice *spiDevice = NULL; struct SpiResource *resource = NULL; if (spiCntlr == NULL || spiCntlr->priv == NULL) { @@ -420,7 +418,6 @@ static int32_t SpiDevOpen(struct SpiCntlr *spiCntlr) static int32_t SpiDevClose(struct SpiCntlr *spiCntlr) { - int ret; struct SpiDevice *spiDevice = NULL; if (spiCntlr == NULL || spiCntlr->priv == NULL) { HDF_LOGE("%s: spiCntlr is NULL\r\n", __func__); diff --git a/adapter/platform/uart/uart_asr.c b/adapter/platform/uart/uart_asr.c index 448bea346963b4b923460dd1976883343769de79..fa3e1e0aac86eb9ea7b8b5211d618048843b53fa 100644 --- a/adapter/platform/uart/uart_asr.c +++ b/adapter/platform/uart/uart_asr.c @@ -416,7 +416,7 @@ static int32_t UartHostDevSetTransMode(struct UartHost *host, enum UartTransMode static int32_t UartDevSemInit(uint32_t id) { - uint32_t uwRet = 0; + uint32_t uwRet; uwRet = LOS_MuxCreate(&g_uartTxMutex[id]); if (uwRet != LOS_OK) { @@ -448,7 +448,7 @@ static void UartDevSemDeinit(uint32_t id) static int32_t UartHostDevInit(struct UartHost *host) { struct UartDriverData *udd = NULL; - uint32_t ret = 0; + uint32_t ret; uint8_t *ptxBuf = NULL; if (host == NULL || host->priv == NULL) { diff --git a/adapter/platform/uart/uart_bes.c b/adapter/platform/uart/uart_bes.c index 4567c771319d27ffc92aa35dab52edc49a32e12c..8aec34bdfb84fda79e251dcdbdeec3705719ec0a 100755 --- a/adapter/platform/uart/uart_bes.c +++ b/adapter/platform/uart/uart_bes.c @@ -204,7 +204,6 @@ static void HalUartStartRx(uint32_t uartId) static int32_t HalUartSend(uint32_t uartId, const void *data, uint32_t size, uint32_t timeOut) { - int32_t ret; struct HAL_DMA_DESC_T dmaSescTx; uint32_t descCnt; if (data == NULL || size == 0) { @@ -265,9 +264,7 @@ static int32_t HalUartRecv(uint8_t uartId, void *data, uint32_t expectSize, } } while (true); - if (recvSize != NULL) { - *recvSize = recvedLen; - } + *recvSize = recvedLen; return HDF_SUCCESS; } diff --git a/adapter/platform/uart/uart_gr5xx.c b/adapter/platform/uart/uart_gr5xx.c index 37ce5134351c7ea21b113ccc8a87aa9c32cd71cb..c9221a983207e42d28412575952633c028bd0d7a 100644 --- a/adapter/platform/uart/uart_gr5xx.c +++ b/adapter/platform/uart/uart_gr5xx.c @@ -402,7 +402,7 @@ static void UartDevSemDeinit(uint32_t id) static int32_t UartHostDevInit(struct UartHost *host) { struct UartDriverData *udd = NULL; - uint32_t ret = 0; + uint32_t ret; uint8_t *ptxBuf = NULL; if (host == NULL || host->priv == NULL) { diff --git a/adapter/platform/uart/uart_stm32f4xx.c b/adapter/platform/uart/uart_stm32f4xx.c index 9468c5035fdbe4874dd728647fbdbd8d8d6a952c..cbd60ae8930ed05bd6a92d4eb775c042a492bb52 100644 --- a/adapter/platform/uart/uart_stm32f4xx.c +++ b/adapter/platform/uart/uart_stm32f4xx.c @@ -323,7 +323,7 @@ struct UartHostMethod g_uartHostMethod = { static int InitUartDevice(struct UartHost *host) { - uint8_t initRet = 0; + uint8_t initRet; UartDevice *uartDevice = NULL; LL_USART_InitTypeDef *initTypedef = NULL; UartResource *resource = NULL; @@ -555,7 +555,6 @@ static int32_t AttachUartDevice(struct UartHost *uartHost, struct HdfDeviceObjec static int32_t UartDriverBind(struct HdfDeviceObject *device) { - struct UartHost *devService; if (device == NULL) { HDF_LOGE("%s: invalid parameter", __func__); return HDF_ERR_INVALID_PARAM; @@ -691,7 +690,6 @@ static int32_t UartHostDevWrite(struct UartHost *host, uint8_t *data, uint32_t s static int32_t UartHostDevRead(struct UartHost *host, uint8_t *data, uint32_t size) { - uint32_t recvSize = 0; int32_t ret; uint32_t uartId; UartDevice *uartDevice = NULL; diff --git a/adapter/platform/uart/uart_wm.c b/adapter/platform/uart/uart_wm.c index 3fc97066967a4ca097d231d1d3d932b0b43fb61d..bd3b52a2fdf48bf3b274c8612addd9315f36a5ec 100755 --- a/adapter/platform/uart/uart_wm.c +++ b/adapter/platform/uart/uart_wm.c @@ -116,8 +116,7 @@ static int32_t HalUartSend(uint32_t uartId, const uint8_t *data, uint32_t size, static int32_t HalUartRecv(uint8_t uartId, uint8_t *data, uint32_t expectSize, uint32_t *recvSize, uint32_t timeOut) { - int32_t ret = HDF_FAILURE; - uint32_t fifoPopLen = 0; + uint32_t fifoPopLen; uint32_t recvedLen = 0; uint32_t expectLen = expectSize; OsalTimespec hdfTs1 = { 0, 0 }; @@ -150,9 +149,7 @@ static int32_t HalUartRecv(uint8_t uartId, uint8_t *data, uint32_t expectSize, } } while (true); - if (recvSize != NULL) { - *recvSize = recvedLen; - } + *recvSize = recvedLen; return HDF_SUCCESS; } @@ -294,7 +291,7 @@ static uint32_t GetUartDeviceResource(struct UartDevice *device, const struct De return HDF_FAILURE; } - HDF_LOGI("%d, %d, %d, %d", resource->num, resource->baudRate, resource->parity); + HDF_LOGI("%d, %d, %d", resource->num, resource->baudRate, resource->parity); // copy config device->uartId = resource->num; diff --git a/adapter/uhdf2/hdi/src/devmgr_client.c b/adapter/uhdf2/hdi/src/devmgr_client.c index 280a7618bbce09c3fc2a4e4f36ad2d1149e24b44..789d13a6b51627d844cb41c301e6973f27939170 100644 --- a/adapter/uhdf2/hdi/src/devmgr_client.c +++ b/adapter/uhdf2/hdi/src/devmgr_client.c @@ -45,12 +45,11 @@ static int32_t HdfObtainDeviceInfo(struct DeviceInfoList *list, struct HdfSBuf * { struct DeviceInfoNode *node = NULL; const char *svrName = NULL; - int32_t svrNameLen; char *base = NULL; int32_t deviceType; while ((svrName = HdfSbufReadString(reply))) { - svrNameLen = strlen(svrName) + 1; + const size_t svrNameLen = strlen(svrName) + 1; base = (char *)OsalMemCalloc(sizeof(*node) + svrNameLen); if (base == NULL) { DevmgrFreeQueryDeviceListImpl(list); diff --git a/adapter/uhdf2/hdi/src/hdi_buffer_handle.cpp b/adapter/uhdf2/hdi/src/hdi_buffer_handle.cpp index a7fbf23133e9a8bbf8f901f827dc67a5fffada58..40bac83fb0bce906da23ac85711ba3a8278a1ecc 100644 --- a/adapter/uhdf2/hdi/src/hdi_buffer_handle.cpp +++ b/adapter/uhdf2/hdi/src/hdi_buffer_handle.cpp @@ -130,37 +130,6 @@ BufferHandle *HdiBufferHandle::Move() return handlePtr; } -std::string HdiBufferHandle::Dump() const -{ - std::stringstream os; - os << "{"; - if (handle_ != nullptr) { - os << "fd:" << handle_->fd << ", "; - os << "width:" << handle_->width << ", "; - os << "stride:" << handle_->stride << ", "; - os << "height:" << handle_->height << ", "; - os << "size:" << handle_->size << ", "; - os << "format:" << handle_->format << ", "; - os << "usage:" << handle_->usage << ", "; - os << "phyAddr:" << handle_->phyAddr << ", "; - os << "key:" << handle_->key << ", "; - os << "}\nreserveFds[" << handle_->reserveFds << "]:{"; - - uint32_t i = 0; - for (; i < handle_->reserveFds; i++) { - os << handle_->reserve[i] << ", "; - } - os << "},\nreserveInts[" << handle_->reserveInts << "]:{"; - - uint32_t n = 0; - for (; n < handle_->reserveInts; n++) { - os << handle_->reserve[i + n] << ", "; - } - } - os << "}\n"; - return os.str(); -} - bool HdiBufferHandle::ExtractFromParcel(Parcel &parcel) { MessageParcel &messageParcel = static_cast(parcel); diff --git a/adapter/uhdf2/host/src/devhost_service_full.c b/adapter/uhdf2/host/src/devhost_service_full.c index 48727f28a3b830801d3097a6008fac337b0142aa..c9331f5ce2950e666e02d66f509f22e27113563c 100644 --- a/adapter/uhdf2/host/src/devhost_service_full.c +++ b/adapter/uhdf2/host/src/devhost_service_full.c @@ -88,7 +88,7 @@ static int DevHostServiceFullDelDevice(struct IDevHostService *devHostService, d static int DevHostServiceFullDispatchPowerState(struct HdfDevice *device, uint32_t state) { struct HdfDeviceNode *deviceNode = NULL; - int ret = HDF_SUCCESS; + int ret; int result = HDF_SUCCESS; if (IsPowerWakeState(state)) { diff --git a/adapter/uhdf2/host/test/unittest/sample_driver/sample_hdi_service.cpp b/adapter/uhdf2/host/test/unittest/sample_driver/sample_hdi_service.cpp index 9242a22efc4d2065dedc437136d418822af8d105..35ccdf0b7e5e754c215e20c27ec8419337737d48 100644 --- a/adapter/uhdf2/host/test/unittest/sample_driver/sample_hdi_service.cpp +++ b/adapter/uhdf2/host/test/unittest/sample_driver/sample_hdi_service.cpp @@ -149,7 +149,7 @@ static int32_t SampleServiceTansSmq( return HDF_FAILURE; } static size_t elem = static_cast(element); - std::thread t([&]() { + std::thread t([]() { HDF_LOGI("SampleServiceTansSmq:smq read thread start, elem=%{public}zu", elem); std::shared_ptr> smqLocal = smq; size_t elemLocal = elem; diff --git a/adapter/uhdf2/ipc/src/hdf_remote_adapter.cpp b/adapter/uhdf2/ipc/src/hdf_remote_adapter.cpp index 1cf5ed8423e1f655519a75b13364dccd736bfd12..1258e17fe4b769f324b57b1bf89db02fee98ca5c 100644 --- a/adapter/uhdf2/ipc/src/hdf_remote_adapter.cpp +++ b/adapter/uhdf2/ipc/src/hdf_remote_adapter.cpp @@ -213,9 +213,7 @@ void HdfRemoteAdapterRecycle(struct HdfRemoteService *object) { struct HdfRemoteServiceHolder *holder = reinterpret_cast(object); if (holder != nullptr) { - if (holder->remote_ != nullptr) { - holder->remote_ = nullptr; - } + holder->remote_ = nullptr; delete holder; } } @@ -350,7 +348,7 @@ bool HdfRemoteAdapterCheckInterfaceToken(struct HdfRemoteService *service, struc return false; } struct HdfRemoteServiceHolder *holder = reinterpret_cast(service); - if (holder == nullptr || holder->remote_ == nullptr) { + if (holder->remote_ == nullptr) { return false; } OHOS::MessageParcel *parcel = nullptr; diff --git a/adapter/uhdf2/ipc/src/hdf_sbuf_impl_hipc.cpp b/adapter/uhdf2/ipc/src/hdf_sbuf_impl_hipc.cpp index 534e70d938575ed80456db028508e6d3d839b26f..0d31ae1c2cc6158f65d5c21b463fc6269a1e122a 100644 --- a/adapter/uhdf2/ipc/src/hdf_sbuf_impl_hipc.cpp +++ b/adapter/uhdf2/ipc/src/hdf_sbuf_impl_hipc.cpp @@ -334,10 +334,7 @@ static int32_t SbufMParcelImplWriteRemoteService(struct HdfSBufImpl *sbuf, const } MessageParcel *parcel = MParcelCast(sbuf); const struct HdfRemoteServiceHolder *holder = reinterpret_cast(service); - if (holder != nullptr) { - return parcel->WriteRemoteObject(holder->remote_) ? HDF_SUCCESS : HDF_FAILURE; - } - return HDF_FAILURE; + return parcel->WriteRemoteObject(holder->remote_) ? HDF_SUCCESS : HDF_FAILURE; } static struct HdfRemoteService *SbufMParcelImplReadRemoteService(struct HdfSBufImpl *sbuf) diff --git a/adapter/uhdf2/manager/src/devmgr_uevent.c b/adapter/uhdf2/manager/src/devmgr_uevent.c index f92dd4718d38fa9ba224b5b8a48530054e1f1dd0..02309dfcef8c6ed90c1ea759ab6232d81eca3343 100644 --- a/adapter/uhdf2/manager/src/devmgr_uevent.c +++ b/adapter/uhdf2/manager/src/devmgr_uevent.c @@ -109,7 +109,8 @@ static void DevMgrUeventReplaceLineFeed(char *str, const char *subStr, char c) while ((ptr = strstr(str, subStr)) != NULL) { ptr[0] = c; uint32_t i = 1; - for (; i < (strlen(ptr) - 1); i++) { + const size_t len = strlen(ptr) - 1; + for (; i < len; i++) { ptr[i] = ptr[i + 1]; } ptr[i] = '\0'; @@ -410,10 +411,9 @@ static bool DevMgrUeventMatchRule(struct DListHead *keyList, struct DListHead *r { struct DevMgrMatchKey *key = NULL; struct DevMgrMatchKey *keyMsg = NULL; - bool match = false; DLIST_FOR_EACH_ENTRY(key, ruleKeyList, struct DevMgrMatchKey, entry) { - match = false; + bool match = false; DLIST_FOR_EACH_ENTRY(keyMsg, keyList, struct DevMgrMatchKey, entry) { if (strcmp(key->key, keyMsg->key) == 0) { if (strcmp(key->value, keyMsg->value) == 0) { diff --git a/adapter/uhdf2/model/display/base/command_pack/command_data_packer.h b/adapter/uhdf2/model/display/base/command_pack/command_data_packer.h index 0602595ad0beea10ca08c053ba74531700c48607..1f6e08a117ed578f13037a5cb145f3177f029cbf 100644 --- a/adapter/uhdf2/model/display/base/command_pack/command_data_packer.h +++ b/adapter/uhdf2/model/display/base/command_pack/command_data_packer.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef DISPLAY_COMMAND_DATA_PACKER_H_ -#define DISPLAY_COMMAND_DATA_PACKER_H_ +#ifndef DISPLAY_COMMAND_DATA_PACKER_H +#define DISPLAY_COMMAND_DATA_PACKER_H #include #include @@ -230,4 +230,4 @@ private: } // namespace Display } // namespace HDI } // namespace OHOS -#endif // DISPLAY_COMMAND_DATA_PACKER_H_ +#endif // DISPLAY_COMMAND_DATA_PACKER_H diff --git a/adapter/uhdf2/model/display/base/command_pack/command_data_unpacker.h b/adapter/uhdf2/model/display/base/command_pack/command_data_unpacker.h index dad403a29966bf7fb1299e93bced3aa9821362fe..f845a82f7456157d3fec3c97f986e75002ad1f22 100644 --- a/adapter/uhdf2/model/display/base/command_pack/command_data_unpacker.h +++ b/adapter/uhdf2/model/display/base/command_pack/command_data_unpacker.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef DISPLAY_COMMAND_DATA_UNPACKER_H_ -#define DISPLAY_COMMAND_DATA_UNPACKER_H_ +#ifndef DISPLAY_COMMAND_DATA_UNPACKER_H +#define DISPLAY_COMMAND_DATA_UNPACKER_H #include #include "hdf_log.h" @@ -178,4 +178,4 @@ private: } // namespace Display } // namespace HDI } // namespace OHOS -#endif // DISPLAY_COMMAND_DATA_UNPACKER_H_ +#endif // DISPLAY_COMMAND_DATA_UNPACKER_H diff --git a/adapter/uhdf2/model/display/buffer/v1_0/hdi_impl/display_buffer_hdi_impl.h b/adapter/uhdf2/model/display/buffer/v1_0/hdi_impl/display_buffer_hdi_impl.h index 4fe2ba7aeb69665a18316c04fb6cc357d227bc93..20bffe2fd7ef66bc2ec7c1970e99938d84080b94 100644 --- a/adapter/uhdf2/model/display/buffer/v1_0/hdi_impl/display_buffer_hdi_impl.h +++ b/adapter/uhdf2/model/display/buffer/v1_0/hdi_impl/display_buffer_hdi_impl.h @@ -32,15 +32,15 @@ public: explicit DisplayBufferHdiImpl(bool isAllocLocal = false); virtual ~DisplayBufferHdiImpl() = default; - virtual int32_t AllocMem(const AllocInfo &info, BufferHandle *&handle) const override; - virtual void FreeMem(const BufferHandle &handle) const override; - virtual void *Mmap(const BufferHandle &handle) const override; - virtual void *MmapCache(const BufferHandle &handle) const override; - virtual int32_t Unmap(const BufferHandle &handle) const override; - virtual int32_t FlushCache(const BufferHandle &handle) const override; - virtual int32_t FlushMCache(const BufferHandle &handle) const override; - virtual int32_t InvalidateCache(const BufferHandle &handle) const override; - virtual int32_t IsSupportedAlloc( + int32_t AllocMem(const AllocInfo &info, BufferHandle *&handle) const override; + void FreeMem(const BufferHandle &handle) const override; + void *Mmap(const BufferHandle &handle) const override; + void *MmapCache(const BufferHandle &handle) const override; + int32_t Unmap(const BufferHandle &handle) const override; + int32_t FlushCache(const BufferHandle &handle) const override; + int32_t FlushMCache(const BufferHandle &handle) const override; + int32_t InvalidateCache(const BufferHandle &handle) const override; + int32_t IsSupportedAlloc( const std::vector &infos, std::vector &supporteds) const override; private: diff --git a/adapter/uhdf2/osal/test/unittest/common/osal_slist_test.cpp b/adapter/uhdf2/osal/test/unittest/common/osal_slist_test.cpp index 42ac075b8a8d6df49ff57c21527653e2dcbd6e01..ccdd4e893e43109f09ce6ba0336c1fb393f806a9 100644 --- a/adapter/uhdf2/osal/test/unittest/common/osal_slist_test.cpp +++ b/adapter/uhdf2/osal/test/unittest/common/osal_slist_test.cpp @@ -96,6 +96,7 @@ static void HdfOsalSlistTestInit(struct HdfSList *list, int &totalCount, HdfSLis totalCount = static_cast(sizeof(insertData) / sizeof(insertData[0])); for (int i = 0; i < totalCount; i++) { struct TestList *testData = reinterpret_cast(OsalMemAlloc(sizeof(struct TestList))); + ASSERT_NE(testData, nullptr); testData->data = insertData[i]; ops(list, &testData->entry); } diff --git a/adapter/uhdf2/test/BUILD.gn b/adapter/uhdf2/test/BUILD.gn index d2e20fd4e647ce45dfdc4fbde1ed3100611c94bd..607c73cd674bde90228a2a7189cf6b21d7df5f0f 100644 --- a/adapter/uhdf2/test/BUILD.gn +++ b/adapter/uhdf2/test/BUILD.gn @@ -28,9 +28,11 @@ if (hdf_core_khdf_test_support) { "unittest/manager:hdf_adapter_uhdf_test_uevent", "unittest/osal:hdf_adapter_uhdf_test_osal", "unittest/osal:hdf_adapter_uhdf_test_osal_posix", - "unittest/platform:hdf_adapter_uhdf_test_platform", "//drivers/hdf_core/framework/test/fuzztest:hdf_framework_fuzztest", ] + if (product_name == "rk3568") { + deps += [ "unittest/platform:hdf_adapter_uhdf_test_platform" ] + } } } else { group("hdf_test_uhdf") { @@ -39,8 +41,10 @@ if (hdf_core_khdf_test_support) { "fuzztest:hdf_platform_test", "unittest/manager:hdf_adapter_uhdf_test_sbuf", "unittest/osal:hdf_adapter_uhdf_test_osal_posix", - "unittest/platform:hdf_adapter_uhdf_test_platform", "//drivers/hdf_core/framework/test/fuzztest:hdf_framework_fuzztest", ] + if (product_name == "rk3568") { + deps += [ "unittest/platform:hdf_adapter_uhdf_test_platform" ] + } } } diff --git a/framework/core/host/src/devhost_service.c b/framework/core/host/src/devhost_service.c index b14a484dfc12b9faa5cfe3ea953defe70d8f19d5..33836a52c05e5627fb43cae479bcae6c8f56875f 100644 --- a/framework/core/host/src/devhost_service.c +++ b/framework/core/host/src/devhost_service.c @@ -159,7 +159,7 @@ static int DevHostServiceStartService(struct IDevHostService *service) static int ApplyDevicesPowerState(struct HdfDevice *device, uint32_t state) { struct HdfDeviceNode *deviceNode = NULL; - int ret = HDF_SUCCESS; + int ret; /* The power management strategy is to ignore devices that fail to operate and avoid more devices that fail to sleep or wake up */ diff --git a/framework/core/manager/src/devmgr_service.c b/framework/core/manager/src/devmgr_service.c index 0ace2366e371f441379a1e8c429981e4f430d5f8..1728726d9fc9afca3801852b0223f0b5eb9cc4f2 100644 --- a/framework/core/manager/src/devmgr_service.c +++ b/framework/core/manager/src/devmgr_service.c @@ -108,7 +108,14 @@ static int DevmgrServiceLoadDevice(struct IDevmgrService *devMgrSvc, const char HDF_LOGW("failed to start device host(%{public}s, %{public}u)", hostClnt->hostName, hostClnt->hostId); return HDF_FAILURE; } + OsalMutexLock(&hostClnt->hostLock); + if (hostClnt->hostService == NULL || hostClnt->hostService->AddDevice == NULL) { + OsalMutexUnlock(&hostClnt->hostLock); + HDF_LOGE("%{public}s load %{public}s failed, hostService is null", __func__, serviceName); + return HDF_FAILURE; + } ret = hostClnt->hostService->AddDevice(hostClnt->hostService, deviceInfo); + OsalMutexUnlock(&hostClnt->hostLock); if (ret == HDF_SUCCESS) { deviceInfo->status = HDF_SERVICE_USABLE; } @@ -143,11 +150,14 @@ static int DevmgrServiceUnloadDevice(struct IDevmgrService *devMgrSvc, const cha HDF_LOGE("device %{public}s not in configed dynamic device list", serviceName); return HDF_DEV_ERR_NO_DEVICE; } - - if (hostClnt->hostService == NULL) { + OsalMutexLock(&hostClnt->hostLock); + if (hostClnt->hostService == NULL || hostClnt->hostService->DelDevice == NULL) { + OsalMutexUnlock(&hostClnt->hostLock); + HDF_LOGE("%{public}s unload %{public}s failed, hostService is null", __func__, serviceName); return HDF_FAILURE; } ret = hostClnt->hostService->DelDevice(hostClnt->hostService, deviceInfo->deviceId); + OsalMutexUnlock(&hostClnt->hostLock); if (ret != HDF_SUCCESS) { HDF_LOGI("%{public}s:unload service %{public}s delDevice failed", __func__, serviceName); return ret; diff --git a/framework/core/manager/test/unittest/common/hdf_ioservice_test.cpp b/framework/core/manager/test/unittest/common/hdf_ioservice_test.cpp index d5b798b725875dec21286265cde504e45cff8275..108a7aa7c2bd16060a14387bd2675e72fe1629dd 100644 --- a/framework/core/manager/test/unittest/common/hdf_ioservice_test.cpp +++ b/framework/core/manager/test/unittest/common/hdf_ioservice_test.cpp @@ -83,8 +83,8 @@ int IoServiceTest::OnDevEventReceived( { OsalTimespec time; OsalGetTime(&time); - HDF_LOGE("%s: received event[%d] from %s at %" PRIu64 ".%" PRIu64 "", (char *)listener->priv, eventCount++, - (char *)service->priv, time.sec, time.usec); + HDF_LOGE("%s: received event[%d] from %s at %" PRIu64 ".%" PRIu64 "", static_cast(listener->priv), + eventCount++, static_cast(service->priv), time.sec, time.usec); const char *string = HdfSbufReadString(data); if (string == nullptr) { @@ -93,7 +93,7 @@ int IoServiceTest::OnDevEventReceived( } struct Eventlistener *l = CONTAINER_OF(listener, struct Eventlistener, listener); l->eventCount++; - HDF_LOGE("%s: dev event received: %u %s", (char *)service->priv, id, string); + HDF_LOGE("%s: dev event received: %u %s", static_cast(service->priv), id, string); return 0; } @@ -701,7 +701,7 @@ struct IoServiceStatusData { static void TestOnServiceStatusReceived(struct ServiceStatusListener *listener, struct ServiceStatus *servstat) { - struct IoServiceStatusData *issd = (struct IoServiceStatusData *)listener->priv; + struct IoServiceStatusData *issd = static_cast(listener->priv); if (issd == nullptr) { return; } diff --git a/framework/core/shared/include/hdf_usb_pnp_manage.h b/framework/core/shared/include/hdf_usb_pnp_manage.h index d68f76fe207c31b1ce68bc1b3ee0c7ef52601649..0f0c811d12aaf8e4a49fbbfa03f6a1e3a4f19c6b 100644 --- a/framework/core/shared/include/hdf_usb_pnp_manage.h +++ b/framework/core/shared/include/hdf_usb_pnp_manage.h @@ -31,6 +31,7 @@ enum UsbPnpNotifyServiceCmd { USB_PNP_DRIVER_GADGET_REMOVE, USB_PNP_DRIVER_PORT_HOST = 40, USB_PNP_DRIVER_PORT_DEVICE, + USB_PNP_DRIVER_GET_GADGET_LINK_STATUS, }; enum UsbPnpNotifyRemoveType { diff --git a/framework/model/audio/common/src/audio_codec_base.c b/framework/model/audio/common/src/audio_codec_base.c index 6b3217f1a4a76cc8e6a94172bb1edf42851f917b..234df6b38d59a8e0532e026f81131b2cbaf7450b 100644 --- a/framework/model/audio/common/src/audio_codec_base.c +++ b/framework/model/audio/common/src/audio_codec_base.c @@ -458,6 +458,7 @@ static void CodecI2cRelease(struct I2cMsg *msgs, int16_t msgSize, DevHandle i2cH msgs[0].buf = NULL; } else if (msgSize >= I2C_MSG_NUM) { if (msgs[0].buf != NULL) { + OsalMemFree(msgs[0].buf); msgs[0].buf = NULL; } if (msgs[1].buf != NULL) { @@ -542,7 +543,7 @@ static int32_t CodecI2cTransfer(struct I2cTransferParam *i2cTransferParam, struc (void)memset_s(msgs, sizeof(struct I2cMsg) * I2C_MSG_NUM, 0, sizeof(struct I2cMsg) * I2C_MSG_NUM); AUDIO_DRIVER_LOG_DEBUG("entry.\n"); - if (i2cTransferParam == NULL || regAttr == NULL || rwFlag < 0 || rwFlag > 1) { + if (i2cTransferParam == NULL || regAttr == NULL || rwFlag > 1) { AUDIO_DRIVER_LOG_ERR("invalid parameter."); return HDF_ERR_INVALID_PARAM; } diff --git a/framework/model/audio/common/src/audio_platform_base.c b/framework/model/audio/common/src/audio_platform_base.c index 38ab1ace8cbd3f6e9ce4ca815e8287ec35ee3f01..46e93131ca73c89bf2dfd35e9bbaafbf1533f53b 100755 --- a/framework/model/audio/common/src/audio_platform_base.c +++ b/framework/model/audio/common/src/audio_platform_base.c @@ -156,7 +156,6 @@ int32_t AudioSetPcmInfo(struct PlatformData *platformData, const struct AudioPcm platformData->renderPcmInfo.silenceThreshold = param->silenceThreshold; platformData->renderPcmInfo.interleaved = INTERLEAVED; - platformData->renderPcmInfo.channels = param->channels; platformData->renderPcmInfo.streamType = param->streamType; } else if (param->streamType == AUDIO_CAPTURE_STREAM) { if (AudioFormatToBitWidth(param->format, &platformData->capturePcmInfo.bitWidth) != HDF_SUCCESS) { @@ -175,7 +174,6 @@ int32_t AudioSetPcmInfo(struct PlatformData *platformData, const struct AudioPcm platformData->capturePcmInfo.silenceThreshold = param->silenceThreshold; platformData->capturePcmInfo.interleaved = INTERLEAVED; - platformData->capturePcmInfo.channels = param->channels; platformData->capturePcmInfo.streamType = param->streamType; } else { AUDIO_DRIVER_LOG_ERR("streamType is invalid."); diff --git a/framework/model/audio/sapm/src/audio_sapm.c b/framework/model/audio/sapm/src/audio_sapm.c index 8685b537cd6fe1c7d53e91b04d27a2e729362e16..39160ae6b2e3f9a7f12c99035d12aa14665b8b89 100644 --- a/framework/model/audio/sapm/src/audio_sapm.c +++ b/framework/model/audio/sapm/src/audio_sapm.c @@ -1353,7 +1353,6 @@ int32_t AudioCodecSapmSetCtrlOps(const struct AudioKcontrol *kcontrol, const str uint32_t pathStatus = 0; struct CodecDevice *codec = NULL; struct AudioMixerControl *mixerCtrl = NULL; - struct AudioCard *audioCard = NULL; if ((kcontrol == NULL) || (kcontrol->privateValue <= 0) || (kcontrol->pri == NULL)) { ADM_LOG_ERR("input params: kcontrol is NULL."); return HDF_ERR_INVALID_OBJECT; @@ -1362,7 +1361,6 @@ int32_t AudioCodecSapmSetCtrlOps(const struct AudioKcontrol *kcontrol, const str ADM_LOG_ERR("input params: elemValue is NULL."); return HDF_ERR_INVALID_OBJECT; } - audioCard = (struct AudioCard *)((volatile uintptr_t)(kcontrol->pri)); mixerCtrl = (struct AudioMixerControl *)((volatile uintptr_t)kcontrol->privateValue); if (AudioSapmSetCtrlOps(kcontrol, elemValue, &value, &pathStatus) != HDF_SUCCESS) { diff --git a/framework/model/input/driver/hdf_input_device_manager.h b/framework/model/input/driver/hdf_input_device_manager.h index fca8fdf31ec03577beeeb498c8578026a9078ae8..00d5e165589e97725ca9b79fff2b1d051f5a25e0 100644 --- a/framework/model/input/driver/hdf_input_device_manager.h +++ b/framework/model/input/driver/hdf_input_device_manager.h @@ -166,7 +166,7 @@ enum TouchIoctlCmd { INPUT_IOCTL_RUN_EXTRA_CMD, }; InputManager* GetInputManager(void); -int32_t RegisterInputDevice(InputDevice *device); +int32_t RegisterInputDevice(InputDevice *inputDev); void UnregisterInputDevice(InputDevice *inputDev); #endif \ No newline at end of file diff --git a/framework/model/network/wifi/core/hdf_wifi_core.c b/framework/model/network/wifi/core/hdf_wifi_core.c index 8b5a8023db90cf21f2f56dc5d4c852d35591bb9d..c75a51681bad821473bf47dc006b1109e90ae0d3 100644 --- a/framework/model/network/wifi/core/hdf_wifi_core.c +++ b/framework/model/network/wifi/core/hdf_wifi_core.c @@ -120,33 +120,6 @@ static struct HdfConfigWlanDeviceList *HdfWlanGetDeviceList(void) return &rootConfig->wlanConfig.deviceList; } -/* CreatePowerMgrByConfig,call by HdfWlanMainInit */ -struct PowerManager *HdfWlanCreatePowerMgrByConfig(void) -{ - struct HdfConfWlanPowers *powerConfig = NULL; - struct HdfConfigWlanRoot *rootConfig = HdfWlanGetModuleConfigRoot(); - if (rootConfig == NULL) { - HDF_LOGE("%s: HdfWlanGetModuleConfigRoot get failed", __func__); - return NULL; - } - powerConfig = &rootConfig->wlanConfig.deviceList.deviceInst[0].powers; - return HdfWlanCreatePowerManager(powerConfig); -} - -struct ResetManager *CreateResetMgrByConfig(void) -{ - uint8_t bootUpTimeOut; - struct HdfConfWlanRest *resetConfig = NULL; - struct HdfConfigWlanRoot *rootConfig = HdfWlanGetModuleConfigRoot(); - if (rootConfig == NULL) { - HDF_LOGE("%s: HdfWlanGetModuleConfigRoot get failed", __func__); - return NULL; - } - resetConfig = &rootConfig->wlanConfig.deviceList.deviceInst[0].reset; - bootUpTimeOut = rootConfig->wlanConfig.deviceList.deviceInst[0].bootUpTimeOut; - return HdfWlanCreateResetManager(resetConfig, bootUpTimeOut); -} - /* get wlan related config */ static int32_t HdfWlanGetConfig(const struct HdfDeviceObject *device) { @@ -553,6 +526,10 @@ static int32_t HdfWlanMainInit(struct HdfDeviceObject *device) } /* feature init */ rootConfig = HdfWlanGetModuleConfigRoot(); + if (rootConfig == NULL) { + HDF_LOGE("%s: HdfWlanGetModuleConfigRoot get failed", __func__); + return HDF_FAILURE; + } moduleConfig = &rootConfig->wlanConfig.moduleConfig; if (HdfWlanInitProduct(device, moduleConfig) != HDF_SUCCESS) { HDF_LOGE("%s:HdfWlanInitProduct failed!", __func__); diff --git a/framework/model/network/wifi/platform/src/message/message_dispatcher.h b/framework/model/network/wifi/platform/src/message/message_dispatcher.h index f56f708f71bd9fd21da56b804090abd0c5d6e032..d86db25d6a5e00f91f65837b3b174f2cc679f2a6 100644 --- a/framework/model/network/wifi/platform/src/message/message_dispatcher.h +++ b/framework/model/network/wifi/platform/src/message/message_dispatcher.h @@ -37,7 +37,7 @@ void ReleaseMessageMapper(struct ServiceDef *mapper); void ReleaseMessageContext(MessageContext *context); void SetToResponse(MessageContext *context); -struct MessageDef* GetMsgDef(const struct ServiceDef *mapper, uint32_t commandID); +struct MessageDef *GetMsgDef(const struct ServiceDef *serviceDef, uint32_t commandId); ErrorCode CreateLocalDispatcher(MessageDispatcher **dispatcher, const DispatcherConfig *config); diff --git a/framework/model/network/wifi/platform/src/message/message_router.c b/framework/model/network/wifi/platform/src/message/message_router.c index 5365659626e61289c89f81dfa7b4ab3eebc48463..86ea0a1b7fa6abf3122c6b8ea2015edc2c4fa736 100644 --- a/framework/model/network/wifi/platform/src/message/message_router.c +++ b/framework/model/network/wifi/platform/src/message/message_router.c @@ -624,7 +624,7 @@ ErrorCode StartMessageRouter(uint8_t nodesConfig) HDF_STATUS status; ErrorCode errCode; if (g_routerMutex.realMutex == NULL) { - HDF_STATUS status = OsalMutexInit(&g_routerMutex); + status = OsalMutexInit(&g_routerMutex); if (status != HDF_SUCCESS) { HDF_LOGE("%s: Init mutex failed! status=%d", __func__, status); return ME_ERROR_OPER_MUTEX_FAILED; diff --git a/framework/model/network/wifi/platform/src/message/message_router_inner.h b/framework/model/network/wifi/platform/src/message/message_router_inner.h index 9359af6bf855cacd557dd416288c06b0d2df3107..8ef4dc0e757493769aca526e3c42ad57455ee234 100644 --- a/framework/model/network/wifi/platform/src/message/message_router_inner.h +++ b/framework/model/network/wifi/platform/src/message/message_router_inner.h @@ -50,7 +50,7 @@ typedef struct RemoteService { INHERT_REMOTE_SERVICE; } RemoteService; -RemoteService *RefRemoteService(ServiceId id); +RemoteService *RefRemoteService(ServiceId serviceId); ErrorCode SendMessage(MessageContext *context); diff --git a/framework/model/storage/src/mmc/sdio_if.c b/framework/model/storage/src/mmc/sdio_if.c index cd05ef458d5aa6238f7afe5320b57aa4f962db67..2bd0afb07047718f757538d0746ccf708496df30 100644 --- a/framework/model/storage/src/mmc/sdio_if.c +++ b/framework/model/storage/src/mmc/sdio_if.c @@ -58,7 +58,7 @@ DevHandle SdioOpen(int16_t mmcBusNum, struct SdioFunctionConfig *config) return NULL; } cntlr = (struct MmcCntlr *)handle; - if (cntlr != NULL && cntlr->ops != NULL && cntlr->ops->rescanSdioDev != NULL) { + if (cntlr->ops != NULL && cntlr->ops->rescanSdioDev != NULL) { ret = cntlr->ops->rescanSdioDev(cntlr); if (ret != HDF_SUCCESS) { HDF_LOGE("SdioOpen: sdio rescan fail!"); diff --git a/framework/model/usb/include/usb_ddk_pnp_loader.h b/framework/model/usb/include/usb_ddk_pnp_loader.h index 8b112e7800686df3361178fd0254cc4f50b7b766..09dfc25d1715e31892ea153424ae844aea79d618 100644 --- a/framework/model/usb/include/usb_ddk_pnp_loader.h +++ b/framework/model/usb/include/usb_ddk_pnp_loader.h @@ -12,13 +12,7 @@ #include "devmgr_service_if.h" #include "hdf_usb_pnp_manage.h" -#define USB_PNP_NOTIFY_SERVICE_NAME "hdf_usb_pnp_notify_service" - -typedef enum { - USB_PNP_NORMAL_STATUS, - USB_PNP_ADD_STATUS, - USB_PNP_REMOVE_STATUS -} UsbPnpDriverStatus; +typedef enum { USB_PNP_NORMAL_STATUS, USB_PNP_ADD_STATUS, USB_PNP_REMOVE_STATUS } UsbPnpDriverStatus; struct UsbPnpMatchIdTable { const char *moduleName; diff --git a/framework/model/usb/src/usb_ddk_pnp_loader.c b/framework/model/usb/src/usb_ddk_pnp_loader.c index 0c05a1dd640fa205768619a0c9681570ddcb0c1c..3dd17ea9283a90355d62d373b61302669c637cef 100644 --- a/framework/model/usb/src/usb_ddk_pnp_loader.c +++ b/framework/model/usb/src/usb_ddk_pnp_loader.c @@ -25,13 +25,13 @@ #define HDF_LOG_TAG USB_DDK_PNP_LOADER -#define USB_DDK_PNP_CLASS_VENDOR_SPEC 0xFF +#define USB_DDK_PNP_CLASS_VENDOR_SPEC 0xFF static struct DListHead g_usbPnpDeviceTableListHead; static struct UsbPnpMatchIdTable **g_usbPnpMatchIdTable = NULL; -static struct HdfSBuf *UsbDdkPnpLoaderBufCreate(const char *moduleName, - const char *serviceName, const char *deviceMatchAttr, struct UsbPnpNotifyServiceInfo serviceInfo) +static struct HdfSBuf *UsbDdkPnpLoaderBufCreate(const char *moduleName, const char *serviceName, + const char *deviceMatchAttr, struct UsbPnpNotifyServiceInfo serviceInfo) { struct HdfSBuf *pnpData = NULL; @@ -69,41 +69,34 @@ OUT: return NULL; } -static bool UsbDdkPnpLoaderMatchDevice(const struct UsbPnpNotifyMatchInfoTable *dev, - const struct UsbPnpMatchIdTable *id) +static bool UsbDdkPnpLoaderMatchDevice( + const struct UsbPnpNotifyMatchInfoTable *dev, const struct UsbPnpMatchIdTable *id) { - if ((id->matchFlag & USB_PNP_NOTIFY_MATCH_VENDOR) && - (id->vendorId != dev->deviceInfo.vendorId)) { + if ((id->matchFlag & USB_PNP_NOTIFY_MATCH_VENDOR) && (id->vendorId != dev->deviceInfo.vendorId)) { return false; } - if ((id->matchFlag & USB_PNP_NOTIFY_MATCH_PRODUCT) && - (id->productId != dev->deviceInfo.productId)) { + if ((id->matchFlag & USB_PNP_NOTIFY_MATCH_PRODUCT) && (id->productId != dev->deviceInfo.productId)) { return false; } - if ((id->matchFlag & USB_PNP_NOTIFY_MATCH_DEV_LOW) && - (id->bcdDeviceLow > dev->deviceInfo.bcdDeviceLow)) { + if ((id->matchFlag & USB_PNP_NOTIFY_MATCH_DEV_LOW) && (id->bcdDeviceLow > dev->deviceInfo.bcdDeviceLow)) { return false; } - if ((id->matchFlag & USB_PNP_NOTIFY_MATCH_DEV_HIGH) && - (id->bcdDeviceHigh < dev->deviceInfo.bcdDeviceHigh)) { + if ((id->matchFlag & USB_PNP_NOTIFY_MATCH_DEV_HIGH) && (id->bcdDeviceHigh < dev->deviceInfo.bcdDeviceHigh)) { return false; } - if ((id->matchFlag & USB_PNP_NOTIFY_MATCH_DEV_CLASS) && - (id->deviceClass != dev->deviceInfo.deviceClass)) { + if ((id->matchFlag & USB_PNP_NOTIFY_MATCH_DEV_CLASS) && (id->deviceClass != dev->deviceInfo.deviceClass)) { return false; } - if ((id->matchFlag & USB_PNP_NOTIFY_MATCH_DEV_SUBCLASS) && - (id->deviceSubClass != dev->deviceInfo.deviceSubClass)) { + if ((id->matchFlag & USB_PNP_NOTIFY_MATCH_DEV_SUBCLASS) && (id->deviceSubClass != dev->deviceInfo.deviceSubClass)) { return false; } - if ((id->matchFlag & USB_PNP_NOTIFY_MATCH_DEV_PROTOCOL) && - (id->deviceProtocol != dev->deviceInfo.deviceProtocol)) { + if ((id->matchFlag & USB_PNP_NOTIFY_MATCH_DEV_PROTOCOL) && (id->deviceProtocol != dev->deviceInfo.deviceProtocol)) { return false; } @@ -189,8 +182,8 @@ int32_t UsbPnpManagerRegisterOrUnregisterDevice(struct UsbPnpManagerDeviceInfo * return managerInfo->isReg ? UsbPnpManagerRegisterDevice(managerInfo) : UsbPnpManagerUnregisterDevice(managerInfo); } -static void UsbDdkPnpLoaderMatchHandle(const struct UsbPnpNotifyMatchInfoTable *dev, - int8_t index, struct UsbPnpMatchIdTable *id, bool flag) +static void UsbDdkPnpLoaderMatchHandle( + const struct UsbPnpNotifyMatchInfoTable *dev, int8_t index, struct UsbPnpMatchIdTable *id, bool flag) { if ((!id->pnpMatchFlag) && flag) { if (!(id->matchFlag & USB_PNP_NOTIFY_MATCH_INT_CLASS)) { @@ -243,8 +236,8 @@ OUT: return ret; } -static bool UsbDdkPnpLoaderMatchFlag(const struct UsbPnpNotifyMatchInfoTable *dev, - int8_t index, struct UsbPnpMatchIdTable *id, bool flag) +static bool UsbDdkPnpLoaderMatchFlag( + const struct UsbPnpNotifyMatchInfoTable *dev, int8_t index, struct UsbPnpMatchIdTable *id, bool flag) { int32_t i; bool ret = true; @@ -286,8 +279,8 @@ OUT: return ret; } -static bool UsbDdkPnpLoaderMatchInterface(const struct UsbPnpNotifyMatchInfoTable *dev, - int8_t index, struct UsbPnpMatchIdTable *id) +static bool UsbDdkPnpLoaderMatchInterface( + const struct UsbPnpNotifyMatchInfoTable *dev, int8_t index, struct UsbPnpMatchIdTable *id) { int32_t i; bool maskFlag = true; @@ -347,15 +340,16 @@ static bool UsbDdkPnpLoaderMatchInterface(const struct UsbPnpNotifyMatchInfoTabl return maskFlag; } -static bool UsbDdkPnpLoaderMatchOneIdIntf(const struct UsbPnpNotifyMatchInfoTable *dev, - int8_t index, struct UsbPnpMatchIdTable *id) +static bool UsbDdkPnpLoaderMatchOneIdIntf( + const struct UsbPnpNotifyMatchInfoTable *dev, int8_t index, struct UsbPnpMatchIdTable *id) { bool maskFlag = true; if (dev->deviceInfo.deviceClass == USB_DDK_PNP_CLASS_VENDOR_SPEC && !(id->matchFlag & USB_PNP_NOTIFY_MATCH_VENDOR) && - (id->matchFlag & (USB_PNP_NOTIFY_MATCH_INT_CLASS | USB_PNP_NOTIFY_MATCH_INT_SUBCLASS | - USB_PNP_NOTIFY_MATCH_INT_PROTOCOL | USB_PNP_NOTIFY_MATCH_INT_NUMBER))) { + (id->matchFlag & + (USB_PNP_NOTIFY_MATCH_INT_CLASS | USB_PNP_NOTIFY_MATCH_INT_SUBCLASS | USB_PNP_NOTIFY_MATCH_INT_PROTOCOL | + USB_PNP_NOTIFY_MATCH_INT_NUMBER))) { return false; } @@ -382,8 +376,8 @@ static int32_t UsbDdkPnpLoaderParseIdInfClass(const struct DeviceResourceNode *n HDF_LOGE("%s: read interfaceClass length=%d fail!", __func__, table->interfaceClassLength); return HDF_FAILURE; } - if (devResIface->GetUint8Array(node, "interfaceClass", table->interfaceClass, \ - table->interfaceClassLength, 0) != HDF_SUCCESS) { + if (devResIface->GetUint8Array(node, "interfaceClass", table->interfaceClass, table->interfaceClassLength, 0) != + HDF_SUCCESS) { HDF_LOGE("%s: read interfaceClass fail!", __func__); return HDF_FAILURE; } @@ -394,12 +388,11 @@ static int32_t UsbDdkPnpLoaderParseIdInfClass(const struct DeviceResourceNode *n table->interfaceSubClassMask = 0; table->interfaceSubClassLength = devResIface->GetElemNum(node, "interfaceSubClass"); if (table->interfaceSubClassLength <= 0) { - HDF_LOGE("%s: read interfaceSubClass length=%d fail!", - __func__, table->interfaceSubClassLength); + HDF_LOGE("%s: read interfaceSubClass length=%d fail!", __func__, table->interfaceSubClassLength); return HDF_FAILURE; } - if (devResIface->GetUint8Array(node, "interfaceSubClass", table->interfaceSubClass, \ - table->interfaceSubClassLength, 0) != HDF_SUCCESS) { + if (devResIface->GetUint8Array( + node, "interfaceSubClass", table->interfaceSubClass, table->interfaceSubClassLength, 0) != HDF_SUCCESS) { HDF_LOGE("%s: read interfaceSubClass fail!", __func__); return HDF_FAILURE; } @@ -410,7 +403,6 @@ static int32_t UsbDdkPnpLoaderParseIdInfClass(const struct DeviceResourceNode *n return HDF_SUCCESS; } - static int32_t UsbDdkPnpLoaderParseIdInferface(const struct DeviceResourceNode *node, const struct DeviceResourceIface *devResIface, struct UsbPnpMatchIdTable *table) { @@ -421,12 +413,11 @@ static int32_t UsbDdkPnpLoaderParseIdInferface(const struct DeviceResourceNode * table->interfaceProtocolMask = 0; table->interfaceProtocolLength = devResIface->GetElemNum(node, "interfaceProtocol"); if (table->interfaceProtocolLength <= 0) { - HDF_LOGE("%s: read interfaceProtocol length=%d fail!", - __func__, table->interfaceProtocolLength); + HDF_LOGE("%s: read interfaceProtocol length=%d fail!", __func__, table->interfaceProtocolLength); return HDF_FAILURE; } - if (devResIface->GetUint8Array(node, "interfaceProtocol", table->interfaceProtocol, \ - table->interfaceProtocolLength, 0) != HDF_SUCCESS) { + if (devResIface->GetUint8Array( + node, "interfaceProtocol", table->interfaceProtocol, table->interfaceProtocolLength, 0) != HDF_SUCCESS) { HDF_LOGE("%s: read interfaceProtocol fail!", __func__); return HDF_FAILURE; } @@ -440,8 +431,8 @@ static int32_t UsbDdkPnpLoaderParseIdInferface(const struct DeviceResourceNode * HDF_LOGE("%s: read interfaceNumber length=%d fail!", __func__, table->interfaceLength); return HDF_FAILURE; } - if (devResIface->GetUint8Array(node, "interfaceNumber", table->interfaceNumber, \ - table->interfaceLength, 0) != HDF_SUCCESS) { + if (devResIface->GetUint8Array(node, "interfaceNumber", table->interfaceNumber, table->interfaceLength, 0) != + HDF_SUCCESS) { HDF_LOGE("%s: read interfaceNumber fail!", __func__); return HDF_FAILURE; } @@ -662,8 +653,8 @@ static struct UsbPnpMatchIdTable **UsbDdkPnpLoaderPnpMatch(void) return UsbDdkPnpLoaderParseDeviceId(usbPnpNode); } -static int32_t UsbDdkPnpLoaderDispatchPnpDevice(struct HdfDeviceObject *usbPnpManagerDevice, - struct HdfSBuf *data, bool isReg) +static int32_t UsbDdkPnpLoaderDispatchPnpDevice( + struct HdfDeviceObject *usbPnpManagerDevice, struct HdfSBuf *data, bool isReg) { uint32_t infoSize = 0; struct UsbPnpNotifyServiceInfo *privateData = NULL; @@ -698,8 +689,8 @@ static int32_t UsbDdkPnpLoaderDispatchPnpDevice(struct HdfDeviceObject *usbPnpMa return UsbPnpManagerRegisterOrUnregisterDevice(&managerInfo); } -static int32_t UsbDdkPnpLoaderDeviceListAdd(const struct UsbPnpNotifyMatchInfoTable *info, - const struct UsbPnpMatchIdTable *idTable) +static int32_t UsbDdkPnpLoaderDeviceListAdd( + const struct UsbPnpNotifyMatchInfoTable *info, const struct UsbPnpMatchIdTable *idTable) { int32_t ret; unsigned char *ptr = NULL; @@ -721,13 +712,13 @@ static int32_t UsbDdkPnpLoaderDeviceListAdd(const struct UsbPnpNotifyMatchInfoTa deviceTableListTemp->devNum = info->devNum; deviceTableListTemp->busNum = info->busNum; deviceTableListTemp->interfaceLength = idTable->interfaceLength; - ret = memcpy_s(deviceTableListTemp->interfaceNumber, USB_PNP_INFO_MAX_INTERFACES, \ - idTable->interfaceNumber, USB_PNP_INFO_MAX_INTERFACES); + ret = memcpy_s(deviceTableListTemp->interfaceNumber, USB_PNP_INFO_MAX_INTERFACES, idTable->interfaceNumber, + USB_PNP_INFO_MAX_INTERFACES); if (ret != HDF_SUCCESS) { HDF_LOGE("%{public}s:%{public}d memcpy_s failed", __func__, __LINE__); return ret; } - + DListInsertTail(&deviceTableListTemp->list, &g_usbPnpDeviceTableListHead); ret = HDF_SUCCESS; @@ -739,28 +730,26 @@ static int32_t UsbDdkPnpLoaderDeviceListAdd(const struct UsbPnpNotifyMatchInfoTa static struct UsbPnpDeviceListTable *UsbDdkPnpLoaderAddInterface( const struct UsbPnpNotifyMatchInfoTable *info, const struct UsbPnpMatchIdTable *idTable) { - struct UsbPnpDeviceListTable *deviceListTablePos = NULL; - struct UsbPnpDeviceListTable *deviceListTableTemp = NULL; - if (DListIsEmpty(&g_usbPnpDeviceTableListHead) == true) { HDF_LOGE("%s:%d g_usbPnpDeviceTableListHead is empty. ", __func__, __LINE__); return NULL; } - DLIST_FOR_EACH_ENTRY_SAFE(deviceListTablePos, deviceListTableTemp, &g_usbPnpDeviceTableListHead, - struct UsbPnpDeviceListTable, list) { - if ((strcmp(deviceListTablePos->moduleName, idTable->moduleName) == 0) && \ - (strcmp(deviceListTablePos->serviceName, idTable->serviceName) == 0) && \ - (strcmp(deviceListTablePos->deviceMatchAttr, idTable->deviceMatchAttr) == 0) && \ - (deviceListTablePos->usbDevAddr == info->usbDevAddr) && \ - (deviceListTablePos->devNum == info->devNum) && \ + struct UsbPnpDeviceListTable *deviceListTablePos = NULL; + struct UsbPnpDeviceListTable *deviceListTableTemp = NULL; + DLIST_FOR_EACH_ENTRY_SAFE( + deviceListTablePos, deviceListTableTemp, &g_usbPnpDeviceTableListHead, struct UsbPnpDeviceListTable, list) { + if ((strcmp(deviceListTablePos->moduleName, idTable->moduleName) == 0) && + (strcmp(deviceListTablePos->serviceName, idTable->serviceName) == 0) && + (strcmp(deviceListTablePos->deviceMatchAttr, idTable->deviceMatchAttr) == 0) && + (deviceListTablePos->usbDevAddr == info->usbDevAddr) && (deviceListTablePos->devNum == info->devNum) && (deviceListTablePos->busNum == info->busNum)) { return deviceListTablePos; } } - HDF_LOGE("%s:%d interface=%d-%d-%d to be add but not exist. ", - __func__, __LINE__, info->devNum, info->busNum, info->numInfos); + HDF_LOGE("%s:%d interface=%d-%d-%d to be add but not exist. ", __func__, __LINE__, info->devNum, info->busNum, + info->numInfos); return NULL; } @@ -768,30 +757,26 @@ static struct UsbPnpDeviceListTable *UsbDdkPnpLoaderAddInterface( static int32_t UsbDdkPnpLoaderrAddPnpDevice(struct HdfDeviceObject *usbPnpManagerDevice, const struct UsbPnpNotifyMatchInfoTable *infoTable, const struct UsbPnpMatchIdTable *idTable, uint32_t cmdId) { - int32_t ret; - struct HdfSBuf *pnpData = NULL; - struct UsbPnpNotifyServiceInfo serviceInfo; - struct UsbPnpDeviceListTable *deviceListTable = NULL; - - deviceListTable = UsbDdkPnpLoaderAddInterface(infoTable, idTable); + struct UsbPnpDeviceListTable *deviceListTable = UsbDdkPnpLoaderAddInterface(infoTable, idTable); if ((deviceListTable != NULL) && (deviceListTable->status != USB_PNP_REMOVE_STATUS)) { return HDF_SUCCESS; } - serviceInfo.length = sizeof(struct UsbPnpNotifyServiceInfo) - - (USB_PNP_INFO_MAX_INTERFACES - idTable->interfaceLength); + struct UsbPnpNotifyServiceInfo serviceInfo; + serviceInfo.length = + sizeof(struct UsbPnpNotifyServiceInfo) - (USB_PNP_INFO_MAX_INTERFACES - idTable->interfaceLength); serviceInfo.devNum = infoTable->devNum; serviceInfo.busNum = infoTable->busNum; serviceInfo.interfaceLength = idTable->interfaceLength; - ret = memcpy_s(serviceInfo.interfaceNumber, USB_PNP_INFO_MAX_INTERFACES, \ - idTable->interfaceNumber, USB_PNP_INFO_MAX_INTERFACES); + int32_t ret = memcpy_s(serviceInfo.interfaceNumber, USB_PNP_INFO_MAX_INTERFACES, idTable->interfaceNumber, + USB_PNP_INFO_MAX_INTERFACES); if (ret != HDF_SUCCESS) { HDF_LOGE("%{public}s:%{public}d memcpy_s failed", __func__, __LINE__); return ret; } - - pnpData = UsbDdkPnpLoaderBufCreate(idTable->moduleName, idTable->serviceName, - idTable->deviceMatchAttr, serviceInfo); + + struct HdfSBuf *pnpData = + UsbDdkPnpLoaderBufCreate(idTable->moduleName, idTable->serviceName, idTable->deviceMatchAttr, serviceInfo); if (pnpData == NULL) { ret = HDF_FAILURE; HDF_LOGE("%s: UsbDdkPnpLoaderBufCreate failed", __func__); @@ -849,26 +834,26 @@ static void UsbDdkPnpLoaderAddDevice(uint32_t cmdId, uint8_t index, struct HdfDe } } -static int32_t UsbDdkPnpLoaderRemoveHandle(struct HdfDeviceObject *usbPnpManager, - struct UsbPnpDeviceListTable *deviceListTablePos) +static int32_t UsbDdkPnpLoaderRemoveHandle( + struct HdfDeviceObject *usbPnpManager, struct UsbPnpDeviceListTable *deviceListTablePos) { struct UsbPnpNotifyServiceInfo serviceInfo; struct HdfSBuf *pnpData = NULL; int32_t ret = HDF_SUCCESS; - serviceInfo.length = (uint32_t)(sizeof(struct UsbPnpNotifyServiceInfo) - (USB_PNP_INFO_MAX_INTERFACES \ - - deviceListTablePos->interfaceLength)); + serviceInfo.length = (uint32_t)(sizeof(struct UsbPnpNotifyServiceInfo) - + (USB_PNP_INFO_MAX_INTERFACES - deviceListTablePos->interfaceLength)); serviceInfo.devNum = deviceListTablePos->devNum; serviceInfo.busNum = deviceListTablePos->busNum; serviceInfo.interfaceLength = deviceListTablePos->interfaceLength; - ret = memcpy_s(serviceInfo.interfaceNumber, USB_PNP_INFO_MAX_INTERFACES, \ - deviceListTablePos->interfaceNumber, USB_PNP_INFO_MAX_INTERFACES); + ret = memcpy_s(serviceInfo.interfaceNumber, USB_PNP_INFO_MAX_INTERFACES, deviceListTablePos->interfaceNumber, + USB_PNP_INFO_MAX_INTERFACES); if (ret != HDF_SUCCESS) { HDF_LOGE("%{public}s:%{public}d memcpy_s failed", __func__, __LINE__); return ret; } - pnpData = UsbDdkPnpLoaderBufCreate(deviceListTablePos->moduleName, deviceListTablePos->serviceName, \ + pnpData = UsbDdkPnpLoaderBufCreate(deviceListTablePos->moduleName, deviceListTablePos->serviceName, deviceListTablePos->deviceMatchAttr, serviceInfo); if (pnpData == NULL) { HDF_LOGE("%s: UsbDdkPnpLoaderBufCreate faile", __func__); @@ -878,8 +863,7 @@ static int32_t UsbDdkPnpLoaderRemoveHandle(struct HdfDeviceObject *usbPnpManager if (deviceListTablePos->status != USB_PNP_REMOVE_STATUS) { ret = UsbDdkPnpLoaderDispatchPnpDevice(usbPnpManager, pnpData, false); if (ret != HDF_SUCCESS) { - HDF_LOGE("%s:%d UsbDdkPnpLoaderDispatchPnpDevice faile ret=%d", - __func__, __LINE__, ret); + HDF_LOGE("%s:%d UsbDdkPnpLoaderDispatchPnpDevice faile ret=%d", __func__, __LINE__, ret); goto ERROR; } deviceListTablePos->status = USB_PNP_REMOVE_STATUS; @@ -890,8 +874,8 @@ ERROR: return ret; } -static int32_t UsbDdkPnpLoaderRemoveDevice(struct HdfDeviceObject *usbPnpManager, - struct UsbPnpRemoveInfo removeInfo, uint32_t cmdId) +static int32_t UsbDdkPnpLoaderRemoveDevice( + struct HdfDeviceObject *usbPnpManager, struct UsbPnpRemoveInfo removeInfo, uint32_t cmdId) { int32_t ret = HDF_SUCCESS; struct UsbPnpDeviceListTable *deviceListTablePos = NULL; @@ -904,32 +888,34 @@ static int32_t UsbDdkPnpLoaderRemoveDevice(struct HdfDeviceObject *usbPnpManager return HDF_SUCCESS; } - DLIST_FOR_EACH_ENTRY_SAFE(deviceListTablePos, deviceListTableTemp, &g_usbPnpDeviceTableListHead, - struct UsbPnpDeviceListTable, list) { + DLIST_FOR_EACH_ENTRY_SAFE( + deviceListTablePos, deviceListTableTemp, &g_usbPnpDeviceTableListHead, struct UsbPnpDeviceListTable, list) { if (deviceListTablePos->usbDevAddr == removeInfo.usbDevAddr) { - if (removeInfo.removeType == USB_PNP_NOTIFY_REMOVE_INTERFACE_NUM) { - for (i = 0; i < deviceListTablePos->interfaceLength; i++) { - if (deviceListTablePos->interfaceNumber[i] == removeInfo.interfaceNum) { - break; - } - } + continue; + } - if (i >= deviceListTablePos->interfaceLength) { - continue; + if (removeInfo.removeType == USB_PNP_NOTIFY_REMOVE_INTERFACE_NUM) { + for (i = 0; i < deviceListTablePos->interfaceLength; i++) { + if (deviceListTablePos->interfaceNumber[i] == removeInfo.interfaceNum) { + break; } } - findFlag = true; - ret = UsbDdkPnpLoaderRemoveHandle(usbPnpManager, deviceListTablePos); - if (ret != HDF_SUCCESS) { - break; + if (i >= deviceListTablePos->interfaceLength) { + continue; } + } + findFlag = true; - if (cmdId != USB_PNP_NOTIFY_REMOVE_INTERFACE) { - DListRemove(&deviceListTablePos->list); - OsalMemFree(deviceListTablePos); - deviceListTablePos = NULL; - } + ret = UsbDdkPnpLoaderRemoveHandle(usbPnpManager, deviceListTablePos); + if (ret != HDF_SUCCESS) { + break; + } + + if (cmdId != USB_PNP_NOTIFY_REMOVE_INTERFACE) { + DListRemove(&deviceListTablePos->list); + OsalMemFree(deviceListTablePos); + deviceListTablePos = NULL; } } @@ -941,8 +927,8 @@ static int32_t UsbDdkPnpLoaderRemoveDevice(struct HdfDeviceObject *usbPnpManager return ret; } -static int32_t UsbDdkPnpLoaderDevice(struct HdfDeviceObject *usbPnpManagerDevice, - const struct UsbPnpNotifyMatchInfoTable *infoTable, uint32_t id) +static int32_t UsbDdkPnpLoaderDevice( + struct HdfDeviceObject *usbPnpManagerDevice, const struct UsbPnpNotifyMatchInfoTable *infoTable, uint32_t id) { int8_t i; int32_t tableCount; @@ -958,7 +944,7 @@ static int32_t UsbDdkPnpLoaderDevice(struct HdfDeviceObject *usbPnpManagerDevice } for (tableCount = 0, idTable = g_usbPnpMatchIdTable[0]; idTable != NULL; - idTable = g_usbPnpMatchIdTable[++tableCount]) { + idTable = g_usbPnpMatchIdTable[++tableCount]) { idTable->interfaceClassMask = 0; if (!(idTable->matchFlag & USB_PNP_NOTIFY_MATCH_INT_CLASS)) { idTable->interfaceClassLength = 0; @@ -981,55 +967,6 @@ static int32_t UsbDdkPnpLoaderDevice(struct HdfDeviceObject *usbPnpManagerDevice return HDF_SUCCESS; } -#ifndef USB_EVENT_NOTIFY_LINUX_NATIVE_MODE -static int32_t UsbDdkPnpLoaderEventSend(const struct HdfIoService *serv, const char *eventData) -{ - int32_t ret; - int32_t replyData = 0; - struct HdfSBuf *data = NULL; - - data = HdfSbufObtainDefaultSize(); - if (data == NULL) { - ret = HDF_DEV_ERR_NO_MEMORY; - HDF_LOGE("%s: fail to obtain sbuf data", __func__); - return ret; - } - - struct HdfSBuf *reply = HdfSbufObtainDefaultSize(); - if (reply == NULL) { - ret = HDF_DEV_ERR_NO_MEMORY; - HDF_LOGE("%s: fail to obtain sbuf reply", __func__); - goto OUT; - } - - if (!HdfSbufWriteString(data, eventData)) { - ret = HDF_FAILURE; - HDF_LOGE("%s: fail to write sbuf", __func__); - goto OUT; - } - - ret = serv->dispatcher->Dispatch((struct HdfObject *)&serv->object, USB_PNP_NOTIFY_REPORT_INTERFACE, data, reply); - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: fail to send serivice call, ret=%d", __func__, ret); - goto OUT; - } - - if (!HdfSbufReadInt32(reply, &replyData)) { - ret = HDF_ERR_INVALID_OBJECT; - HDF_LOGE("%s: fail to get service call reply", __func__); - goto OUT; - } - - HDF_LOGI("%s:%d get reply is 0x%x", __func__, __LINE__, replyData); - -OUT: - HdfSbufRecycle(data); - HdfSbufRecycle(reply); - - return ret; -} -#endif - int32_t UsbDdkPnpLoaderEventReceived(void *usbPnpManagerPtr, uint32_t id, struct HdfSBuf *data) { int32_t ret; @@ -1085,22 +1022,9 @@ int32_t UsbDdkPnpLoaderEventReceived(void *usbPnpManagerPtr, uint32_t id, struct int32_t UsbDdkPnpLoaderEventHandle(void) { -#ifndef USB_EVENT_NOTIFY_LINUX_NATIVE_MODE - int32_t status; - int32_t tableCount = 0; - const struct UsbPnpMatchIdTable *idTable = NULL; - struct HdfIoService *usbPnpServ = HdfIoServiceBind(USB_PNP_NOTIFY_SERVICE_NAME); - - if (usbPnpServ == NULL) { - HDF_LOGE("%s: HdfIoServiceBind faile.", __func__); - return HDF_ERR_INVALID_OBJECT; - } -#endif - static bool firstInitFlag = true; if (firstInitFlag == true) { firstInitFlag = false; - DListHeadInit(&g_usbPnpDeviceTableListHead); } @@ -1110,28 +1034,5 @@ int32_t UsbDdkPnpLoaderEventHandle(void) return HDF_ERR_INVALID_PARAM; } -#ifndef USB_EVENT_NOTIFY_LINUX_NATIVE_MODE - status = UsbDdkPnpLoaderEventSend(usbPnpServ, "USB PNP Handle Info"); - if (status != HDF_SUCCESS) { - HDF_LOGE("UsbDdkPnpLoaderEventSend faile status=%d", status); - goto ERROR; - } -#endif return HDF_SUCCESS; -#ifndef USB_EVENT_NOTIFY_LINUX_NATIVE_MODE -ERROR: - idTable = g_usbPnpMatchIdTable[0]; - while (idTable != NULL) { - tableCount++; - idTable = g_usbPnpMatchIdTable[tableCount]; - } - while ((--tableCount) >= 0) { - OsalMemFree(g_usbPnpMatchIdTable[tableCount]); - g_usbPnpMatchIdTable[tableCount] = NULL; - } - OsalMemFree(g_usbPnpMatchIdTable); - g_usbPnpMatchIdTable = NULL; - - return status; -#endif } diff --git a/framework/sample/platform/uart/src/uart_dev_sample.c b/framework/sample/platform/uart/src/uart_dev_sample.c index 0ed29e249624266516f32851a0c60a293ffba254..7e7da2dd50f87f3f35e24206cf0c405d3255af24 100644 --- a/framework/sample/platform/uart/src/uart_dev_sample.c +++ b/framework/sample/platform/uart/src/uart_dev_sample.c @@ -53,7 +53,6 @@ static int32_t UartSampleRelease(struct file *filep) static ssize_t UartSampleRead(struct file *filep, char *buf, size_t count) { - int32_t ret; uint8_t *tmpBuf = NULL; struct UartHost *host = NULL; @@ -69,7 +68,7 @@ static ssize_t UartSampleRead(struct file *filep, char *buf, size_t count) HDF_LOGE("%s: OsalMemCalloc error", __func__); return HDF_ERR_MALLOC_FAIL; } - ret = UartHostRead(host, tmpBuf, count); + int32_t ret = UartHostRead(host, tmpBuf, count); if (ret == HDF_SUCCESS) { ret = LOS_ArchCopyToUser(buf, tmpBuf, count); } @@ -82,7 +81,6 @@ static ssize_t UartSampleRead(struct file *filep, char *buf, size_t count) static ssize_t UartSampleWrite(struct file *filep, const char *buf, size_t count) { - int32_t ret; uint8_t *tmpBuf = NULL; struct UartHost *host = NULL; @@ -98,7 +96,7 @@ static ssize_t UartSampleWrite(struct file *filep, const char *buf, size_t count HDF_LOGE("%s: OsalMemCalloc error", __func__); return HDF_ERR_MALLOC_FAIL; } - ret = LOS_ArchCopyFromUser(tmpBuf, buf, count); + int32_t ret = LOS_ArchCopyFromUser(tmpBuf, buf, count); if (ret != LOS_OK) { OsalMemFree(tmpBuf); return ret; diff --git a/framework/sample/platform/uart/src/uart_pl011_sample.c b/framework/sample/platform/uart/src/uart_pl011_sample.c index b58665cebaf6801fb5af08e41a54888c3bc9e413..8c29eb99d96ce10af5d92ffdfceaa68ffe21418e 100644 --- a/framework/sample/platform/uart/src/uart_pl011_sample.c +++ b/framework/sample/platform/uart/src/uart_pl011_sample.c @@ -25,7 +25,6 @@ static void UartPl011UpdateLcr(struct UartRegisterMap *regMap) bool uartEnabled = UartPl011IsEnabled(regMap); /* UART must be disabled before UARTLCR_H are reprogrammed */ UartPl011Disable(regMap); - regMap->lcr = regMap->lcr; /* restore uart enable state */ if (uartEnabled) { UartPl011Enable(regMap); diff --git a/framework/support/platform/include/hdmi/hdmi_cec.h b/framework/support/platform/include/hdmi/hdmi_cec.h index 7f33cc2a18a949d124b2a7abf6ee904817b340e2..b65d8852b061ad1f3d76ffa337d709b3e80c1f7a 100644 --- a/framework/support/platform/include/hdmi/hdmi_cec.h +++ b/framework/support/platform/include/hdmi/hdmi_cec.h @@ -1733,6 +1733,91 @@ void HdmiCecEncodingTimerStatusMsg(struct HdmiCecMsg *msg, const struct HdmiCecT void HdmiCecEncodingTunerDeviceStatusMsg(struct HdmiCecMsg *msg, const struct HdmiCecTunerDeviceInfo *info); void HdmiCecEncodingUserControlPrtessedMsg(struct HdmiCecMsg *msg, const struct HdmiCecUiCmd *cmd); +void HdmiCdcEncodingHecDiscoverMsg(struct HdmiCecMsg *msg, uint16_t initiatorPhyAddr, bool response); +void HdmiCdcEncodingHecInquireStateMsg(struct HdmiCecMsg *msg, uint16_t initiatorPhyAddr, + uint16_t phyAddr1, uint16_t phyAddr2, bool response); +void HdmiCdcEncodingHecNotifyAliveMsg(struct HdmiCecMsg *msg, uint16_t initiatorPhyAddr); +void HdmiCdcEncodingHecReportStateMsg(struct HdmiCecMsg *msg, uint16_t initiatorPhyAddr, + uint16_t phyAddr, const struct HdmiCdcHecState *state); +void HdmiCdcEncodingHecSetStateMsg(struct HdmiCecMsg *msg, uint16_t initiatorPhyAddr, + struct HemiCdcHecStateInfo *info, bool response); +void HdmiCdcEncodingHpdReportStateMsg(struct HdmiCecMsg *msg, uint16_t initiatorPhyAddr, + uint8_t hpdState, uint8_t errCode); +void HdmiCdcEncodingHpdSetStateMsg(struct HdmiCecMsg *msg, uint16_t initiatorPhyAddr, + uint8_t portNum, uint8_t hpdState, bool response); +void HdmiCecEncodingAbortMsg(struct HdmiCecMsg *msg); +void HdmiCecEncodingActiveSourceMsg(struct HdmiCecMsg *msg, uint16_t phyAddr); +void HdmiCecEncodingClearAnalogueTimerMsg(struct HdmiCecMsg *msg, struct HdmiCecAnalogueTimerInfo *info, + bool response); +void HdmiCecEncodingClearDigitalTimerMsg(struct HdmiCecMsg *msg, struct HdmiCecDigitalTimerInfo *info, bool response); +void HdmiCecEncodingClearExternalTimerMsg(struct HdmiCecMsg *msg, struct HdmiCecExternalTimerInfo *info, + bool response); +void HdmiCecEncodingDeckControlMsg(struct HdmiCecMsg *msg, uint8_t mode); +void HdmiCecEncodingDeckStatusMsg(struct HdmiCecMsg *msg, uint8_t info); +void HdmiCecEncodingGetCecVersionMsg(struct HdmiCecMsg *msg, bool response); +void HdmiCecEncodingGetMenuLanguageMsg(struct HdmiCecMsg *msg, bool response); +void HdmiCecEncodingGetPhyAddressMsg(struct HdmiCecMsg *msg, bool response); +void HdmiCecEncodingGiveAudioStatusMsg(struct HdmiCecMsg *msg, bool response); +void HdmiCecEncodingGiveDeckStatusMsg(struct HdmiCecMsg *msg, uint8_t statusReq, bool response); +void HdmiCecEncodingGiveDevicePowerStatusMsg(struct HdmiCecMsg *msg, bool response); +void HdmiCecEncodingGiveDeviceVendorIdMsg(struct HdmiCecMsg *msg, bool response); +void HdmiCecEncodingGiveFeaturesMsg(struct HdmiCecMsg *msg, bool response); +void HdmiCecEncodingGiveOsdNameMsg(struct HdmiCecMsg *msg, bool response); +void HdmiCecEncodingGiveSystemAudioModeMsg(struct HdmiCecMsg *msg, bool response); +void HdmiCecEncodingGiveTunerDeviceStatusMsg(struct HdmiCecMsg *msg, uint8_t statusReq, bool response); +void HdmiCecEncodingImageViewOnMsg(struct HdmiCecMsg *msg); +void HdmiCecEncodingInactiveSourceMsg(struct HdmiCecMsg *msg, uint16_t phyAddr); +void HdmiCecEncodingInitiateArcMsg(struct HdmiCecMsg *msg, bool response); +void HdmiCecEncodingMenuRequestMsg(struct HdmiCecMsg *msg, uint8_t menuReq, bool response); +void HdmiCecEncodingMenuStatusMsg(struct HdmiCecMsg *msg, uint8_t menuStatus); +void HdmiCecEncodingPlayMsg(struct HdmiCecMsg *msg, uint8_t playMode); +void HdmiCecEncodingRecordOffMsg(struct HdmiCecMsg *msg, bool response); +void HdmiCecEncodingRecordOnMsg(struct HdmiCecMsg *msg, struct HdmiCecRecordSource *src, bool response); +void HdmiCecEncodingRecordStatusMsg(struct HdmiCecMsg *msg, uint8_t recordStatusInfo); +void HdmiCecEncodingRecordTvScreenMsg(struct HdmiCecMsg *msg, bool response); +void HdmiCecEncodingReportArcInitiatedMsg(struct HdmiCecMsg *msg); +void HdmiCecEncodingReportArcTerminationMsg(struct HdmiCecMsg *msg); +void HdmiCecEncodingReportAudioStatusMsg(struct HdmiCecMsg *msg, uint8_t audioMuteStatus, uint8_t audioVolumeStatus); +void HdmiCecEncodingReportCurrentLatencyMsg(struct HdmiCecMsg *msg, uint16_t phyAddr, struct HdmiCecLatencyInfo *info); +void HdmiCecEncodingReportDevicePowerStatusMsg(struct HdmiCecMsg *msg, uint8_t powerStatus); +void HdmiCecEncodingReportShortAudioDescriptorMsg(struct HdmiCecMsg *msg, uint32_t *descriptor, uint32_t len); +void HdmiCecEncodingRequestActiveSourceMsg(struct HdmiCecMsg *msg, bool response); +void HdmiCecEncodingRequestArcInitiationMsg(struct HdmiCecMsg *msg, bool response); +void HdmiCecEncodingRequestArcTerminationMsg(struct HdmiCecMsg *msg, bool response); +void HdmiCecEncodingRequestCurrentLatencyMsg(struct HdmiCecMsg *msg, uint16_t phyAddr, bool response); +void HdmiCecEncodingRequestShortAudioDescriptorMsg(struct HdmiCecMsg *msg, uint8_t *id, uint8_t *code, + uint32_t len, bool response); +void HdmiCecEncodingRoutingChangeMsg(struct HdmiCecMsg *msg, uint16_t orgAddr, uint16_t newAddr, bool response); +void HdmiCecEncodingRoutingInfomationMsg(struct HdmiCecMsg *msg, uint16_t phyAddr); +void HdmiCecEncodingSelectAnalogueServiceMsg(struct HdmiCecMsg *msg, uint8_t anaBcastType, uint16_t anaFreq, + uint8_t bcstSystem); +void HdmiCecEncodingSelectDigitalServiceMsg(struct HdmiCecMsg *msg, struct HdmiCecDigitalServiceId *digital); +void HdmiCecEncodingSetAnalogueTimerMsg(struct HdmiCecMsg *msg, struct HdmiCecAnalogueTimerInfo *info, bool response); +void HdmiCecEncodingSetAudioRateMsg(struct HdmiCecMsg *msg, uint8_t rate); +void HdmiCecEncodingSetDigitalTimerMsg(struct HdmiCecMsg *msg, struct HdmiCecDigitalTimerInfo *info, bool response); +void HdmiCecEncodingSetExternalTimerMsg(struct HdmiCecMsg *msg, struct HdmiCecExternalTimerInfo *info, bool response); +void HdmiCecEncodingSetMenuLanguageMsg(struct HdmiCecMsg *msg, uint8_t *language, uint32_t len); +void HdmiCecEncodingSetOsdStringMsg(struct HdmiCecMsg *msg, uint8_t dispControl, uint8_t *str, uint32_t len); +void HdmiCecEncodingSetStreamPathMsg(struct HdmiCecMsg *msg, uint16_t phyAddr); +void HdmiCecEncodingSetSystemAudioModeMsg(struct HdmiCecMsg *msg, uint8_t status); +void HdmiCecEncodingSetTimerProgramTitleMsg(struct HdmiCecMsg *msg, uint8_t *title, uint32_t len); +void HdmiCecEncodingStandbyMsg(struct HdmiCecMsg *msg); +void HdmiCecEncodingSystemAudioModeRequestMsg(struct HdmiCecMsg *msg, uint16_t phyAddr, bool response); +void HdmiCecEncodingSystemAudioModeStatusMsg(struct HdmiCecMsg *msg, uint8_t status); +void HdmiCecEncodingTerminateArcMsg(struct HdmiCecMsg *msg, bool response); +void HdmiCecEncodingTextViewOnMsg(struct HdmiCecMsg *msg); +void HdmiCecEncodingTimerClearedStatusMsg(struct HdmiCecMsg *msg, uint8_t status); +void HdmiCecEncodingTimerStatusMsg(struct HdmiCecMsg *msg, const struct HdmiCecTimerStatusData *status); +void HdmiCecEncodingTunerDeviceStatusMsg(struct HdmiCecMsg *msg, const struct HdmiCecTunerDeviceInfo *info); +void HdmiCecEncodingTunerStepDecrementMsg(struct HdmiCecMsg *msg); +void HdmiCecEncodingTunerStepIncrementMsg(struct HdmiCecMsg *msg); +void HdmiCecEncodingUserControlPrtessedMsg(struct HdmiCecMsg *msg, const struct HdmiCecUiCmd *cmd); +void HdmiCecEncodingUserControlReleasedMsg(struct HdmiCecMsg *msg); +void HdmiCecEncodingVendorCommandMsg(struct HdmiCecMsg *msg, uint8_t *data, uint32_t len); +void HdmiCecEncodingVendorCommandWithIdMsg(struct HdmiCecMsg *msg, uint32_t vendorId, uint8_t *data, uint32_t len); +void HdmiCecEncodingVendorRemoteButtonDownMsg(struct HdmiCecMsg *msg, uint8_t *rcCode, uint32_t len); +void HdmiCecEncodingVendorRemoteButtonUpMsg(struct HdmiCecMsg *msg); + #ifdef __cplusplus #if __cplusplus } diff --git a/framework/support/platform/include/hdmi/hdmi_frl.h b/framework/support/platform/include/hdmi/hdmi_frl.h index 4c81381f1622d0cdfdc433b844b3eb5f6096bfe3..cc1292fbbd77f3511e9ec67bb93b97c80609acf6 100644 --- a/framework/support/platform/include/hdmi/hdmi_frl.h +++ b/framework/support/platform/include/hdmi/hdmi_frl.h @@ -202,6 +202,8 @@ void HdmiFrlEnable(struct HdmiFrl *frl, bool enable); bool HdmiFrlSupport(struct HdmiFrl *frl); int32_t HdmiFrlModeSelect(struct HdmiFrl *frl); bool HdmiFrlModeChanged(struct HdmiFrl *frl); +void HdmiFrlTrainingStateMachineHandle(struct HdmiFrl *frl); +void HdmiFrlTrainingStateMachineTimeoutHandle(struct HdmiFrl *frl); #ifdef __cplusplus #if __cplusplus diff --git a/framework/support/platform/include/hdmi/hdmi_scdc.h b/framework/support/platform/include/hdmi/hdmi_scdc.h index c1c02f8ccf8bbc18aaa69fd457130def08545c84..6a7c70700337502f9d9a737673fb0b0d76595c8f 100644 --- a/framework/support/platform/include/hdmi/hdmi_scdc.h +++ b/framework/support/platform/include/hdmi/hdmi_scdc.h @@ -315,6 +315,7 @@ void HdmiScdcReset(struct HdmiScdc *scdc); int32_t HdmiScdcOptMsgHandle(const struct HdmiScdc *scdc, enum HdmiScdcOptMsg msg, uint8_t *buffer, uint32_t len); int32_t HdmiScdcFillScrambleCap(struct HdmiScdc *scdc, struct HdmiScdcScrambleCap *scramble, enum HdmiTmdsModeType *tmdsMode); +int32_t HdmiScdcRrDisable(struct HdmiScdc *scdc); #ifdef __cplusplus #if __cplusplus diff --git a/framework/support/platform/include/mipi/mipi_dsi_core.h b/framework/support/platform/include/mipi/mipi_dsi_core.h index 03244af287ac3e2989287b61bb9845c57f68ebb0..fa9ef5a5e0f3a856bc6e8f5711da4a82b9463125 100644 --- a/framework/support/platform/include/mipi/mipi_dsi_core.h +++ b/framework/support/platform/include/mipi/mipi_dsi_core.h @@ -173,6 +173,10 @@ int32_t MipiDsiCntlrAttach(struct MipiDsiCntlr *cntlr, uint8_t *name); */ int32_t MipiDsiCntlrSetDrvData(struct MipiDsiCntlr *cntlr, void *panelData); +void MipiDsiCntlrEnterUlps(struct MipiDsiCntlr *cntlr); +void MipiDsiCntlrExitUlps(struct MipiDsiCntlr *cntlr); +int32_t MipiDsiCntlrPowerControl(struct MipiDsiCntlr *cntlr, uint8_t enable); + #ifdef __cplusplus #if __cplusplus } diff --git a/framework/support/platform/include/regulator/regulator_core.h b/framework/support/platform/include/regulator/regulator_core.h index 0c237d568b489c550d0ba01be506c8cd2aaf38f2..a66f28917a057a74b260dc491f0b4cf3d940931b 100644 --- a/framework/support/platform/include/regulator/regulator_core.h +++ b/framework/support/platform/include/regulator/regulator_core.h @@ -194,6 +194,8 @@ int32_t RegulatorNodeGetStatus(struct RegulatorNode *node, uint32_t *status); */ int32_t RegulatorNodeRegisterStatusChangeCb(struct RegulatorNode *node, RegulatorStatusChangecb cb); int32_t RegulatorNodeStatusCb(struct RegulatorNode *node); +void RegulatorNodeListPrint(void); +int32_t RegulatorTreeInfoInit(struct RegulatorNode *node); #ifdef __cplusplus #if __cplusplus diff --git a/framework/support/platform/src/fwk/platform_device.c b/framework/support/platform/src/fwk/platform_device.c index 721e671e310f19f78b1fafc3e6656ad9a45d1edb..6f29cc046d6ef02a7cfac0310403905bb35a34c6 100644 --- a/framework/support/platform/src/fwk/platform_device.c +++ b/framework/support/platform/src/fwk/platform_device.c @@ -74,7 +74,7 @@ int32_t PlatformDeviceSetName(struct PlatformDevice *device, const char *fmt, .. } realLen = strlen(tmpName); - if (realLen <= 0 || realLen > PLATFORM_DEV_NAME_LEN) { + if (realLen > PLATFORM_DEV_NAME_LEN) { PLAT_LOGE("PlatformDeviceSetName: invalid name len:%zu", realLen); return HDF_ERR_INVALID_PARAM; } diff --git a/framework/support/platform/src/fwk/platform_queue.c b/framework/support/platform/src/fwk/platform_queue.c index 4b7654bb3a61b886f5a5619b78a0391a4977e1ed..efa55bd87d7d8f37d1877cb0cd73a626dda23f9a 100644 --- a/framework/support/platform/src/fwk/platform_queue.c +++ b/framework/support/platform/src/fwk/platform_queue.c @@ -106,7 +106,6 @@ int32_t PlatformQueueStart(struct PlatformQueue *queue) ret = OsalThreadCreate(&queue->thread, (OsalThreadEntry)PlatformQueueWorker, (void *)queue); (void)PlatformQueueWorker; - ret = HDF_SUCCESS; if (ret != HDF_SUCCESS) { PLAT_LOGE("PlatformQueueStart: create thread fail!"); return ret; @@ -117,7 +116,6 @@ int32_t PlatformQueueStart(struct PlatformQueue *queue) cfg.stackSize = PLAT_QUEUE_THREAD_STAK; ret = OsalThreadStart(&queue->thread, &cfg); (void)cfg; - ret = HDF_SUCCESS; if (ret != HDF_SUCCESS) { OsalThreadDestroy(&queue->thread); PLAT_LOGE("PlatformQueueStart: start thread fail:%d", ret); diff --git a/framework/support/platform/src/hdmi/hdmi_core.c b/framework/support/platform/src/hdmi/hdmi_core.c index d16625f2e8a9240533630ea137d3a79fa9298f1a..4313b81a8c758dc871af35eee467b8acff11d7cf 100644 --- a/framework/support/platform/src/hdmi/hdmi_core.c +++ b/framework/support/platform/src/hdmi/hdmi_core.c @@ -613,7 +613,6 @@ static void HdmiVideoAttrInit(struct HdmiCntlr *cntlr) struct HdmiVideoAttr *videoAttr = &(cntlr->attr.videoAttr); bool colorimetry601; - videoAttr->colorSpace = (enum HdmiColorSpace)cntlr->cap.colorSpace; videoAttr->colorimetry = (enum HdmiColorimetry)cntlr->cap.colorimetry; videoAttr->timing = (enum HdmiVideoTiming)cntlr->cap.videoTiming; colorimetry601 = ((videoAttr->timing == HDMI_VIDEO_TIMING_720X480P60) || @@ -1080,8 +1079,8 @@ static void HdmiHdrModeCheck( static void HdmiFillVideoAttrFromHardwareStatus( struct HdmiVideoAttr *videoAttr, const struct HdmiHardwareStatus *hwStatus, struct HdmiCommonAttr *commAttr) { - bool rgb = false; - bool aspectIs256 = false; + bool rgb; + bool aspectIs256; uint8_t vic; enum HdmiVsVideoFormat format; enum Hdmi4kVic vic4k; @@ -1108,7 +1107,13 @@ static void HdmiFillVideoAttrFromHardwareStatus( /* * when the timing is 4096*2160, the aspect ratio in AVI infoFrame is 0 * (but the real aspect ratio is 256:135<0x04>, the video_code is 0) - * vsif[8] is HDMI_VIC. 0x04: 4K*2K @24Hz(SMPTE) + * vsif[0]: Packet Type = 0x81 + * vsif[1]: Version = 0x01 + * vsif[2]: BIT[7:5]: 0, Bit[4:0]: Length, defines the length of HDMI vendor specific infoFrame payload. + * vsif[3]: Checksum. + * vsif[4]--vsif[6]: 24bit IEEE Registration Identifier(0x000C03)(least significant byte first). + * vsif[7]: BIT[7]: reserved for future, BIT[6:5]: HDMI_Video_Format, BIT[4:0]: reserved. + * vsif[8]: HDMI_VIC, 0x04: 4K*2K @24Hz(SMPTE). */ aspectIs256 = (((vic == 0) && (hwStatus->infoFrameStatus.vsif[8] == 0x04)) || ((vic >= HDMI_VIC_4096X2160P25_256_135) && (vic <= HDMI_VIC_4096X2160P60_256_135))); diff --git a/framework/support/platform/src/hdmi/hdmi_frl.c b/framework/support/platform/src/hdmi/hdmi_frl.c index b0466e9b2ec0ef3533162570f3cd3505e5bf4782..1dd76100c59a29b68db03d125329a8322df44138 100644 --- a/framework/support/platform/src/hdmi/hdmi_frl.c +++ b/framework/support/platform/src/hdmi/hdmi_frl.c @@ -680,7 +680,7 @@ static void HdmiFrlTrainingResultCheckTimeout(struct HdmiFrl *frl) static void HdmiFrlTrainingResultHandleTimeout(struct HdmiFrl *frl) { uint64_t curTime; - bool frlStart = false; + bool frlStart; struct HdmiCntlr *cntlr = (struct HdmiCntlr *)frl->priv; if (cntlr == NULL || cntlr->ops == NULL) { @@ -806,11 +806,10 @@ int32_t HdmiFrlModeSelect(struct HdmiFrl *frl) } ret = HdmiFrlCheckFrlCapability(frl); - if (ret == HDF_FAILURE) { - return ret; - } else if (ret != HDF_SUCCESS) { + if (ret != HDF_SUCCESS) { HDF_LOGD("frl check capability fail, change to TMDS."); frl->info.mode = HDMI_FRL_MODE_TMDS; + return ret; } else { if (HdnmiFrlCheckFrlMode(frl) == true) { HDF_LOGD("frl check frl mode succ."); diff --git a/framework/support/platform/src/pin/pin_core.c b/framework/support/platform/src/pin/pin_core.c index b7552a5bbf16ccde599d2320c50a377861ba74e8..83c64349b5f53b604c3acbace0669d31825b5626 100644 --- a/framework/support/platform/src/pin/pin_core.c +++ b/framework/support/platform/src/pin/pin_core.c @@ -153,7 +153,7 @@ struct PinCntlr *PinCntlrGetByPin(const struct PinDesc *desc) head = PinCntlrListGet(); DLIST_FOR_EACH_ENTRY_SAFE(cntlr, tmp, head, struct PinCntlr, node) { - for (num = 0; num pinCount; num++) { + for (num = 0; num < cntlr->pinCount; num++) { if (desc == &cntlr->pins[num]) { PinCntlrListPut(); HDF_LOGI("%s: get cntlr by desc success!", __func__); diff --git a/framework/support/platform/src/rtc/rtc_if_u.c b/framework/support/platform/src/rtc/rtc_if_u.c index 9e0e237178d5a67e79aade03bdfdf815ae8ddf95..8d93d7d0ee43dbdd229e98c08aeef2f14084d828 100644 --- a/framework/support/platform/src/rtc/rtc_if_u.c +++ b/framework/support/platform/src/rtc/rtc_if_u.c @@ -12,6 +12,7 @@ #include "hdf_sbuf.h" #include "osal_mem.h" #include "platform_listener_u.h" +#include "rtc_base.h" #include "securec.h" #define HDF_LOG_TAG rtc_if_u_c @@ -74,7 +75,7 @@ int32_t RtcReadTime(DevHandle handle, struct RtcTime *time) } service = (struct HdfIoService *)handle; - if (service == NULL || service->dispatcher == NULL || service->dispatcher->Dispatch == NULL) { + if (service->dispatcher == NULL || service->dispatcher->Dispatch == NULL) { HDF_LOGE("%s: service is invalid", __func__); ret = HDF_ERR_MALLOC_FAIL; goto EXIT; @@ -120,6 +121,11 @@ int32_t RtcWriteTime(DevHandle handle, const struct RtcTime *time) return HDF_ERR_INVALID_OBJECT; } + if (RtcIsInvalid(time) == RTC_TRUE) { + HDF_LOGE("%s: time invalid", __func__); + return HDF_ERR_INVALID_PARAM; + } + data = HdfSbufObtainDefaultSize(); if (data == NULL) { HDF_LOGE("%s: fail to obtain data", __func__); @@ -133,7 +139,7 @@ int32_t RtcWriteTime(DevHandle handle, const struct RtcTime *time) } service = (struct HdfIoService *)handle; - if (service == NULL || service->dispatcher == NULL || service->dispatcher->Dispatch == NULL) { + if (service->dispatcher == NULL || service->dispatcher->Dispatch == NULL) { HDF_LOGE("%s: service is invalid", __func__); HdfSbufRecycle(data); return HDF_ERR_MALLOC_FAIL; @@ -184,7 +190,7 @@ int32_t RtcReadAlarm(DevHandle handle, enum RtcAlarmIndex alarmIndex, struct Rtc } service = (struct HdfIoService *)handle; - if (service == NULL || service->dispatcher == NULL || service->dispatcher->Dispatch == NULL) { + if (service->dispatcher == NULL || service->dispatcher->Dispatch == NULL) { HDF_LOGE("%s: service is invalid", __func__); ret = HDF_ERR_MALLOC_FAIL; goto EXIT; @@ -231,6 +237,11 @@ int32_t RtcWriteAlarm(DevHandle handle, enum RtcAlarmIndex alarmIndex, const str return HDF_ERR_INVALID_OBJECT; } + if (RtcIsInvalid(time) == RTC_TRUE) { + HDF_LOGE("%s: time invalid", __func__); + return HDF_ERR_INVALID_PARAM; + } + data = HdfSbufObtainDefaultSize(); if (data == NULL) { HDF_LOGE("%s: fail to obtain data", __func__); @@ -250,7 +261,7 @@ int32_t RtcWriteAlarm(DevHandle handle, enum RtcAlarmIndex alarmIndex, const str } service = (struct HdfIoService *)handle; - if (service == NULL || service->dispatcher == NULL || service->dispatcher->Dispatch == NULL) { + if (service->dispatcher == NULL || service->dispatcher->Dispatch == NULL) { HDF_LOGE("%s: service is invalid", __func__); HdfSbufRecycle(data); return HDF_ERR_MALLOC_FAIL; @@ -311,7 +322,7 @@ int32_t RtcRegisterAlarmCallback(DevHandle handle, enum RtcAlarmIndex alarmIndex return HDF_ERR_IO; } - if (service == NULL || service->dispatcher == NULL || service->dispatcher->Dispatch == NULL) { + if (service->dispatcher == NULL || service->dispatcher->Dispatch == NULL) { HDF_LOGE("%s: service is invalid", __func__); HdfSbufRecycle(data); return HDF_ERR_MALLOC_FAIL; @@ -366,7 +377,7 @@ int32_t RtcAlarmInterruptEnable(DevHandle handle, enum RtcAlarmIndex alarmIndex, } service = (struct HdfIoService *)handle; - if (service == NULL || service->dispatcher == NULL || service->dispatcher->Dispatch == NULL) { + if (service->dispatcher == NULL || service->dispatcher->Dispatch == NULL) { HDF_LOGE("%s: service is invalid", __func__); HdfSbufRecycle(data); return HDF_ERR_MALLOC_FAIL; @@ -401,7 +412,7 @@ int32_t RtcGetFreq(DevHandle handle, uint32_t *freq) } service = (struct HdfIoService *)handle; - if (service == NULL || service->dispatcher == NULL || service->dispatcher->Dispatch == NULL) { + if (service->dispatcher == NULL || service->dispatcher->Dispatch == NULL) { HDF_LOGE("%s: service is invalid", __func__); ret = HDF_ERR_MALLOC_FAIL; goto EXIT; @@ -447,7 +458,7 @@ int32_t RtcSetFreq(DevHandle handle, uint32_t freq) } service = (struct HdfIoService *)handle; - if (service == NULL || service->dispatcher == NULL || service->dispatcher->Dispatch == NULL) { + if (service->dispatcher == NULL || service->dispatcher->Dispatch == NULL) { HDF_LOGE("%s: service is invalid", __func__); HdfSbufRecycle(data); return HDF_ERR_MALLOC_FAIL; @@ -521,7 +532,7 @@ int32_t RtcReadReg(DevHandle handle, uint8_t usrDefIndex, uint8_t *value) } service = (struct HdfIoService *)handle; - if (service == NULL || service->dispatcher == NULL || service->dispatcher->Dispatch == NULL) { + if (service->dispatcher == NULL || service->dispatcher->Dispatch == NULL) { HDF_LOGE("%s: service is invalid", __func__); ret = HDF_ERR_MALLOC_FAIL; goto EXIT; @@ -575,7 +586,7 @@ int32_t RtcWriteReg(DevHandle handle, uint8_t usrDefIndex, uint8_t value) } service = (struct HdfIoService *)handle; - if (service == NULL || service->dispatcher == NULL || service->dispatcher->Dispatch == NULL) { + if (service->dispatcher == NULL || service->dispatcher->Dispatch == NULL) { HDF_LOGE("%s: service is invalid", __func__); HdfSbufRecycle(data); return HDF_ERR_MALLOC_FAIL; diff --git a/framework/support/platform/src/rtc/rtc_service.c b/framework/support/platform/src/rtc/rtc_service.c index 3ed55ac31a9b9017a6f3a2f426952c615a7f91a7..1945f534c966627fb8e8b18000cb9209f50294f5 100644 --- a/framework/support/platform/src/rtc/rtc_service.c +++ b/framework/support/platform/src/rtc/rtc_service.c @@ -130,6 +130,11 @@ static int32_t RtcAlarmServiceCallback(enum RtcAlarmIndex index) return HDF_ERR_IO; } ret = HdfDeviceSendEvent(host->device, PLATFORM_LISTENER_EVENT_RTC_ALARM_NOTIFY, data); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s:send event failed, ret=%d", __func__, ret); + HdfSbufRecycle(data); + return ret; + } HdfSbufRecycle(data); return HDF_SUCCESS; } diff --git a/framework/support/platform/src/uart/uart_if_u.c b/framework/support/platform/src/uart/uart_if_u.c index e6de5fff5399a0ab9d789522c1abdd913e75b526..c3ff0d4c6a2fbfc084204b67162b74c1f4d39722 100644 --- a/framework/support/platform/src/uart/uart_if_u.c +++ b/framework/support/platform/src/uart/uart_if_u.c @@ -48,7 +48,7 @@ DevHandle UartOpen(uint32_t port) } struct HdfIoService *service = (struct HdfIoService *)handle; - if (service == NULL || service->dispatcher == NULL || service->dispatcher->Dispatch == NULL) { + if (service->dispatcher == NULL || service->dispatcher->Dispatch == NULL) { HDF_LOGE("%s: service is invalid", __func__); UartPutObjByPointer(handle); return NULL; @@ -73,7 +73,7 @@ void UartClose(DevHandle handle) } struct HdfIoService *service = (struct HdfIoService *)handle; - if (service == NULL || service->dispatcher == NULL || service->dispatcher->Dispatch == NULL) { + if (service->dispatcher == NULL || service->dispatcher->Dispatch == NULL) { HDF_LOGE("%s: service is invalid", __func__); UartPutObjByPointer(handle); return; diff --git a/framework/support/platform/src/watchdog/watchdog_if_u.c b/framework/support/platform/src/watchdog/watchdog_if_u.c index 7cd05d54a4bf7304f04f9474b460007a931fba82..51e83336ca2d60242d05e927a3524136eae2d0eb 100644 --- a/framework/support/platform/src/watchdog/watchdog_if_u.c +++ b/framework/support/platform/src/watchdog/watchdog_if_u.c @@ -57,7 +57,7 @@ int32_t WatchdogOpen(int16_t wdtId, DevHandle *handle) return HDF_FAILURE; } - if (service == NULL ||service->dispatcher == NULL || service->dispatcher->Dispatch == NULL) { + if (service->dispatcher == NULL || service->dispatcher->Dispatch == NULL) { HDF_LOGE("%s: service is invalid", __func__); HdfIoServiceRecycle(service); return HDF_FAILURE; @@ -121,7 +121,7 @@ int32_t WatchdogGetStatus(DevHandle handle, int32_t *status) } service = (struct HdfIoService *)handle; - if (service == NULL || service->dispatcher == NULL || service->dispatcher->Dispatch == NULL) { + if (service->dispatcher == NULL || service->dispatcher->Dispatch == NULL) { HDF_LOGE("%s: service is invalid", __func__); return HDF_ERR_INVALID_OBJECT; } @@ -242,7 +242,7 @@ int32_t WatchdogGetTimeout(DevHandle handle, uint32_t *seconds) } service = (struct HdfIoService *)handle; - if (service == NULL || service->dispatcher == NULL || service->dispatcher->Dispatch == NULL) { + if (service->dispatcher == NULL || service->dispatcher->Dispatch == NULL) { HDF_LOGE("%s: service is invalid", __func__); return HDF_ERR_INVALID_OBJECT; } diff --git a/framework/test/unittest/model/usb/device/src/usb_device_lite_cdcacm_test.c b/framework/test/unittest/model/usb/device/src/usb_device_lite_cdcacm_test.c index 8ce987ddd5aa0ed4b27e711b68e260c74a322050..6632a014d9bd07c5d6a6c002190305b822f9d2e6 100644 --- a/framework/test/unittest/model/usb/device/src/usb_device_lite_cdcacm_test.c +++ b/framework/test/unittest/model/usb/device/src/usb_device_lite_cdcacm_test.c @@ -7,216 +7,213 @@ */ #include "usb_device_lite_cdcacm_test.h" -#include "usbfn_dev_mgr.h" -#include "usbfn_cfg_mgr.h" #include "adapter_if.h" +#include "usbfn_cfg_mgr.h" +#include "usbfn_dev_mgr.h" static struct UsbInterfaceAssocDescriptor g_acmIadDescriptor = { - .bLength = sizeof(g_acmIadDescriptor), - .bDescriptorType = USB_DDK_DT_INTERFACE_ASSOCIATION, + .bLength = sizeof(g_acmIadDescriptor), + .bDescriptorType = USB_DDK_DT_INTERFACE_ASSOCIATION, #ifdef CDC_ECM - .bFirstInterface = 0x02, + .bFirstInterface = 0x02, #else - .bFirstInterface = 0, + .bFirstInterface = 0, #endif - .bInterfaceCount = INTF_COUNT, - .bFunctionClass = USB_DDK_CLASS_COMM, + .bInterfaceCount = INTF_COUNT, + .bFunctionClass = USB_DDK_CLASS_COMM, .bFunctionSubClass = USB_DDK_CDC_SUBCLASS_ACM, .bFunctionProtocol = USB_DDK_CDC_ACM_PROTO_AT_V25TER, - .iFunction = ACM_IAD_IDX, + .iFunction = ACM_IAD_IDX, }; static struct UsbInterfaceDescriptor g_acmControlInterfaceDesc = { - .bLength = USB_DDK_DT_INTERFACE_SIZE, - .bDescriptorType = USB_DDK_DT_INTERFACE, + .bLength = USB_DDK_DT_INTERFACE_SIZE, + .bDescriptorType = USB_DDK_DT_INTERFACE, #ifdef CDC_ECM - .bInterfaceNumber = 0x02, + .bInterfaceNumber = 0x02, #else - .bInterfaceNumber = 0, + .bInterfaceNumber = 0, #endif - .bAlternateSetting = 0, - .bNumEndpoints = NOTIFY_EP_NUM, - .bInterfaceClass = USB_DDK_CLASS_COMM, + .bAlternateSetting = 0, + .bNumEndpoints = NOTIFY_EP_NUM, + .bInterfaceClass = USB_DDK_CLASS_COMM, .bInterfaceSubClass = USB_DDK_CDC_SUBCLASS_ACM, .bInterfaceProtocol = USB_DDK_CDC_ACM_PROTO_AT_V25TER, - .iInterface = ACM_CTRL_IDX, + .iInterface = ACM_CTRL_IDX, }; static struct UsbInterfaceDescriptor g_acmDataInterfaceDesc = { - .bLength = USB_DDK_DT_INTERFACE_SIZE, - .bDescriptorType = USB_DDK_DT_INTERFACE, + .bLength = USB_DDK_DT_INTERFACE_SIZE, + .bDescriptorType = USB_DDK_DT_INTERFACE, #ifdef CDC_ECM - .bInterfaceNumber = 0x03, + .bInterfaceNumber = 0x03, #else - .bInterfaceNumber = 1, + .bInterfaceNumber = 1, #endif - .bAlternateSetting = 0, - .bNumEndpoints = DATA_EP_NUM, - .bInterfaceClass = USB_DDK_CLASS_CDC_DATA, + .bAlternateSetting = 0, + .bNumEndpoints = DATA_EP_NUM, + .bInterfaceClass = USB_DDK_CLASS_CDC_DATA, .bInterfaceSubClass = 0, .bInterfaceProtocol = 0x2, - .iInterface = ACM_DATA_IDX, + .iInterface = ACM_DATA_IDX, }; static struct UsbCdcHeaderDesc g_acmHeaderDesc = { - .bLength = sizeof(g_acmHeaderDesc), - .bDescriptorType = USB_DDK_DT_CS_INTERFACE, + .bLength = sizeof(g_acmHeaderDesc), + .bDescriptorType = USB_DDK_DT_CS_INTERFACE, .bDescriptorSubType = USB_DDK_CDC_HEADER_TYPE, - .bcdCDC = CPU_TO_LE16(0x0110), + .bcdCDC = CPU_TO_LE16(0x0110), }; static struct UsbCdcCallMgmtDescriptor g_acmCallMgmtDescriptor = { - .bLength = sizeof(g_acmCallMgmtDescriptor), - .bDescriptorType = USB_DDK_DT_CS_INTERFACE, + .bLength = sizeof(g_acmCallMgmtDescriptor), + .bDescriptorType = USB_DDK_DT_CS_INTERFACE, .bDescriptorSubType = USB_DDK_CDC_CALL_MANAGEMENT_TYPE, - .bmCapabilities = 0, - .bDataInterface = 1, + .bmCapabilities = 0, + .bDataInterface = 1, }; static struct UsbCdcAcmDescriptor g_acmDescriptor = { - .bLength = sizeof(g_acmDescriptor), - .bDescriptorType = USB_DDK_DT_CS_INTERFACE, + .bLength = sizeof(g_acmDescriptor), + .bDescriptorType = USB_DDK_DT_CS_INTERFACE, .bDescriptorSubType = USB_DDK_CDC_ACM_TYPE, - .bmCapabilities = USB_DDK_CDC_CAP_LINE, + .bmCapabilities = USB_DDK_CDC_CAP_LINE, }; static struct UsbCdcUnionDesc g_acmUnionDesc = { - .bLength = sizeof(g_acmUnionDesc), - .bDescriptorType = USB_DDK_DT_CS_INTERFACE, + .bLength = sizeof(g_acmUnionDesc), + .bDescriptorType = USB_DDK_DT_CS_INTERFACE, .bDescriptorSubType = USB_DDK_CDC_UNION_TYPE, #ifdef CDC_ECM - .bMasterInterface0 = 0x02, - .bSlaveInterface0 = 0x03, + .bMasterInterface0 = 0x02, + .bSlaveInterface0 = 0x03, #else - .bMasterInterface0 = 0, - .bSlaveInterface0 = 1, + .bMasterInterface0 = 0, + .bSlaveInterface0 = 1, #endif }; static struct UsbEndpointDescriptor g_acmFsNotifyDesc = { - .bLength = USB_DDK_DT_ENDPOINT_SIZE, - .bDescriptorType = USB_DDK_DT_ENDPOINT, + .bLength = USB_DDK_DT_ENDPOINT_SIZE, + .bDescriptorType = USB_DDK_DT_ENDPOINT, .bEndpointAddress = EP_ADD_NOTIFY | USB_DDK_DIR_IN, - .bmAttributes = USB_DDK_ENDPOINT_XFER_INT, - .wMaxPacketSize = CPU_TO_LE16(ACM_NOTIFY_MAXPACKET), - .bInterval = ACM_NOTIFY_INTERVAL, + .bmAttributes = USB_DDK_ENDPOINT_XFER_INT, + .wMaxPacketSize = CPU_TO_LE16(ACM_NOTIFY_MAXPACKET), + .bInterval = ACM_NOTIFY_INTERVAL, }; static struct UsbEndpointDescriptor g_acmFsInDesc = { - .bLength = USB_DDK_DT_ENDPOINT_SIZE, - .bDescriptorType = USB_DDK_DT_ENDPOINT, + .bLength = USB_DDK_DT_ENDPOINT_SIZE, + .bDescriptorType = USB_DDK_DT_ENDPOINT, .bEndpointAddress = EP_ADD_DATA_IN | USB_DDK_DIR_IN, - .bmAttributes = USB_DDK_ENDPOINT_XFER_BULK, + .bmAttributes = USB_DDK_ENDPOINT_XFER_BULK, }; static struct UsbEndpointDescriptor g_acmFsOutDesc = { - .bLength = USB_DDK_DT_ENDPOINT_SIZE, - .bDescriptorType = USB_DDK_DT_ENDPOINT, + .bLength = USB_DDK_DT_ENDPOINT_SIZE, + .bDescriptorType = USB_DDK_DT_ENDPOINT, .bEndpointAddress = EP_ADD_DATA_OUT | USB_DDK_DIR_OUT, - .bmAttributes = USB_DDK_ENDPOINT_XFER_BULK, + .bmAttributes = USB_DDK_ENDPOINT_XFER_BULK, }; static struct UsbDescriptorHeader *g_acmFsFunction[] = { - (struct UsbDescriptorHeader *) &g_acmIadDescriptor, - (struct UsbDescriptorHeader *) &g_acmControlInterfaceDesc, - (struct UsbDescriptorHeader *) &g_acmHeaderDesc, - (struct UsbDescriptorHeader *) &g_acmCallMgmtDescriptor, - (struct UsbDescriptorHeader *) &g_acmDescriptor, - (struct UsbDescriptorHeader *) &g_acmUnionDesc, - (struct UsbDescriptorHeader *) &g_acmFsNotifyDesc, - (struct UsbDescriptorHeader *) &g_acmDataInterfaceDesc, - (struct UsbDescriptorHeader *) &g_acmFsInDesc, - (struct UsbDescriptorHeader *) &g_acmFsOutDesc, + (struct UsbDescriptorHeader *)&g_acmIadDescriptor, + (struct UsbDescriptorHeader *)&g_acmControlInterfaceDesc, + (struct UsbDescriptorHeader *)&g_acmHeaderDesc, + (struct UsbDescriptorHeader *)&g_acmCallMgmtDescriptor, + (struct UsbDescriptorHeader *)&g_acmDescriptor, + (struct UsbDescriptorHeader *)&g_acmUnionDesc, + (struct UsbDescriptorHeader *)&g_acmFsNotifyDesc, + (struct UsbDescriptorHeader *)&g_acmDataInterfaceDesc, + (struct UsbDescriptorHeader *)&g_acmFsInDesc, + (struct UsbDescriptorHeader *)&g_acmFsOutDesc, NULL, }; static struct UsbEndpointDescriptor g_acmHsNotifyDesc = { - .bLength = USB_DDK_DT_ENDPOINT_SIZE, - .bDescriptorType = USB_DDK_DT_ENDPOINT, + .bLength = USB_DDK_DT_ENDPOINT_SIZE, + .bDescriptorType = USB_DDK_DT_ENDPOINT, .bEndpointAddress = EP_ADD_NOTIFY | USB_DDK_DIR_IN, - .bmAttributes = USB_DDK_ENDPOINT_XFER_INT, - .wMaxPacketSize = CPU_TO_LE16(ACM_NOTIFY_MAXPACKET), - .bInterval = ACM_HS_NOTIFY_INTERVAL, + .bmAttributes = USB_DDK_ENDPOINT_XFER_INT, + .wMaxPacketSize = CPU_TO_LE16(ACM_NOTIFY_MAXPACKET), + .bInterval = ACM_HS_NOTIFY_INTERVAL, }; static struct UsbEndpointDescriptor g_acmHsInDesc = { - .bLength = USB_DDK_DT_ENDPOINT_SIZE, - .bDescriptorType = USB_DDK_DT_ENDPOINT, + .bLength = USB_DDK_DT_ENDPOINT_SIZE, + .bDescriptorType = USB_DDK_DT_ENDPOINT, .bEndpointAddress = EP_ADD_DATA_IN | USB_DDK_DIR_IN, - .bmAttributes = USB_DDK_ENDPOINT_XFER_BULK, - .wMaxPacketSize = CPU_TO_LE16(MAX_PACKET_SIZE), + .bmAttributes = USB_DDK_ENDPOINT_XFER_BULK, + .wMaxPacketSize = CPU_TO_LE16(MAX_PACKET_SIZE), }; static struct UsbEndpointDescriptor g_acmHsOutDesc = { - .bLength = USB_DDK_DT_ENDPOINT_SIZE, - .bDescriptorType = USB_DDK_DT_ENDPOINT, - .bEndpointAddress = EP_ADD_DATA_OUT | USB_DDK_DIR_OUT, - .bmAttributes = USB_DDK_ENDPOINT_XFER_BULK, - .wMaxPacketSize = CPU_TO_LE16(MAX_PACKET_SIZE), + .bLength = USB_DDK_DT_ENDPOINT_SIZE, + .bDescriptorType = USB_DDK_DT_ENDPOINT, + .bEndpointAddress = EP_ADD_DATA_OUT | USB_DDK_DIR_OUT, + .bmAttributes = USB_DDK_ENDPOINT_XFER_BULK, + .wMaxPacketSize = CPU_TO_LE16(MAX_PACKET_SIZE), }; static struct UsbDescriptorHeader *g_acmHsFunction[] = { - (struct UsbDescriptorHeader *) &g_acmIadDescriptor, - (struct UsbDescriptorHeader *) &g_acmControlInterfaceDesc, - (struct UsbDescriptorHeader *) &g_acmHeaderDesc, - (struct UsbDescriptorHeader *) &g_acmCallMgmtDescriptor, - (struct UsbDescriptorHeader *) &g_acmDescriptor, - (struct UsbDescriptorHeader *) &g_acmUnionDesc, - (struct UsbDescriptorHeader *) &g_acmHsNotifyDesc, - (struct UsbDescriptorHeader *) &g_acmDataInterfaceDesc, - (struct UsbDescriptorHeader *) &g_acmHsInDesc, - (struct UsbDescriptorHeader *) &g_acmHsOutDesc, + (struct UsbDescriptorHeader *)&g_acmIadDescriptor, + (struct UsbDescriptorHeader *)&g_acmControlInterfaceDesc, + (struct UsbDescriptorHeader *)&g_acmHeaderDesc, + (struct UsbDescriptorHeader *)&g_acmCallMgmtDescriptor, + (struct UsbDescriptorHeader *)&g_acmDescriptor, + (struct UsbDescriptorHeader *)&g_acmUnionDesc, + (struct UsbDescriptorHeader *)&g_acmHsNotifyDesc, + (struct UsbDescriptorHeader *)&g_acmDataInterfaceDesc, + (struct UsbDescriptorHeader *)&g_acmHsInDesc, + (struct UsbDescriptorHeader *)&g_acmHsOutDesc, NULL, }; static struct UsbEndpointDescriptor g_acmSsInDesc = { - .bLength = USB_DDK_DT_ENDPOINT_SIZE, - .bDescriptorType = USB_DDK_DT_ENDPOINT, + .bLength = USB_DDK_DT_ENDPOINT_SIZE, + .bDescriptorType = USB_DDK_DT_ENDPOINT, .bEndpointAddress = EP_ADD_DATA_IN | USB_DDK_DIR_IN, - .bmAttributes = USB_DDK_ENDPOINT_XFER_BULK, - .wMaxPacketSize = CPU_TO_LE16(SS_MAX_PACKET_SIZE), + .bmAttributes = USB_DDK_ENDPOINT_XFER_BULK, + .wMaxPacketSize = CPU_TO_LE16(SS_MAX_PACKET_SIZE), }; static struct UsbEndpointDescriptor g_acmSsOutDesc = { - .bLength = USB_DDK_DT_ENDPOINT_SIZE, - .bDescriptorType = USB_DDK_DT_ENDPOINT, + .bLength = USB_DDK_DT_ENDPOINT_SIZE, + .bDescriptorType = USB_DDK_DT_ENDPOINT, .bEndpointAddress = EP_ADD_DATA_OUT | USB_DDK_DIR_OUT, - .bmAttributes = USB_DDK_ENDPOINT_XFER_BULK, - .wMaxPacketSize = CPU_TO_LE16(SS_MAX_PACKET_SIZE), + .bmAttributes = USB_DDK_ENDPOINT_XFER_BULK, + .wMaxPacketSize = CPU_TO_LE16(SS_MAX_PACKET_SIZE), }; static struct UsbSsEpCompDescriptor g_acmSsBulkCompDesc = { - .bLength = sizeof(g_acmSsBulkCompDesc), + .bLength = sizeof(g_acmSsBulkCompDesc), .bDescriptorType = USB_DDK_DT_SS_ENDPOINT_COMP, }; static struct UsbDescriptorHeader *g_acmSsFunction[] = { - (struct UsbDescriptorHeader *) &g_acmIadDescriptor, - (struct UsbDescriptorHeader *) &g_acmControlInterfaceDesc, - (struct UsbDescriptorHeader *) &g_acmHeaderDesc, - (struct UsbDescriptorHeader *) &g_acmCallMgmtDescriptor, - (struct UsbDescriptorHeader *) &g_acmDescriptor, - (struct UsbDescriptorHeader *) &g_acmUnionDesc, - (struct UsbDescriptorHeader *) &g_acmHsNotifyDesc, - (struct UsbDescriptorHeader *) &g_acmSsBulkCompDesc, - (struct UsbDescriptorHeader *) &g_acmDataInterfaceDesc, - (struct UsbDescriptorHeader *) &g_acmSsInDesc, - (struct UsbDescriptorHeader *) &g_acmSsBulkCompDesc, - (struct UsbDescriptorHeader *) &g_acmSsOutDesc, - (struct UsbDescriptorHeader *) &g_acmSsBulkCompDesc, + (struct UsbDescriptorHeader *)&g_acmIadDescriptor, + (struct UsbDescriptorHeader *)&g_acmControlInterfaceDesc, + (struct UsbDescriptorHeader *)&g_acmHeaderDesc, + (struct UsbDescriptorHeader *)&g_acmCallMgmtDescriptor, + (struct UsbDescriptorHeader *)&g_acmDescriptor, + (struct UsbDescriptorHeader *)&g_acmUnionDesc, + (struct UsbDescriptorHeader *)&g_acmHsNotifyDesc, + (struct UsbDescriptorHeader *)&g_acmSsBulkCompDesc, + (struct UsbDescriptorHeader *)&g_acmDataInterfaceDesc, + (struct UsbDescriptorHeader *)&g_acmSsInDesc, + (struct UsbDescriptorHeader *)&g_acmSsBulkCompDesc, + (struct UsbDescriptorHeader *)&g_acmSsOutDesc, + (struct UsbDescriptorHeader *)&g_acmSsBulkCompDesc, NULL, }; static struct UsbString g_acmStringDefs[] = { - [0].s = "CDC Abstract Control Model (ACM)", - [1].s = "CDC ACM Data", - [2].s = "CDC Serial", - { } /* end of list */ + [0].s = "CDC Abstract Control Model (ACM)", [1].s = "CDC ACM Data", [2].s = "CDC Serial", {} /* end of list */ }; static struct UsbFnStrings g_acmStringTable = { .language = 0x0409, /* en-us */ - .strings = g_acmStringDefs, + .strings = g_acmStringDefs, }; static struct UsbFnStrings *g_acmStrings[] = { @@ -225,41 +222,41 @@ static struct UsbFnStrings *g_acmStrings[] = { }; static struct UsbFnFunction g_acmFunction = { - .funcName = "f_generic.0", - .strings = g_acmStrings, - .fsDescriptors = g_acmFsFunction, - .hsDescriptors = g_acmHsFunction, - .ssDescriptors = g_acmSsFunction, + .funcName = "f_generic.0", + .strings = g_acmStrings, + .fsDescriptors = g_acmFsFunction, + .hsDescriptors = g_acmHsFunction, + .ssDescriptors = g_acmSsFunction, .sspDescriptors = NULL, }; /** device **/ -#define BCD_USB 0x0200 -#define DEVICE_VENDOR_ID 0x12D1 -#define DEVICE_PRODUCT_ID 0x5000 -#define DEVICE_VERSION 0x0223 +#define BCD_USB 0x0200 +#define DEVICE_VENDOR_ID 0x12D1 +#define DEVICE_PRODUCT_ID 0x5000 +#define DEVICE_VERSION 0x0223 -#define USB_MAX_PACKET_SIZE 0x40 -#define POWER 500 +#define USB_MAX_PACKET_SIZE 0x40 +#define POWER 500 #define USB_FUNC_CONFIG_IDX USB_FUNC_FIRST_AVAIL_IDX -#define DRIVER_DESC "HDC Device" -#define CONFIG_DESC "hdc" +#define DRIVER_DESC "HDC Device" +#define CONFIG_DESC "hdc" static struct UsbDeviceDescriptor g_cdcMasterDeviceDesc = { - .bLength = sizeof(g_cdcMasterDeviceDesc), - .bDescriptorType = USB_DDK_DT_DEVICE, - .bcdUSB = CPU_TO_LE16(BCD_USB), - .bDeviceClass = 0, - .bDeviceSubClass = 0, - .bDeviceProtocol = 0, - .bMaxPacketSize0 = USB_MAX_PACKET_SIZE, - .idVendor = CPU_TO_LE16(DEVICE_VENDOR_ID), - .idProduct = CPU_TO_LE16(DEVICE_PRODUCT_ID), - .bcdDevice = CPU_TO_LE16(DEVICE_VERSION), - .iManufacturer = USB_FUNC_MANUFACTURER_IDX, - .iProduct = USB_FUNC_PRODUCT_IDX, - .iSerialNumber = USB_FUNC_SERIAL_IDX, + .bLength = sizeof(g_cdcMasterDeviceDesc), + .bDescriptorType = USB_DDK_DT_DEVICE, + .bcdUSB = CPU_TO_LE16(BCD_USB), + .bDeviceClass = 0, + .bDeviceSubClass = 0, + .bDeviceProtocol = 0, + .bMaxPacketSize0 = USB_MAX_PACKET_SIZE, + .idVendor = CPU_TO_LE16(DEVICE_VENDOR_ID), + .idProduct = CPU_TO_LE16(DEVICE_PRODUCT_ID), + .bcdDevice = CPU_TO_LE16(DEVICE_VERSION), + .iManufacturer = USB_FUNC_MANUFACTURER_IDX, + .iProduct = USB_FUNC_PRODUCT_IDX, + .iSerialNumber = USB_FUNC_SERIAL_IDX, .bNumConfigurations = 1, }; @@ -268,12 +265,12 @@ static struct UsbString g_stringsDev[] = { {USB_FUNC_PRODUCT_IDX, DRIVER_DESC}, {USB_FUNC_SERIAL_IDX, "0123456789POPLAR"}, {USB_FUNC_CONFIG_IDX, CONFIG_DESC}, - { } /* end of list */ + {} /* end of list */ }; static struct UsbFnStrings g_stringTabDev = { - .language = 0x0409, /* en-us */ - .strings = g_stringsDev, + .language = 0x0409, /* en-us */ + .strings = g_stringsDev, }; static struct UsbFnStrings *g_devStrings[] = { @@ -288,15 +285,14 @@ static struct UsbFnFunction *g_functions[] = { #ifdef CDC_ACM &g_acmFunction, #endif - NULL -}; + NULL}; static struct UsbFnConfiguration g_masterConfig = { .configurationValue = 1, - .iConfiguration = USB_FUNC_CONFIG_IDX, - .attributes = USB_CFG_BUS_POWERED, - .maxPower = POWER, - .functions = g_functions, + .iConfiguration = USB_FUNC_CONFIG_IDX, + .attributes = USB_CFG_BUS_POWERED, + .maxPower = POWER, + .functions = g_functions, }; static struct UsbFnConfiguration *g_configs[] = { @@ -305,9 +301,9 @@ static struct UsbFnConfiguration *g_configs[] = { }; struct UsbFnDeviceDesc g_acmFnDevice = { - .deviceDesc = &g_cdcMasterDeviceDesc, + .deviceDesc = &g_cdcMasterDeviceDesc, .deviceStrings = g_devStrings, - .configs = g_configs, + .configs = g_configs, }; static struct Serial *SerialAlloc(void) @@ -419,13 +415,13 @@ static int32_t AllocCtrlRequests(struct AcmDevice *acmDevice) return -1; } ctrlInfo->acm = acmDevice; - req = UsbFnAllocCtrlRequest(acmDevice->ctrlIface.handle, - sizeof(struct UsbCdcLineCoding) + sizeof(struct UsbCdcLineCoding)); + req = UsbFnAllocCtrlRequest( + acmDevice->ctrlIface.handle, sizeof(struct UsbCdcLineCoding) + sizeof(struct UsbCdcLineCoding)); if (req == NULL) { return -1; } req->complete = CtrlComplete; - req->context = ctrlInfo; + req->context = ctrlInfo; DListInsertTail(&req->list, head); acmDevice->ctrlReqNum++; } @@ -433,8 +429,8 @@ static int32_t AllocCtrlRequests(struct AcmDevice *acmDevice) return 0; } -static int32_t SendNotifyRequest(struct AcmDevice *acm, uint8_t type, - uint16_t value, const uint16_t *data, uint32_t length) +static int32_t SendNotifyRequest( + struct AcmDevice *acm, uint8_t type, uint16_t value, const uint16_t *data, uint32_t length) { struct UsbFnRequest *req = NULL; struct UsbCdcNotification *notify = NULL; @@ -447,8 +443,8 @@ static int32_t SendNotifyRequest(struct AcmDevice *acm, uint8_t type, return -1; } acm->notifyReq = NULL; - acm->pending = false; - req->length = sizeof(*notify) + length; + acm->pending = false; + req->length = sizeof(*notify) + length; notify = (struct UsbCdcNotification *)req->buf; notify->bmRequestType = USB_DDK_DIR_IN | USB_DDK_TYPE_CLASS | USB_DDK_RECIP_INTERFACE; @@ -476,8 +472,7 @@ static int32_t NotifySerialState(struct AcmDevice *acm) OsalMutexLock(&acm->lock); if (acm->notifyReq) { serialState = CPU_TO_LE16(acm->serialState); - ret = SendNotifyRequest(acm, USB_DDK_CDC_NOTIFY_SERIAL_STATE, - 0, &serialState, sizeof(acm->serialState)); + ret = SendNotifyRequest(acm, USB_DDK_CDC_NOTIFY_SERIAL_STATE, 0, &serialState, sizeof(acm->serialState)); } else { acm->pending = true; } @@ -508,8 +503,8 @@ static void NotifyComplete(uint8_t pipe, struct UsbFnRequest *req) static int32_t AllocNotifyRequest(struct AcmDevice *acmDevice) { /* allocate notification request */ - acmDevice->notifyReq = UsbFnAllocRequest(acmDevice->ctrlIface.handle, acmDevice->notifyPipe.id, - sizeof(struct UsbCdcNotification)); + acmDevice->notifyReq = + UsbFnAllocRequest(acmDevice->ctrlIface.handle, acmDevice->notifyPipe.id, sizeof(struct UsbCdcNotification)); if (acmDevice->notifyReq == NULL) { return -1; } @@ -554,9 +549,9 @@ static int32_t SendBreak(struct AcmDevice *acm, int32_t duration) } static struct AcmNotifyMethod g_notifyMethod = { - .Connect = Connect, + .Connect = Connect, .Disconnect = Disconnect, - .SendBreak = SendBreak, + .SendBreak = SendBreak, }; static uint32_t Enable(struct AcmDevice *acm) @@ -600,7 +595,7 @@ static int32_t Setup(struct AcmDevice *acm, const struct UsbFnCtrlRequest *setup { struct UsbFnRequest *req = NULL; struct CtrlInfo *ctrlInfo = NULL; - uint16_t value = LE16_TO_CPU(setup->value); + uint16_t value = LE16_TO_CPU(setup->value); uint16_t length = LE16_TO_CPU(setup->length); int32_t ret = 0; req = GetCtrlReq(acm); @@ -615,8 +610,7 @@ static int32_t Setup(struct AcmDevice *acm, const struct UsbFnCtrlRequest *setup ret = (int)length; break; case USB_DDK_CDC_REQ_GET_LINE_CODING: - ret = (length > sizeof(struct UsbCdcLineCoding)) ? \ - sizeof(struct UsbCdcLineCoding) : length; + ret = (length > sizeof(struct UsbCdcLineCoding)) ? sizeof(struct UsbCdcLineCoding) : length; if (acm->lineCoding.dwDTERate == 0) { acm->lineCoding = acm->port->lineCoding; } @@ -666,8 +660,9 @@ void AcmEventCallback(struct UsbFnEvent *event) { struct AcmDevice *acm = NULL; - if (event == NULL || event->context == NULL) + if (event == NULL || event->context == NULL) { return; + } acm = (struct AcmDevice *)event->context; switch (event->type) { case USBFN_STATE_BIND: @@ -808,7 +803,7 @@ int32_t RemoveUsbDevice(void) break; } } - + for (i = 0; i < device->numInterfaces; i++) { intfMgr = devMgr->interfaceMgr + i; if (intfMgr) { @@ -837,4 +832,3 @@ int32_t RemoveUsbDevice(void) return 0; } - diff --git a/framework/test/unittest/osal/osal_all_test.c b/framework/test/unittest/osal/osal_all_test.c index 6b264bb68e2f72dfce1ac324976ace65009ab5c3..30ad5d1435863902592d5099f5749df6ef053091 100644 --- a/framework/test/unittest/osal/osal_all_test.c +++ b/framework/test/unittest/osal/osal_all_test.c @@ -36,7 +36,7 @@ uint32_t g_osalTestCases[OSAL_TEST_CASE_CNT]; OsalTimespec g_hdfTestBegin; OsalTimespec g_hdfTestEnd; static int32_t g_waitMutexTime = 3100; -static int32_t g_threadTest1Flag = true; +static bool g_threadTest1Flag = true; OSAL_DECLARE_THREAD(thread1); OSAL_DECLARE_THREAD(thread2); OSAL_DECLARE_THREAD(thread); @@ -47,8 +47,8 @@ OSAL_DECLARE_SPINLOCK(g_spinTest); #define HDF_THREAD_TEST_SLEEP_US 600 #define HDF_THREAD_TEST_SLEEP_MS 300 #define HDF_THREAD_TEST_MUX_CNT 20 -static int g_thread1RunFlag; -static int g_threadMuxLockFlag; +static bool g_thread1RunFlag; +static bool g_threadMuxLockFlag; static int32_t g_test1Para = 120; static int32_t g_test2Para = 123; #define TIME_RANGE 200000 @@ -83,7 +83,7 @@ static int ThreadTest1(void *arg) g_waitMutexTime = HDF_WAIT_FOREVER; } ret = OsalMutexTimedLock(&g_mutexTest, g_waitMutexTime); - if (g_threadMuxLockFlag == true) { + if (g_threadMuxLockFlag) { UT_TEST_CHECK_RET(ret == HDF_FAILURE, OSAL_MUTEX_LOCK_TIMEOUT); } else { UT_TEST_CHECK_RET(ret == HDF_FAILURE, OSAL_MUTEX_LOCK_TIMEOUT); @@ -113,8 +113,8 @@ static int ThreadTest1(void *arg) return 0; } -static int g_thread2RunFlag; -static int32_t g_threadTest2Flag = true; +static bool g_thread2RunFlag; +static bool g_threadTest2Flag = true; static int ThreadTest2(void *arg) { static int cnt = 0; @@ -141,7 +141,7 @@ static int ThreadTest2(void *arg) cnt++; ret = OsalMutexTimedLock(&g_mutexTest, g_waitMutexTime); - if (g_threadMuxLockFlag == true) { + if (g_threadMuxLockFlag) { UT_TEST_CHECK_RET(ret == HDF_FAILURE, OSAL_MUTEX_LOCK_TIMEOUT); } else { UT_TEST_CHECK_RET(ret == HDF_FAILURE, OSAL_MUTEX_LOCK_TIMEOUT); @@ -192,7 +192,7 @@ static int32_t g_timerPeriod2Modify = 750; #define HDF_TEST_TIMER_MODIFY 2 #define HDF_TEST_TIMER_END 3 -static int g_timerLoop1RunFlag; +static bool g_timerLoop1RunFlag; static int g_timer1Cnt = 0; static void TimerLoopTest1(uintptr_t arg) { @@ -238,7 +238,7 @@ static void TimerLoopTest1(uintptr_t arg) g_timerLoop1RunFlag = true; } -static int g_timerLoop2RunFlag; +static bool g_timerLoop2RunFlag; static int g_timer2Cnt = 0; static void TimerLoopTest2(uintptr_t arg) { @@ -284,7 +284,7 @@ static void TimerLoopTest2(uintptr_t arg) g_timerLoop2RunFlag = true; } -static int g_timerOnceRunFlag; +static int g_timerOnceRunCnt = 0; static void TimerOnceTest(uintptr_t arg) { int32_t para; @@ -292,7 +292,7 @@ static void TimerOnceTest(uintptr_t arg) HDF_LOGE("%s %d", __func__, para); UT_TEST_CHECK_RET(para != g_timerPeriod3, OSAL_TIMER_PARA_CHECK); - g_timerOnceRunFlag++; + g_timerOnceRunCnt++; } static void OsaTimerTest(void) @@ -397,15 +397,15 @@ static void OsaCheckRun(int cnt) OsalTimespec diffTime = { 0, 0 }; if (cnt == THREAD_TEST_TIMER_RUN) { - UT_TEST_CHECK_RET(g_timerOnceRunFlag == 0, OSAL_TIMER_RUN_CHECK); - UT_TEST_CHECK_RET(g_timerLoop2RunFlag == false, OSAL_TIMER_RUN_CHECK); - UT_TEST_CHECK_RET(g_timerLoop1RunFlag == false, OSAL_TIMER_RUN_CHECK); + UT_TEST_CHECK_RET(g_timerOnceRunCnt == 0, OSAL_TIMER_RUN_CHECK); + UT_TEST_CHECK_RET(!g_timerLoop2RunFlag, OSAL_TIMER_RUN_CHECK); + UT_TEST_CHECK_RET(!g_timerLoop1RunFlag, OSAL_TIMER_RUN_CHECK); HDF_LOGI("[OSAL_UT_TEST]%s timer run end", __func__); } if (cnt == THREAD_TEST_TIMER_STOP) { - UT_TEST_CHECK_RET(g_timerOnceRunFlag != 1, OSAL_TIMER_STOP_CHECK); - UT_TEST_CHECK_RET(g_timerLoop2RunFlag != false, OSAL_TIMER_STOP_CHECK); + UT_TEST_CHECK_RET(g_timerOnceRunCnt != 1, OSAL_TIMER_STOP_CHECK); + UT_TEST_CHECK_RET(g_timerLoop2RunFlag, OSAL_TIMER_STOP_CHECK); HDF_LOGI("[OSAL_UT_TEST]%s timer stop end", __func__); } if (cnt == THREAD_TEST_TIMER_STOP) { @@ -502,8 +502,8 @@ static void OsaIrqTest(void) #define THREAD_TEST_MUX_BEGIN 3 #define THREAD_TEST_MUX_END 5 #define THREAD_TEST_SLEEP_MS 1 -static int g_thread3RunFlag; -static int32_t g_threadTestFlag = true; +static bool g_thread3RunFlag; +static bool g_threadTestFlag = true; static int ThreadTest(void *arg) { static int cnt = 0; @@ -795,9 +795,9 @@ static void OsaSpinTest(void) static void OsaCheckThreadRun(void) { - UT_TEST_CHECK_RET(g_thread1RunFlag == 0, OSAL_THREAD_RUN_CHECK); - UT_TEST_CHECK_RET(g_thread1RunFlag == 0, OSAL_THREAD_RUN_CHECK); - UT_TEST_CHECK_RET(g_thread1RunFlag == 0, OSAL_THREAD_RUN_CHECK); + UT_TEST_CHECK_RET(!g_thread1RunFlag, OSAL_THREAD_RUN_CHECK); + UT_TEST_CHECK_RET(!g_thread2RunFlag, OSAL_THREAD_RUN_CHECK); + UT_TEST_CHECK_RET(!g_thread3RunFlag, OSAL_THREAD_RUN_CHECK); HDF_LOGI("[OSAL_UT_TEST]%s end", __func__); } diff --git a/framework/test/unittest/platform/common/adc_test.c b/framework/test/unittest/platform/common/adc_test.c index f0dda75c673a5cfd618118bbd262244ff3ffa9fe..2c0e1466aab82b9eb6bea0ff8e868f587151a8f1 100644 --- a/framework/test/unittest/platform/common/adc_test.c +++ b/framework/test/unittest/platform/common/adc_test.c @@ -256,8 +256,7 @@ static int32_t AdcIfPerformanceTest(void) if (ret == HDF_SUCCESS) { endMs = OsalGetSysTimeMs(); useTime = endMs - startMs; - HDF_LOGI("----->interface performance test:[start:%llu(ms) - end:%llu(ms) = %llu (ms)] < 1ms[%d]\r\n", - startMs, endMs, useTime, useTime < 1 ? true : false); + HDF_LOGI("----->interface performance test:[start - end] < 1ms[%s]\r\n", useTime < 1 ? "yes" : "no"); return HDF_SUCCESS; } return HDF_FAILURE; diff --git a/framework/test/unittest/platform/common/dac_test.c b/framework/test/unittest/platform/common/dac_test.c index 15a2e30488d138dcfc02db76a872201108fd2e14..d87c47086059de74bd855ca89b9698bdfc1dff8f 100644 --- a/framework/test/unittest/platform/common/dac_test.c +++ b/framework/test/unittest/platform/common/dac_test.c @@ -250,8 +250,7 @@ static int32_t DacIfPerformanceTest(void) endMs = OsalGetSysTimeMs(); useTime = endMs - startMs; - HDF_LOGI("----->interface performance test:[start:%llu(ms) - end:%llu(ms) = %llu (ms)] < 1ms[%d]\r\n", - startMs, endMs, useTime, useTime < 1 ? true : false); + HDF_LOGI("----->interface performance test:[start - end] < 1ms[%s]\r\n", useTime < 1 ? "yes" : "no"); return HDF_SUCCESS; } diff --git a/framework/test/unittest/platform/common/gpio_test.c b/framework/test/unittest/platform/common/gpio_test.c index 7ef5111c601d83283f6548cf374ebdf081d89650..4768bd7ea359a924f0be4b442afe4d21e070cb00 100644 --- a/framework/test/unittest/platform/common/gpio_test.c +++ b/framework/test/unittest/platform/common/gpio_test.c @@ -473,8 +473,7 @@ static int32_t GpioIfPerformanceTest(void) endMs = OsalGetSysTimeMs(); useTime = endMs - startMs; - HDF_LOGI("----->interface performance test:[start:%lld(ms) - end:%lld(ms) = %lld (ms)] < 1ms[%d]\r\n", - startMs, endMs, useTime, useTime < 1 ? true : false); + HDF_LOGI("----->interface performance test:[start - end] < 1ms[%s]\r\n", useTime < 1 ? "yes" : "no"); return HDF_SUCCESS; } diff --git a/framework/test/unittest/platform/common/i2c_test.c b/framework/test/unittest/platform/common/i2c_test.c index 703958fb7a24873740d0ac8846a7b6a5ee9a2766..87e03a7ccd2591d66e3a1e0ca50e9972a53b303e 100644 --- a/framework/test/unittest/platform/common/i2c_test.c +++ b/framework/test/unittest/platform/common/i2c_test.c @@ -347,7 +347,7 @@ static int32_t I2cTestPeformance(void) if (handle != NULL) { useTime = endMs - startMs; - HDF_LOGI("----->interface performance test:[start - end] < 1ms[%d]\r\n", useTime < 1 ? true : false); + HDF_LOGI("----->interface performance test:[start - end] < 1ms[%s]\r\n", useTime < 1 ? "yes" : "no"); I2cClose(handle); return HDF_SUCCESS; } diff --git a/framework/test/unittest/platform/common/pwm_test.c b/framework/test/unittest/platform/common/pwm_test.c index 1e64858221aaa6ec13b376358f0195bbe98d26b1..8acb8071435843e4cfbbcb055d5fdfc41be47795 100644 --- a/framework/test/unittest/platform/common/pwm_test.c +++ b/framework/test/unittest/platform/common/pwm_test.c @@ -306,23 +306,28 @@ static int32_t PwmReliabilityTest(struct PwmTester *tester) (void)PwmSetConfig(tester->handle, &(tester->config.cfg)); (void)PwmSetConfig(tester->handle, NULL); + (void)PwmSetConfig(NULL, &(tester->config.cfg)); (void)PwmGetConfig(tester->handle, &cfg); (void)PwmGetConfig(tester->handle, NULL); + (void)PwmGetConfig(NULL, &cfg); (void)PwmSetPeriod(tester->handle, 0); (void)PwmSetPeriod(tester->handle, TEST_PERIOD); + (void)PwmSetPeriod(NULL, TEST_PERIOD); (void)PwmSetDuty(tester->handle, 0); (void)PwmSetDuty(tester->handle, TEST_DUTY); + (void)PwmSetDuty(NULL, TEST_DUTY); (void)PwmSetPolarity(tester->handle, 0); (void)PwmSetPolarity(tester->handle, TEST_POLARITY); + (void)PwmSetPolarity(NULL, TEST_POLARITY); (void)PwmEnable(tester->handle); - (void)PwmEnable(tester->handle); + (void)PwmEnable(NULL); (void)PwmDisable(tester->handle); - (void)PwmDisable(tester->handle); + (void)PwmDisable(NULL); HDF_LOGI("%s: success.", __func__); return HDF_SUCCESS; } @@ -347,8 +352,7 @@ static int32_t PwmIfPerformanceTest(struct PwmTester *tester) endMs = OsalGetSysTimeMs(); useTime = endMs - startMs; - HDF_LOGI("----->interface performance test:[start:%llu(ms) - end:%llu(ms) = %llu (ms)] < 1ms[%d]\r\n", - startMs, endMs, useTime, useTime < 1 ? true : false); + HDF_LOGI("----->interface performance test:[start - end] < 1ms[%s]\r\n", useTime < 1 ? "yes" : "no"); return HDF_SUCCESS; } diff --git a/framework/test/unittest/platform/common/spi_test.c b/framework/test/unittest/platform/common/spi_test.c index 5014621b864d0b252b76f0abddbbcc7299211a9a..d872afffa0cd856b2197fd1bf30484bb726a1b46 100644 --- a/framework/test/unittest/platform/common/spi_test.c +++ b/framework/test/unittest/platform/common/spi_test.c @@ -500,8 +500,7 @@ static int32_t SpiIfPerformanceTest(struct SpiTester *tester) if (ret == HDF_SUCCESS) { useTime = endMs - startMs; - HDF_LOGI("----->interface performance test:[start:%llu(ms) - end:%llu(ms) = %llu (ms)] < 1ms[%d]\r\n", - startMs, endMs, useTime, useTime < 1 ? true : false); + HDF_LOGI("----->interface performance test:[start - end] < 1ms[%s]\r\n", useTime < 1 ? "yes" : "no"); return HDF_SUCCESS; } return HDF_FAILURE; diff --git a/framework/test/unittest/platform/common/timer_test.c b/framework/test/unittest/platform/common/timer_test.c index 0d94de8a71677e48c7ad2c9b514c73e130bf4236..b9a6ccdf3e35063d2239edf151a3cb29b0c607e1 100644 --- a/framework/test/unittest/platform/common/timer_test.c +++ b/framework/test/unittest/platform/common/timer_test.c @@ -362,8 +362,7 @@ static int32_t TimerIfPerformanceTest(struct TimerTest *test) endMs = OsalGetSysTimeMs(); useTime = endMs - startMs; - HDF_LOGI("----->interface performance test:[start:%llu(ms) - end:%llu(ms) = %llu (ms)] < 1ms[%d]\r\n", startMs, - endMs, useTime, useTime < 1 ? true : false); + HDF_LOGI("----->interface performance test:[start - end] < 1ms[%s]\r\n", useTime < 1 ? "yes" : "no"); return HDF_SUCCESS; } diff --git a/framework/test/unittest/platform/common/uart_test.c b/framework/test/unittest/platform/common/uart_test.c index 098d368794843a6c4ca5e42a76fa6d81ac1248c4..ed3d7b15b49a91f1139049e3b8f35864d96678f4 100644 --- a/framework/test/unittest/platform/common/uart_test.c +++ b/framework/test/unittest/platform/common/uart_test.c @@ -297,8 +297,7 @@ static int32_t UartIfPerformanceTest(struct UartTester *tester) endMs = OsalGetSysTimeMs(); useTime = endMs - startMs; - HDF_LOGI("----->interface performance test:[start:%llu(ms) - end:%llu(ms) = %llu (ms)] < 1ms[%d]\r\n", - startMs, endMs, useTime, useTime < 1 ? true : false); + HDF_LOGI("----->interface performance test:[start - end] < 1ms[%s]\r\n", useTime < 1 ? "yes" : "no"); return HDF_SUCCESS; } diff --git a/framework/test/unittest/platform/common/watchdog_test.c b/framework/test/unittest/platform/common/watchdog_test.c index df25cdcd36302bdc79d6015a25510c12b1f76d62..3c18063565cd3d01dbe5f516973441a5461d7fd7 100644 --- a/framework/test/unittest/platform/common/watchdog_test.c +++ b/framework/test/unittest/platform/common/watchdog_test.c @@ -277,8 +277,7 @@ static int32_t TestCaseWatchdogIfPerformanceTest(struct WatchdogTester *tester) endMs = OsalGetSysTimeMs(); useTime = endMs - startMs; - HDF_LOGI("----->interface performance test:[start:%lld(ms) - end:%lld(ms) = %lld (ms)] < 1ms[%d]\r\n", - startMs, endMs, useTime, useTime < 1 ? true : false); + HDF_LOGI("----->interface performance test:[start - end] < 1ms[%s]\r\n", useTime < 1 ? "yes" : "no"); return HDF_SUCCESS; } diff --git a/framework/test/unittest/pm/hdf_pm_driver_test.c b/framework/test/unittest/pm/hdf_pm_driver_test.c index 730dca260dc3209018fac101f9bfc88e5d9e68bc..3b0845e35ecd799cb2d634a9607bd87b185d0c7c 100644 --- a/framework/test/unittest/pm/hdf_pm_driver_test.c +++ b/framework/test/unittest/pm/hdf_pm_driver_test.c @@ -392,9 +392,6 @@ static int32_t HdfPmTestThreeDriver(const uint32_t times, bool sync) if (sync) { total += PM_TEST_COUNT_ONE; - } - - if (sync) { HdfPmTestAcquireSync(PM_TEST_DRIVER); HdfPmTestAcquireSync(HDF_TEST_DRIVER); HdfPmTestAcquireSync(SAMPLE_TEST_DRIVER); diff --git a/framework/tools/hc-gen/Makefile b/framework/tools/hc-gen/Makefile index 2574a29b7d9c8eb70c242a317524692f160c44de..e7fde3daee97db60b652e30453423d5fbeede569 100644 --- a/framework/tools/hc-gen/Makefile +++ b/framework/tools/hc-gen/Makefile @@ -9,7 +9,7 @@ BUILD_DIR := build TARGET := $(BUILD_DIR)/hc-gen CXX := c++ -CXX_FLAGS := -std=gnu++14 +CXX_FLAGS := -std=gnu++14 -s CXX_LD_FLAGS := -lstdc++ SRCS := $(wildcard src/*.cpp) diff --git a/framework/tools/hc-gen/src/ast.cpp b/framework/tools/hc-gen/src/ast.cpp index 4124bbb94ba51fcc655e9f4e62b6c15198f39d59..ba3d3104994070190b1f70fdd92c9dbfd0044525 100644 --- a/framework/tools/hc-gen/src/ast.cpp +++ b/framework/tools/hc-gen/src/ast.cpp @@ -16,53 +16,59 @@ using namespace OHOS::Hardware; -AstObject::AstObject(const AstObject &obj) : AstObject(obj.name_, obj.type_, obj.stringValue_) -{ - integerValue_ = obj.integerValue_; - src_ = obj.src_; -} +static constexpr int FOUR_MULTIPLE = 4; -AstObject::AstObject(std::string name, uint32_t type, uint64_t value) +AstObject::AstObject(std::string name, uint32_t type, uint64_t integerValue, std::string strValue, uint32_t lineno, + const std::shared_ptr &src) : type_(type), name_(std::move(name)), parent_(nullptr), - lineno_(0), + next_(nullptr), + child_(nullptr), + lineno_(lineno), + src_(src), opCode_(0), size_(0), subSize_(0), hash_(0), - integerValue_(value) + integerValue_(integerValue), + stringValue_(strValue) { } -AstObject::AstObject(std::string name, uint32_t type, std::string value) - : AstObject(std::move(name), type, 0) +AstObject::AstObject(std::string name, uint32_t type, uint64_t integerValue) + : AstObject(std::move(name), type, integerValue, "", 0, nullptr) { - stringValue_ = std::move(value); } -AstObject::AstObject(std::string name, uint32_t type, uint64_t value, const Token &bindToken) - : AstObject(std::move(name), type, value) +AstObject::AstObject(std::string name, uint32_t type, std::string strValue) + : AstObject(std::move(name), type, 0, strValue, 0, nullptr) { - lineno_ = bindToken.lineNo; - src_ = bindToken.src; +} +AstObject::AstObject(std::string name, uint32_t type, uint64_t integerValue, const Token &bindToken) + : AstObject(std::move(name), type, integerValue, "", bindToken.lineNo, bindToken.src) +{ switch (type) { case PARSEROP_UINT8: /* fall-through */ case PARSEROP_UINT16: /* fall-through */ case PARSEROP_UINT32: /* fall-through */ case PARSEROP_UINT64: - this->type_ = FitIntegerValueType(value); + this->type_ = FitIntegerValueType(integerValue); break; default: break; } } -AstObject::AstObject(std::string name, uint32_t type, std::string value, const Token &bindToken) - : AstObject(std::move(name), type, 0, bindToken) +AstObject::AstObject(std::string name, uint32_t type, std::string strValue, const Token &bindToken) + : AstObject(std::move(name), type, 0, strValue, bindToken.lineNo, bindToken.src) +{ +} + +AstObject::AstObject(const AstObject &obj) + : AstObject(obj.name_, obj.type_, obj.integerValue_, obj.stringValue_, 0, obj.src_) { - stringValue_ = std::move(value); } AstObject::~AstObject() @@ -372,7 +378,7 @@ const std::string &AstObject::Name() return name_; } -const std::string &AstObject::StringValue() +const std::string &AstObject::StringValue() const { return stringValue_; } @@ -492,7 +498,7 @@ uint32_t ConfigNode::GetNodeType() const return nodeType_; } -const std::string &ConfigNode::GetRefPath() +const std::string &ConfigNode::GetRefPath() const { return refNodePath_; } @@ -650,7 +656,7 @@ bool ConfigNode::NodeCopyExpand(const std::shared_ptr &ref) return Copy(ref, false); } -bool ConfigNode::Compare(ConfigNode &other) +bool ConfigNode::Compare(ConfigNode &other) const { auto objChild = child_; while (objChild != nullptr) { @@ -688,7 +694,7 @@ void ConfigNode::SetTemplateSignNum(uint32_t sigNum) templateSignNum_ = sigNum; } -const std::list &ConfigNode::SubClasses() +const std::list &ConfigNode::SubClasses() const { return subClasses_; } @@ -923,7 +929,7 @@ void Ast::Dump(const std::string &prefix) { Logger().Debug() << "Dump " << prefix << " AST:"; WalkForward([](const std::shared_ptr ¤t, int32_t walkDepth) -> int32_t { - Logger().Debug() << ::std::setw(walkDepth * 4) << " " << *current; + Logger().Debug() << ::std::setw(walkDepth * FOUR_MULTIPLE) << " " << *current; return NOERR; }); } @@ -1119,7 +1125,6 @@ std::shared_ptr Ast::Lookup(const std::shared_ptr &startOb splitPath.erase(splitPath.begin()); std::shared_ptr target = astRoot_; - std::shared_ptr child = astRoot_->Child(); for (auto &it : splitPath) { // look up children target = target->Lookup(it); @@ -1131,7 +1136,7 @@ std::shared_ptr Ast::Lookup(const std::shared_ptr &startOb return target; } -std::list Ast::SplitNodePath(const std::string &path, char separator) const +std::list Ast::SplitNodePath(const std::string &path, char separator) { std::list splitList; std::string temp; diff --git a/framework/tools/hc-gen/src/ast.h b/framework/tools/hc-gen/src/ast.h index 40035de44dcc48fffab2607d278073079930593c..a09a2be093c52e5cfa30a244428574d092c8cdb7 100644 --- a/framework/tools/hc-gen/src/ast.h +++ b/framework/tools/hc-gen/src/ast.h @@ -45,15 +45,18 @@ class AstObject { public: friend class Ast; - AstObject(const AstObject &obj); + AstObject(std::string name, uint32_t type, uint64_t integerValue, std::string strValue, uint32_t lineno, + const std::shared_ptr &src); + + AstObject(std::string name, uint32_t type, uint64_t integerValue); - AstObject(std::string name, uint32_t type, uint64_t value); + AstObject(std::string name, uint32_t type, std::string strValue); - AstObject(std::string name, uint32_t type, std::string value); + AstObject(std::string name, uint32_t type, uint64_t integerValue, const Token &bindToken); - AstObject(std::string name, uint32_t type, uint64_t value, const Token &bindToken); + AstObject(std::string name, uint32_t type, std::string strValue, const Token &bindToken); - AstObject(std::string name, uint32_t type, std::string value, const Token &bindToken); + AstObject(const AstObject &obj); virtual ~AstObject(); @@ -109,7 +112,7 @@ public: virtual const std::string &Name(); - const std::string &StringValue(); + const std::string &StringValue() const; uint64_t IntegerValue() const; @@ -162,7 +165,7 @@ public: uint32_t GetNodeType() const; - const std::string &GetRefPath(); + const std::string &GetRefPath() const; void SetNodeType(uint32_t nodeType); @@ -180,7 +183,7 @@ public: bool Move(std::shared_ptr src) override; - bool Compare(ConfigNode &other); + bool Compare(ConfigNode &other) const; bool IsBaseNode(); @@ -192,7 +195,7 @@ public: void SetTemplateSignNum(uint32_t sigNum); - const std::list &SubClasses(); + const std::list &SubClasses() const; private: bool NodeRefExpand(const std::shared_ptr &ref); @@ -442,7 +445,7 @@ private: bool InheritExpand(); - std::list SplitNodePath(const std::string &path, char separator) const; + static std::list SplitNodePath(const std::string &path, char separator); std::shared_ptr astRoot_; bool redefineChecked_; diff --git a/framework/tools/hc-gen/src/bytecode_gen.cpp b/framework/tools/hc-gen/src/bytecode_gen.cpp index e2c8f64cf121e2e45643376199cb8732a4af3963..99ca76b8fd97a54cb15c5de0889f283b7b1f9a0a 100644 --- a/framework/tools/hc-gen/src/bytecode_gen.cpp +++ b/framework/tools/hc-gen/src/bytecode_gen.cpp @@ -128,11 +128,11 @@ void ByteCodeGen::Write(T &data) void ByteCodeGen::Write(const char *data, uint32_t size) { FsWrite(data, size); - static char stubData[ALIGN_SIZE] = {0}; auto alignSize = Align(size); auto stubSize = alignSize - size; if (stubSize != 0) { + static char stubData[ALIGN_SIZE] = {0}; FsWrite(stubData, stubSize); } diff --git a/framework/tools/hc-gen/src/decompile_gen.cpp b/framework/tools/hc-gen/src/decompile_gen.cpp index 27a6fcb684f5d2a8c2de6205af544e8ca7ac8aa2..9e87810da3fe19387106995195c19c396bbacf26 100644 --- a/framework/tools/hc-gen/src/decompile_gen.cpp +++ b/framework/tools/hc-gen/src/decompile_gen.cpp @@ -13,9 +13,12 @@ using namespace OHOS::Hardware; -DecompileGen::DecompileGen(std::shared_ptr ast, std::string outPutFileName) : ast_(ast) +DecompileGen::DecompileGen(std::shared_ptr ast, std::string outPutFileName) + : fileHeader_("/*\n * HDF decompile hcs file\n */\n\n"), + outPutFileName_(Util::File::StripSuffix(std::move(outPutFileName)).append(".d.hcs")), + file_(), + ast_(ast) { - outPutFileName_ = Util::File::StripSuffix(std::move(outPutFileName)).append(".d.hcs"); Logger().Debug() << "Decompile gen file: " << outPutFileName_; } @@ -125,7 +128,6 @@ uint32_t DecompileGen::OutPutWalk(const std::shared_ptr &astObj, int3 if (astObj->Type() != PARSEROP_CONFNODE && astObj->Type() != PARSEROP_CONFTERM) { return NOERR; } - int ret; std::string tabStr = std::string(TAB_SIZE * walkDepth, ' '); if (walkDepth != 0) { WriteFile(tabStr); @@ -140,15 +142,16 @@ uint32_t DecompileGen::OutPutWalk(const std::shared_ptr &astObj, int3 WriteFile(tabStr); } break; - case PARSEROP_CONFTERM: + case PARSEROP_CONFTERM: { str = astObj->Name() + " = "; WriteFile(str); - ret = PrintBaseType(astObj->Child()); + int32_t ret = PrintBaseType(astObj->Child()); if (ret != NOERR) { return ret; } WriteFile(";\n"); break; + } default: return EOUTPUT; } diff --git a/framework/tools/hc-gen/src/decompile_gen.h b/framework/tools/hc-gen/src/decompile_gen.h index d62150f33e5a16c8c57d90c32d9e0c1b153d1b99..3cf647887e95ec9879ebabaccfe0a7958bc3b81f 100644 --- a/framework/tools/hc-gen/src/decompile_gen.h +++ b/framework/tools/hc-gen/src/decompile_gen.h @@ -39,7 +39,7 @@ private: uint32_t CloseBrace(const std::shared_ptr &astObj, int32_t walkDepth); - const std::string fileHeader_ = "/*\n * HDF decompile hcs file\n */\n\n"; + const std::string fileHeader_; std::string outPutFileName_; std::ofstream file_; std::shared_ptr ast_; diff --git a/framework/tools/hc-gen/src/lexer.cpp b/framework/tools/hc-gen/src/lexer.cpp index 961f0cfc2b09cba164d00cb7ce93dc654ea85ae2..e36e94fbb97420f997ce0695a9426d2c765a3387 100644 --- a/framework/tools/hc-gen/src/lexer.cpp +++ b/framework/tools/hc-gen/src/lexer.cpp @@ -235,7 +235,7 @@ std::ostream &OHOS::Hardware::operator<<(std::ostream &stream, const Lexer &p) return stream << p.GetSourceName()->data() << ":" << p.GetLineno() << ":" << p.GetLineLoc() << ": "; } -void Lexer::InitToken(Token &token) +void Lexer::InitToken(Token &token) const { token.type = 0; token.numval = 0; diff --git a/framework/tools/hc-gen/src/lexer.h b/framework/tools/hc-gen/src/lexer.h index e745f99e4c8c9907b7f16bba53083bc13fe906ec..9696c79ff3c00b5bdc9952a665c8186b607809a3 100644 --- a/framework/tools/hc-gen/src/lexer.h +++ b/framework/tools/hc-gen/src/lexer.h @@ -41,7 +41,7 @@ public: private: static constexpr int BUFFER_SIZE = (1024 * 1024); - void InitToken(Token &token); + void InitToken(Token &token) const; bool GetChar(char &c, bool skipSpace = true); diff --git a/framework/tools/hc-gen/src/logger.h b/framework/tools/hc-gen/src/logger.h index 67d4d3f94b5b8e9cb4269b85b24fa37a09c08f46..ea71e47c24d60e0f10a1ba32db2d963e66e1e253 100644 --- a/framework/tools/hc-gen/src/logger.h +++ b/framework/tools/hc-gen/src/logger.h @@ -90,7 +90,7 @@ private: FATAL, } level_; - void ShowLevel() + void ShowLevel() const { static ::std::map levelStrMap = { {NONE, "" }, diff --git a/framework/tools/hc-gen/src/macro_gen.cpp b/framework/tools/hc-gen/src/macro_gen.cpp index d287be80b3cd67cd92d6f602867cd452b9a5e29c..fc6de4a775dcd66a354ff7a72d1c743ce2358c5d 100644 --- a/framework/tools/hc-gen/src/macro_gen.cpp +++ b/framework/tools/hc-gen/src/macro_gen.cpp @@ -6,6 +6,7 @@ * See the LICENSE file in the root of this repository for complete details. */ +#include #include #include "file.h" @@ -21,7 +22,7 @@ constexpr static const char *FILE_HEAD_COMMENT = MacroGen::MacroGen(std::shared_ptr ast) : Generator(ast) {} -const std::string &MacroGen::ToUpperString(std::string &str) const +const std::string &MacroGen::ToUpperString(std::string &str) { for (char &c : str) { c = static_cast(toupper(c)); @@ -206,11 +207,7 @@ std::string MacroGen::GenRefObjName(int32_t depth, const std::shared_ptrStringValue()); } else { - for (char &c : name) { - if (c == '.') { - c = '_'; - } - } + std::replace(name.begin(), name.end(), '.', '_'); } return name; } diff --git a/framework/tools/hc-gen/src/macro_gen.h b/framework/tools/hc-gen/src/macro_gen.h index 2339d5824070f2e0e35d44c4590aa740d2fedb26..658a116516cf674a676451168ff0f0413c322c26 100644 --- a/framework/tools/hc-gen/src/macro_gen.h +++ b/framework/tools/hc-gen/src/macro_gen.h @@ -44,7 +44,7 @@ private: bool HeaderBottomOutput(); - const std::string &ToUpperString(std::string &str) const; + static const std::string &ToUpperString(std::string &str); bool GenArray(const std::string &arrName, uint32_t &arrSize, uint32_t type, const std::shared_ptr &node); diff --git a/framework/tools/hc-gen/src/option.cpp b/framework/tools/hc-gen/src/option.cpp index ef81da16416675cc92e4ad5d21b317b3750aa48d..e43cfe6ff089a7addc5593444a2be2b3186d55c1 100644 --- a/framework/tools/hc-gen/src/option.cpp +++ b/framework/tools/hc-gen/src/option.cpp @@ -18,8 +18,8 @@ using namespace OHOS::Hardware; static constexpr int HCS_COMPILER_VERSION_MAJOR = 00; static constexpr int HCS_COMPILER_VERSION_MINOR = 7; - static constexpr int ARG_COUNT_MIN = 2; +static constexpr int SPACE_WIDTH = 12; Option &Option::Instance() { @@ -140,7 +140,7 @@ void Option::ShowUsage() const void Option::ShowOption(const ::std::string &option, const ::std::string &helpInfo) { - Logger() << " " << ::std::setw(12) << ::std::left << option << " " << helpInfo; + Logger() << " " << ::std::setw(SPACE_WIDTH) << ::std::left << option << " " << helpInfo; } bool Option::ShouldShowUsage() const @@ -199,7 +199,7 @@ bool Option::ShouldGenStartConfig() const return genStartCfg_; } -std::string Option::GetSymbolPrefix() +std::string Option::GetSymbolPrefix() const { return symbolNamePrefix_; } @@ -215,22 +215,22 @@ void Option::SetOptionError(bool shouldShowUsage) optionError_ = true; } -std::string Option::GetSourceName() +std::string Option::GetSourceName() const { return sourceName_; } -std::string Option::GetSourceNameBase() +std::string Option::GetSourceNameBase() const { return sourceNameBase_; } -std::string Option::GetOutputName() +std::string Option::GetOutputName() const { return outputName_; } -std::string Option::GetSourceDir() +std::string Option::GetSourceDir() const { return sourceDir_; } diff --git a/framework/tools/hc-gen/src/option.h b/framework/tools/hc-gen/src/option.h index 527a9ba87d91d76e4b13512ccbc61d5d67dd9cd7..9c3c8b21cff43490e662d1dde6f9587aaa1e66ba 100644 --- a/framework/tools/hc-gen/src/option.h +++ b/framework/tools/hc-gen/src/option.h @@ -48,19 +48,19 @@ public: bool ShouldDecompile() const; - std::string GetSymbolPrefix(); + std::string GetSymbolPrefix() const; - std::string GetSourceName(); + std::string GetSourceName() const; - std::string GetSourceNameBase(); + std::string GetSourceNameBase() const; - std::string GetOutputName(); + std::string GetOutputName() const; void GetVersion(uint32_t &minor, uint32_t &major) const; bool VerboseLog() const; - std::string GetSourceDir(); + std::string GetSourceDir() const; static std::string RealPathSourcePath(const char *path); diff --git a/framework/tools/hc-gen/src/parser.cpp b/framework/tools/hc-gen/src/parser.cpp index 1b0ac1b4465224584620d63afdc3a72c13c2f851..ce5863e478c80879a337c45164146ce4efdd87ff 100644 --- a/framework/tools/hc-gen/src/parser.cpp +++ b/framework/tools/hc-gen/src/parser.cpp @@ -15,7 +15,7 @@ using namespace OHOS::Hardware; -Parser::Parser() : errno_(NOERR), current_() {} +Parser::Parser() : errno_(NOERR) {} void Parser::CleanError() { diff --git a/framework/tools/hc-gen/src/startup_cfg_gen.cpp b/framework/tools/hc-gen/src/startup_cfg_gen.cpp index f11f437a492773bac1c58367fcfe70dc557327e7..62e3c7ba2b2cd8d15ce08be52b4eea10b6a4b3e8 100644 --- a/framework/tools/hc-gen/src/startup_cfg_gen.cpp +++ b/framework/tools/hc-gen/src/startup_cfg_gen.cpp @@ -31,12 +31,13 @@ static constexpr const char *BOOT_CONFIG_BOTTOM = static constexpr const char *SERVICE_TOP = " {\n" " \"name\" : "; -static constexpr const char *PATH_INFO = " \"path\" : [\"/vendor/bin/hdf_devhost\", "; -static constexpr const char *UID_INFO = " \"uid\" : "; -static constexpr const char *GID_INFO = " \"gid\" : ["; -static constexpr const char *CAPS_INFO = " \"caps\" : ["; -static constexpr const char *DYNAMIC_INFO = " \"ondemand\" : true,\n"; -static constexpr const char *SECON_INFO = " \"secon\" : \"u:r:"; +static constexpr const char *PATH_INFO = " \"path\" : [\"/vendor/bin/hdf_devhost\", "; +static constexpr const char *UID_INFO = " \"uid\" : "; +static constexpr const char *GID_INFO = " \"gid\" : ["; +static constexpr const char *CAPS_INFO = " \"caps\" : ["; +static constexpr const char *DYNAMIC_INFO = " \"ondemand\" : true,\n"; +static constexpr const char *SECON_INFO = " \"secon\" : \"u:r:"; +static constexpr const char *CRITICAL_INFO = " \"critical\" : ["; StartupCfgGen::StartupCfgGen(const std::shared_ptr &ast) : Generator(ast) { @@ -96,24 +97,34 @@ bool StartupCfgGen::Initialize() void StartupCfgGen::HostInfoOutput(const std::string &name, bool end) { ofs_ << SERVICE_TOP << "\"" << name << "\",\n"; + if (hostInfoMap_[name].dynamicLoad) { ofs_ << DYNAMIC_INFO; } + ofs_ << PATH_INFO << "\"" << hostInfoMap_[name].hostId << "\", \"" << name <<"\"],\n"; ofs_ << UID_INFO << "\"" << hostInfoMap_[name].hostUID <<"\",\n"; ofs_ << GID_INFO << hostInfoMap_[name].hostGID <<"],\n"; + if (!hostInfoMap_[name].hostCaps.empty()) { ofs_ << CAPS_INFO << hostInfoMap_[name].hostCaps <<"],\n"; } + + if (!hostInfoMap_[name].hostCritical.empty()) { + ofs_ << CRITICAL_INFO << hostInfoMap_[name].hostCritical <<"],\n"; + } + ofs_ << SECON_INFO << name << ":s0\"\n"; + ofs_ << TAB TAB << "}"; + if (!end) { ofs_<< ","; } ofs_ << '\n'; } -void StartupCfgGen::InitHostInfo(HostInfo &hostData) const +void StartupCfgGen::InitHostInfo(HostInfo &hostData) { hostData.dynamicLoad = true; hostData.hostCaps = ""; @@ -121,6 +132,7 @@ void StartupCfgGen::InitHostInfo(HostInfo &hostData) const hostData.hostGID = ""; hostData.hostPriority = 0; hostData.hostId = 0; + hostData.hostCritical = ""; } bool StartupCfgGen::TemplateNodeSeparate() @@ -158,7 +170,7 @@ void StartupCfgGen::HostInfosOutput() } } -void StartupCfgGen::GetConfigArray(const std::shared_ptr &term, std::string &config) const +void StartupCfgGen::GetConfigArray(const std::shared_ptr &term, std::string &config) { if (term == nullptr) { return; @@ -171,7 +183,7 @@ void StartupCfgGen::GetConfigArray(const std::shared_ptr &term, std:: uint16_t arraySize = ConfigArray::CastFrom(arrayObj)->ArraySize(); std::shared_ptr object = arrayObj->Child(); - while (arraySize && object != nullptr) { + while (arraySize != 0 && object != nullptr) { if (!object->StringValue().empty()) { config.append("\"").append(object->StringValue()).append("\""); if (arraySize != 1) { @@ -184,7 +196,32 @@ void StartupCfgGen::GetConfigArray(const std::shared_ptr &term, std:: } } -void StartupCfgGen::GetHostLoadMode(const std::shared_ptr &hostInfo, HostInfo &hostData) const +void StartupCfgGen::GetConfigIntArray(const std::shared_ptr &term, std::string &config) +{ + if (term == nullptr) { + return; + } + + std::shared_ptr intArrayObj = term->Child(); + if (intArrayObj == nullptr) { + return; + } + + uint16_t arraySize = ConfigArray::CastFrom(intArrayObj)->ArraySize(); + std::shared_ptr object = intArrayObj->Child(); + while (arraySize && object != nullptr) { + std::string value = std::to_string(object->IntegerValue()); + config.append(value); + if (arraySize != 1) { + config.append(", "); + } + + object = object->Next(); + arraySize--; + } +} + +void StartupCfgGen::GetHostLoadMode(const std::shared_ptr &hostInfo, HostInfo &hostData) { uint32_t preload; std::shared_ptr current = nullptr; @@ -196,6 +233,7 @@ void StartupCfgGen::GetHostLoadMode(const std::shared_ptr &hostInfo, devInfo = devInfo->Next(); continue; } + devNodeInfo = devInfo->Child(); while (devNodeInfo != nullptr) { current = devNodeInfo->Lookup("preload", PARSEROP_CONFTERM); @@ -203,10 +241,12 @@ void StartupCfgGen::GetHostLoadMode(const std::shared_ptr &hostInfo, devNodeInfo = devNodeInfo->Next(); continue; } + preload = current->Child()->IntegerValue(); if (preload == 0 || preload == 1) { hostData.dynamicLoad = false; } + devNodeInfo = devNodeInfo->Next(); } devInfo = devInfo->Next(); @@ -252,6 +292,7 @@ bool StartupCfgGen::GetHostInfo() hostInfo = hostInfo->Next(); continue; } + InitHostInfo(hostData); serviceName = object->Child()->StringValue(); @@ -271,7 +312,12 @@ bool StartupCfgGen::GetHostInfo() object = hostInfo->Lookup("caps", PARSEROP_CONFTERM); GetConfigArray(object, hostData.hostCaps); + GetHostLoadMode(hostInfo, hostData); + + object = hostInfo->Lookup("critical", PARSEROP_CONFTERM); + GetConfigIntArray(object, hostData.hostCritical); + hostData.hostId = hostId; hostInfoMap_.insert(make_pair(serviceName, hostData)); hostId++; diff --git a/framework/tools/hc-gen/src/startup_cfg_gen.h b/framework/tools/hc-gen/src/startup_cfg_gen.h index 4acbf41caa3d69d702f3a79497b679c014781fed..5a0a4dba3dcf2b1bbd05751fc3e520b3973ee123 100644 --- a/framework/tools/hc-gen/src/startup_cfg_gen.h +++ b/framework/tools/hc-gen/src/startup_cfg_gen.h @@ -19,6 +19,7 @@ struct HostInfo { std::string hostCaps; std::string hostUID; std::string hostGID; + std::string hostCritical; uint32_t hostPriority; uint32_t hostId; bool dynamicLoad; @@ -43,7 +44,7 @@ public: private: bool Initialize(); - void InitHostInfo(HostInfo &hostData) const; + static void InitHostInfo(HostInfo &hostData); bool TemplateNodeSeparate(); @@ -57,9 +58,11 @@ private: void HostInfosOutput(); - void GetConfigArray(const std::shared_ptr &term, std::string &config) const; + static void GetConfigArray(const std::shared_ptr &term, std::string &config); - void GetHostLoadMode(const std::shared_ptr &hostInfo, HostInfo &hostData) const; + static void GetConfigIntArray(const std::shared_ptr &term, std::string &config); + + static void GetHostLoadMode(const std::shared_ptr &hostInfo, HostInfo &hostData); void GetHostGID(const std::shared_ptr &term, std::string &config, const std::string &name) const; diff --git a/framework/tools/hc-gen/src/token.cpp b/framework/tools/hc-gen/src/token.cpp index 440cef42f9eb5b225ab3c11826c9f0cf7d14dfaa..3fec2e45d90b369883ead4eb03242a1e85290cd6 100644 --- a/framework/tools/hc-gen/src/token.cpp +++ b/framework/tools/hc-gen/src/token.cpp @@ -54,6 +54,8 @@ std::ostream &OHOS::Hardware::operator<<(std::ostream &stream, const OHOS::Hardw return stream; } +Token::Token() : type(0), strval(), numval(0), src(), lineNo(0) {} + bool Token::operator==(int32_t otherType) const { return otherType == type; @@ -63,12 +65,12 @@ bool Token::operator!=(int32_t otherType) const { return otherType != type; } -bool Token::operator==(Token &token) const +bool Token::operator==(const Token &token) const { return token.type == type && token.numval == numval && token.strval == strval; } -bool Token::operator!=(Token &token) const +bool Token::operator!=(const Token &token) const { return token.type != type || token.numval != numval || token.strval != strval; } diff --git a/framework/tools/hc-gen/src/token.h b/framework/tools/hc-gen/src/token.h index c4a099d15a988d5f50b75d6ee728fd0ef18b2f22..47b5b6083e2b7f8003153695fe2b03af7ade7ed4 100644 --- a/framework/tools/hc-gen/src/token.h +++ b/framework/tools/hc-gen/src/token.h @@ -34,8 +34,10 @@ struct Token { uint64_t numval; std::shared_ptr src; int32_t lineNo; - bool operator==(Token &token) const; - bool operator!=(Token &token) const; + + Token(); + bool operator==(const Token &token) const; + bool operator!=(const Token &token) const; bool operator==(int32_t otherType) const; bool operator!=(int32_t otherType) const; friend std::ostream &operator<<(std::ostream &stream, const Token &token); diff --git a/framework/tools/hcs-view/OWNER b/framework/tools/hcs-view/OWNER index 57330effaea7c55d20442e7fcbc990abc66c3785..eeb03a4745e8aeb333fc5f74ac3d355ca732e237 100644 --- a/framework/tools/hcs-view/OWNER +++ b/framework/tools/hcs-view/OWNER @@ -5,4 +5,5 @@ * the GPL, or the BSD license, at your option. * See the LICENSE file in the root of this repository for complete details. """ + 赵军霞 zhaojunxia@kaihongdigi.com \ No newline at end of file diff --git a/framework/tools/hcs-view/hcsWebView/build.py b/framework/tools/hcs-view/hcsWebView/build.py index 3fb656ae44ab2e212bc0d79393e8f57f4304fc8a..64a5c6004176f3f12ce9f8f92003bbbf6a9186eb 100644 --- a/framework/tools/hcs-view/hcsWebView/build.py +++ b/framework/tools/hcs-view/hcsWebView/build.py @@ -1,7 +1,7 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# Shenzhen Kaihong Digital Industry Development Co., Ltd. +# Copyright (c) 2022 Shenzhen Kaihong Digital Industry Development Co., Ltd. # # HDF is dual licensed: you can use it either under the terms of # the GPL, or the BSD license, at your option. @@ -9,15 +9,16 @@ from asyncio import subprocess -# development production -subprocess.run(["npx", "webpack", "--mode=development"]) -with open(r".\..\hcsVSCode\editor.html", "r", encoding="utf8") as file: - ss = file.read() -i1 = ss.index("// update js code begin") + len("// update js code begin") + 1 -i2 = ss.index("// update js code end") - 1 -with open(r".\dist\main.js", "r", encoding="utf8") as file: - destss = file.read() -ss = ss[:i1] + destss + ss[i2:] -with open(r".\..\hcsVSCode\editor.html", "w", encoding="utf8") as file: - file.write(ss) -print("replaced") +if __name__ == "__main__": + # development production + subprocess.run(["npx", "webpack", "--mode=development"]) + with open(r".\..\hcsVSCode\editor.html", "r", encoding="utf8") as file: + ss = file.read() + i1 = ss.index("// update js code begin") + len("// update js code begin") + 1 + i2 = ss.index("// update js code end") - 1 + with open(r".\dist\main.js", "r", encoding="utf8") as file: + destss = file.read() + ss = ss[:i1] + destss + ss[i2:] + with open(r".\..\hcsVSCode\editor.html", "w", encoding="utf8") as file: + file.write(ss) + print("replaced") diff --git a/framework/tools/hcs-view/hcsWebView/build_plugin.py b/framework/tools/hcs-view/hcsWebView/build_plugin.py index afff66d35fcccb053c726a85067be4bcd9956e2d..73743d40e15f6a0328e14d24981750d8f903b1cb 100644 --- a/framework/tools/hcs-view/hcsWebView/build_plugin.py +++ b/framework/tools/hcs-view/hcsWebView/build_plugin.py @@ -1,7 +1,7 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# Shenzhen Kaihong Digital Industry Development Co., Ltd. +# Copyright (c) 2022 Shenzhen Kaihong Digital Industry Development Co., Ltd. # # HDF is dual licensed: you can use it either under the terms of # the GPL, or the BSD license, at your option. @@ -9,15 +9,16 @@ from asyncio import subprocess -# development production -subprocess.run(["npx", "webpack", "--mode=development"]) -with open(r".\..\hcs_config_plugin\editor.html", "r", encoding="utf8") as file: - ss = file.read() -i1 = ss.index("// update js code begin") + len("// update js code begin") + 1 -i2 = ss.index("// update js code end") - 1 -with open(r".\dist\main.js", "r", encoding="utf8") as file: - destss = file.read() -ss = ss[:i1] + destss + ss[i2:] -with open(r".\..\hcs_config_plugin\editor.html", "w", encoding="utf8") as file: - file.write(ss) -print("replace success") \ No newline at end of file +if __name__ == "__main__": + # development production + subprocess.run(["npx", "webpack", "--mode=development"]) + with open(r".\..\hcs_config_plugin\editor.html", "r", encoding="utf8") as file: + ss = file.read() + i1 = ss.index("// update js code begin") + len("// update js code begin") + 1 + i2 = ss.index("// update js code end") - 1 + with open(r".\dist\main.js", "r", encoding="utf8") as file: + destss = file.read() + ss = ss[:i1] + destss + ss[i2:] + with open(r".\..\hcs_config_plugin\editor.html", "w", encoding="utf8") as file: + file.write(ss) + print("replace success") \ No newline at end of file diff --git a/framework/tools/hcs-view/hcsWebView/src/AttrEditor.js b/framework/tools/hcs-view/hcsWebView/src/AttrEditor.js index 298db421a8a8b67d1d89e3aa1a39a0bfb5bb0912..959c49e7b62c6545376c56670cdd32d07ccf68a3 100644 --- a/framework/tools/hcs-view/hcsWebView/src/AttrEditor.js +++ b/framework/tools/hcs-view/hcsWebView/src/AttrEditor.js @@ -12,6 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + const { AttributeArea } = require("./attr/AttributeArea"); const { ModifyNode } = require("./hcs/ModifyNode"); const { DataType, NodeType } = require("./hcs/NodeTools"); diff --git a/framework/tools/hcs-view/hcsWebView/src/MainEditor.js b/framework/tools/hcs-view/hcsWebView/src/MainEditor.js index 10e3ec1c18bde2efcc4a34b6fabb033f3f883f88..af38be888d1a8b154ba7da092cecbe66993946fb 100644 --- a/framework/tools/hcs-view/hcsWebView/src/MainEditor.js +++ b/framework/tools/hcs-view/hcsWebView/src/MainEditor.js @@ -12,6 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + const { XMessage } = require("./message/XMessage"); const { Lexer } = require("./hcs/lexer"); const { Generator } = require("./hcs/Generator"); diff --git a/framework/tools/hcs-view/hcsWebView/src/attr/AttributeArea.js b/framework/tools/hcs-view/hcsWebView/src/attr/AttributeArea.js index f73c5976195153ef0b79da1bf685809c12c345b1..8ee522275cd73f1ba9e276d0b50af47e3e347429 100644 --- a/framework/tools/hcs-view/hcsWebView/src/attr/AttributeArea.js +++ b/framework/tools/hcs-view/hcsWebView/src/attr/AttributeArea.js @@ -12,6 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + class AttributeArea { constructor() { document.attrCallback = this; diff --git a/framework/tools/hcs-view/hcsWebView/src/engine/XDefine.js b/framework/tools/hcs-view/hcsWebView/src/engine/XDefine.js index cd17e6d5ab40623b61126371b648b56a72a79f29..7d20a46cc777a8fb61f27e47ccfbb81a55a8e13f 100644 --- a/framework/tools/hcs-view/hcsWebView/src/engine/XDefine.js +++ b/framework/tools/hcs-view/hcsWebView/src/engine/XDefine.js @@ -12,6 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + const { NapiLog } = require("./../hcs/NapiLog"); export class Scr { constructor() { diff --git a/framework/tools/hcs-view/hcsWebView/src/engine/XTools.js b/framework/tools/hcs-view/hcsWebView/src/engine/XTools.js index aba4db3684323a1d6e2b93bae7444dd2158abc7b..ba4c7a3272acdf4c75ca91dcee9227dbb53c7212 100644 --- a/framework/tools/hcs-view/hcsWebView/src/engine/XTools.js +++ b/framework/tools/hcs-view/hcsWebView/src/engine/XTools.js @@ -12,6 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + export function fAngle(x,y) { return Math.atan2(-y,x)*180/Math.PI diff --git a/framework/tools/hcs-view/hcsWebView/src/engine/control/XButton.js b/framework/tools/hcs-view/hcsWebView/src/engine/control/XButton.js index 3bf11d86c2dffd9945e02c949eecf1307befeae8..1ade00b16fbd58b5f0907c24d10bf739acf26dcb 100644 --- a/framework/tools/hcs-view/hcsWebView/src/engine/control/XButton.js +++ b/framework/tools/hcs-view/hcsWebView/src/engine/control/XButton.js @@ -12,6 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + const { X2DFast } = require("../graphics/X2DFast") class XButton { diff --git a/framework/tools/hcs-view/hcsWebView/src/engine/control/XSelect.js b/framework/tools/hcs-view/hcsWebView/src/engine/control/XSelect.js index a0912bd1b01f04fa99cbab47e346637ce9ec0974..77a690bfa86f301b98d23078c4e0888671eff79e 100644 --- a/framework/tools/hcs-view/hcsWebView/src/engine/control/XSelect.js +++ b/framework/tools/hcs-view/hcsWebView/src/engine/control/XSelect.js @@ -12,6 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + const { X2DFast } = require("../graphics/X2DFast") class XSelect { diff --git a/framework/tools/hcs-view/hcsWebView/src/engine/graphics/X2DFast.js b/framework/tools/hcs-view/hcsWebView/src/engine/graphics/X2DFast.js index d19ea1fc727894019bff0ee33bc880976711ce71..f9a20fb3ff3e77b359ee8c00f3be761770987d9f 100644 --- a/framework/tools/hcs-view/hcsWebView/src/engine/graphics/X2DFast.js +++ b/framework/tools/hcs-view/hcsWebView/src/engine/graphics/X2DFast.js @@ -12,6 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + import { XMat4 } from "./XMat4.js" import { XShader } from "./XShader.js" import { Scr } from "../XDefine.js" diff --git a/framework/tools/hcs-view/hcsWebView/src/engine/graphics/XMat4.js b/framework/tools/hcs-view/hcsWebView/src/engine/graphics/XMat4.js index f4d33c922cba730fe2ce65fadf18c81f5e4b822e..ace2b3db6d0535f3c629ea31e254e4f6bc96f4ca 100644 --- a/framework/tools/hcs-view/hcsWebView/src/engine/graphics/XMat4.js +++ b/framework/tools/hcs-view/hcsWebView/src/engine/graphics/XMat4.js @@ -12,6 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + export class XMat4 { constructor() diff --git a/framework/tools/hcs-view/hcsWebView/src/engine/graphics/XShader.js b/framework/tools/hcs-view/hcsWebView/src/engine/graphics/XShader.js index 7c606715ba42d34c54ba67ee6bd45de854624c8a..4dcc921ba79873f195f5abdb421ff0d44136ca6a 100644 --- a/framework/tools/hcs-view/hcsWebView/src/engine/graphics/XShader.js +++ b/framework/tools/hcs-view/hcsWebView/src/engine/graphics/XShader.js @@ -12,6 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + const { shaderFastVs, shaderFastFs } = require("./shaders/shader_fast") const { NapiLog } = require("./../../hcs/NapiLog") import { gl } from "../GLFrame.js" diff --git a/framework/tools/hcs-view/hcsWebView/src/engine/graphics/XTexture.js b/framework/tools/hcs-view/hcsWebView/src/engine/graphics/XTexture.js index cc65ea031c88829e23610209b685a31d57c28d64..f079c2986c5a78748bd52b52fa6514b3c923f85f 100644 --- a/framework/tools/hcs-view/hcsWebView/src/engine/graphics/XTexture.js +++ b/framework/tools/hcs-view/hcsWebView/src/engine/graphics/XTexture.js @@ -12,6 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + import { gl } from "../GLFrame.js" export class XTexture { diff --git a/framework/tools/hcs-view/hcsWebView/src/engine/graphics/shaders/shader_fast.js b/framework/tools/hcs-view/hcsWebView/src/engine/graphics/shaders/shader_fast.js index ce35d3167c13f5d5248beea0705ce67ad330d3d2..6f6de5a01f184aea6ecdc712f0af5866d280df81 100644 --- a/framework/tools/hcs-view/hcsWebView/src/engine/graphics/shaders/shader_fast.js +++ b/framework/tools/hcs-view/hcsWebView/src/engine/graphics/shaders/shader_fast.js @@ -12,6 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + var shaderFastVs = ` attribute vec3 position; attribute vec2 aTexCoord; diff --git a/framework/tools/hcs-view/hcsWebView/src/hcs/Generator.js b/framework/tools/hcs-view/hcsWebView/src/hcs/Generator.js index 1558d3a69f4e359252e1f6750b0af9e9d51ba632..32a080370c057cd00341c9f14d7f0f8a76748cb5 100644 --- a/framework/tools/hcs-view/hcsWebView/src/hcs/Generator.js +++ b/framework/tools/hcs-view/hcsWebView/src/hcs/Generator.js @@ -12,6 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + const { NapiLog } = require("./NapiLog"); const { NodeTools } = require("./NodeTools"); const { Parser } = require("./parser"); diff --git a/framework/tools/hcs-view/hcsWebView/src/hcs/ModifyNode.js b/framework/tools/hcs-view/hcsWebView/src/hcs/ModifyNode.js index 7dd929299c7d5c88591fde1a169b4568a4c2a568..3c5b6903221b8223384aba02d4db6e47b84e6800 100644 --- a/framework/tools/hcs-view/hcsWebView/src/hcs/ModifyNode.js +++ b/framework/tools/hcs-view/hcsWebView/src/hcs/ModifyNode.js @@ -12,6 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + const { NapiLog } = require("./NapiLog"); const { NodeTools, DataType, NodeType } = require("./NodeTools"); const re = require("./re") diff --git a/framework/tools/hcs-view/hcsWebView/src/hcs/NodeTools.js b/framework/tools/hcs-view/hcsWebView/src/hcs/NodeTools.js index 47e954176983f9ac0bf87c15700e5322426727ec..6efc456035bb3da0308049fb8144e8bf8d8841b1 100644 --- a/framework/tools/hcs-view/hcsWebView/src/hcs/NodeTools.js +++ b/framework/tools/hcs-view/hcsWebView/src/hcs/NodeTools.js @@ -12,6 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + const { NapiLog } = require("./NapiLog"); const re = require("./re") diff --git a/framework/tools/hcs-view/hcsWebView/src/hcs/ast.js b/framework/tools/hcs-view/hcsWebView/src/hcs/ast.js index 141157ed75f1b1438bf5220a5eb43f48e6d79bd5..a0cd1cf66db1bd5a55b16dff1ff7acb3d6581cf8 100644 --- a/framework/tools/hcs-view/hcsWebView/src/hcs/ast.js +++ b/framework/tools/hcs-view/hcsWebView/src/hcs/ast.js @@ -12,6 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + const { NapiLog } = require("./NapiLog") const { TokenType } = require("./lexer") diff --git a/framework/tools/hcs-view/hcsWebView/src/hcs/lexer.js b/framework/tools/hcs-view/hcsWebView/src/hcs/lexer.js index 93627da446027ac02120a031251d35cac71477ac..6ea7e37717d9085bbff2769bebe46fbb16ca28f6 100644 --- a/framework/tools/hcs-view/hcsWebView/src/hcs/lexer.js +++ b/framework/tools/hcs-view/hcsWebView/src/hcs/lexer.js @@ -12,6 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + const { XMessage } = require("../message/XMessage"); const { NapiLog } = require("./NapiLog") diff --git a/framework/tools/hcs-view/hcsWebView/src/hcs/parser.js b/framework/tools/hcs-view/hcsWebView/src/hcs/parser.js index 11c395dc454bceec5291e5340a14126bd730031a..8e680315aca610a31c8c9d6b827977f10d8cbedf 100644 --- a/framework/tools/hcs-view/hcsWebView/src/hcs/parser.js +++ b/framework/tools/hcs-view/hcsWebView/src/hcs/parser.js @@ -12,6 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + const { NapiLog } = require("./NapiLog") const { Lexer, TokenType, code } = require("./lexer") const { XMessage } = require("../message/XMessage"); diff --git a/framework/tools/hcs-view/hcsWebView/src/index.js b/framework/tools/hcs-view/hcsWebView/src/index.js index ac4a11048b7813dfecef1bff5335a35a8a809c8b..b45eb11e37248eaefe0f509ba0c9d32923380164 100644 --- a/framework/tools/hcs-view/hcsWebView/src/index.js +++ b/framework/tools/hcs-view/hcsWebView/src/index.js @@ -12,6 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + import { Scr } from "./engine/XDefine.js" import { GLFrame } from "./engine/GLFrame.js" import { X2DFast } from "./engine/graphics/X2DFast.js" diff --git a/framework/tools/hcs-view/hcsWebView/src/message/XMessage.js b/framework/tools/hcs-view/hcsWebView/src/message/XMessage.js index d31fcd7d4cea3dad45ff63711329a54b9971db38..ca02237f69ae7615739ab0346d270d94ce315b36 100644 --- a/framework/tools/hcs-view/hcsWebView/src/message/XMessage.js +++ b/framework/tools/hcs-view/hcsWebView/src/message/XMessage.js @@ -12,6 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + const { MockMessage } = require("./mock") const { NapiLog } = require("./../hcs/NapiLog"); diff --git a/framework/tools/hcs-view/hcsWebView/src/message/mock.js b/framework/tools/hcs-view/hcsWebView/src/message/mock.js index 648668646271a7bccfa3674cabc69f2af22ea7e3..e1a5249d7a7573aa11887a9a54e5971f0be3b611 100644 --- a/framework/tools/hcs-view/hcsWebView/src/message/mock.js +++ b/framework/tools/hcs-view/hcsWebView/src/message/mock.js @@ -12,6 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + const { NapiLog } = require("./../hcs/NapiLog"); let mockTest = [{ fn: "D:\\ceshi\\d.hcs", diff --git a/framework/tools/hcs-view/hcsWebView/test/conftest.py b/framework/tools/hcs-view/hcsWebView/test/conftest.py index 0c37ac6a5808e633fcb45f6597f633c820ef1724..6f3f30ee8f10ad893082280d037d7fd8a7aee0fd 100644 --- a/framework/tools/hcs-view/hcsWebView/test/conftest.py +++ b/framework/tools/hcs-view/hcsWebView/test/conftest.py @@ -1,7 +1,7 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# Shenzhen Kaihong Digital Industry Development Co., Ltd. +# Copyright (c) 2022 Shenzhen Kaihong Digital Industry Development Co., Ltd. # # HDF is dual licensed: you can use it either under the terms of # the GPL, or the BSD license, at your option. diff --git a/framework/tools/hcs-view/hcsWebView/test/public_moudle/Base.py b/framework/tools/hcs-view/hcsWebView/test/public_moudle/base.py similarity index 95% rename from framework/tools/hcs-view/hcsWebView/test/public_moudle/Base.py rename to framework/tools/hcs-view/hcsWebView/test/public_moudle/base.py index f24a551920990f93fc1d11ba9b36319720ecbc8e..86364203b5ad6e4d6938f571eb6f685d2246a399 100644 --- a/framework/tools/hcs-view/hcsWebView/test/public_moudle/Base.py +++ b/framework/tools/hcs-view/hcsWebView/test/public_moudle/base.py @@ -1,17 +1,18 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# Shenzhen Kaihong Digital Industry Development Co., Ltd. +# Copyright (c) 2022 Shenzhen Kaihong Digital Industry Development Co., Ltd. # # HDF is dual licensed: you can use it either under the terms of # the GPL, or the BSD license, at your option. # See the LICENSE file in the root of this repository for complete details. from re import finditer +import os import time import easyocr -import os + from PIL import Image from selenium.webdriver.common.keys import Keys from selenium.webdriver.support.wait import WebDriverWait @@ -35,11 +36,12 @@ class Base: return ele # Get URL address - def getfiledir(self): + @staticmethod + def getfiledir(): os.chdir('../../') cur_file = os.getcwd() path = cur_file.replace('\\', '/') - url = 'file:///' + path + '/index.html' + url = "file:///{}/index.html".format(path) os.chdir('test/testsuits') return url @@ -60,7 +62,7 @@ class Base: except BaseException: return "" finally: - return "" + pass def click_canvas_point(self, el, x, y): actions = ActionChains(self.driver) diff --git a/framework/tools/hcs-view/hcsWebView/test/testsuits/test_index.py b/framework/tools/hcs-view/hcsWebView/test/testsuits/test_index.py index d592638afd0c6d23dfcbcb623016f95d688cc20b..81506d540f8a60d4c5579f0e53cf179d3240228c 100644 --- a/framework/tools/hcs-view/hcsWebView/test/testsuits/test_index.py +++ b/framework/tools/hcs-view/hcsWebView/test/testsuits/test_index.py @@ -1,22 +1,24 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# Shenzhen Kaihong Digital Industry Development Co., Ltd. +# Copyright (c) 2022 Shenzhen Kaihong Digital Industry Development Co., Ltd. # # HDF is dual licensed: you can use it either under the terms of # the GPL, or the BSD license, at your option. # See the LICENSE file in the root of this repository for complete details. from asyncio import subprocess -import time import os +import time +import warnings + import easyocr import pytest from PIL import Image from selenium import webdriver from selenium.webdriver import ActionChains -from public_moudle.Base import Base -import warnings + +from public_moudle.base import Base warnings.filterwarnings("ignore", category=UserWarning) @@ -26,8 +28,10 @@ class TestHcsTool: test = Base(driver) url = test.getfiledir() - def setup_class(self): - # Determine whether the index.html file in the local project can be opened and used before executing the use case + @staticmethod + def setup_class(): + # Determine whether the index.html file in the local project + # can be opened and used before executing the use case filelist = os.listdir('../../dist') if len(filelist) < 2: os.chdir('../../') diff --git a/framework/tools/hcs-view/hcsWebView/webpack.config.js b/framework/tools/hcs-view/hcsWebView/webpack.config.js index efc83ba1bfecab589086c46712b117e86c3b3edf..8e0087b86331bb6c4a0d40572cd865a2f0d6ce71 100644 --- a/framework/tools/hcs-view/hcsWebView/webpack.config.js +++ b/framework/tools/hcs-view/hcsWebView/webpack.config.js @@ -12,6 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + module.exports = { devtool: 'source-map', //config debug entry: "./src/index.js", diff --git a/framework/tools/hdf_dbg/BUILD.gn b/framework/tools/hdf_dbg/BUILD.gn index d5a790df984e98aeb33ccf797d06c0b529e6eb57..3bf34fbd0af0c6aebe574280de9df0fa970d0cda 100644 --- a/framework/tools/hdf_dbg/BUILD.gn +++ b/framework/tools/hdf_dbg/BUILD.gn @@ -19,7 +19,7 @@ ohos_executable("hdf_dbg") { ] } - install_enable = true + install_enable = false install_images = [ chipset_base_dir ] subsystem_name = "hdf" part_name = "hdf_core" diff --git a/framework/tools/hdf_dbg/hdf_dbg.cpp b/framework/tools/hdf_dbg/hdf_dbg.cpp index 010c886099aa8807cef70cb91b8f3ecab00f6064..c4662a7feeb1da2b6752b7c6901a5b4cdfa63679 100644 --- a/framework/tools/hdf_dbg/hdf_dbg.cpp +++ b/framework/tools/hdf_dbg/hdf_dbg.cpp @@ -25,6 +25,7 @@ static constexpr uint32_t PARA_CNT_IDX = 6; static constexpr uint32_t PARA_MULTIPLE = 2; static constexpr uint32_t WAIT_TIME = 100; static constexpr uint32_t HELP_INFO_PARA_CNT = 2; +static constexpr uint32_t GET_INFO_FUNC_NUMS = 5; static constexpr int32_t DBG_HDI_PARA_MIN_LEN = 7; static constexpr int32_t DBG_HDI_SERVICE_LOAD_IDX = 2; static constexpr int32_t QUERY_INFO_PARA_CNT = 3; @@ -52,7 +53,7 @@ static void GetAllDeviceUserSpace(); static void GetAllDeviceKernelSpace(); static void GetAllInformation(); -GetInfoFunc g_getInfoFuncs[] = { +GetInfoFunc g_getInfoFuncs[GET_INFO_FUNC_NUMS] = { GetAllServiceKernelSpace, GetAllServiceUserSpace, GetAllDeviceKernelSpace, @@ -389,14 +390,13 @@ int main(int argc, char **argv) return HDF_FAILURE; } - uint32_t funcCnt = sizeof(g_getInfoFuncs) / sizeof(g_getInfoFuncs[0]); if (argc == QUERY_INFO_PARA_CNT - 1) { - g_getInfoFuncs[funcCnt - 1](); + g_getInfoFuncs[GET_INFO_FUNC_NUMS - 1](); return HDF_SUCCESS; } uint32_t queryIdx = static_cast(atoi(argv[QUERY_INFO_PARA_CNT - 1])); - if (queryIdx < funcCnt - 1) { + if (queryIdx < GET_INFO_FUNC_NUMS - 1) { g_getInfoFuncs[queryIdx](); } else { PrintHelp(); diff --git a/framework/tools/hdf_dev_eco_tool/command_line/driver_add/hdf_add_driver.py b/framework/tools/hdf_dev_eco_tool/command_line/driver_add/hdf_add_driver.py index 08c636f5eb05c1100b9ae9bef7d31f77a2488e9a..6b11940e2e6473e9ae10f6f47068b378c333cbec 100644 --- a/framework/tools/hdf_dev_eco_tool/command_line/driver_add/hdf_add_driver.py +++ b/framework/tools/hdf_dev_eco_tool/command_line/driver_add/hdf_add_driver.py @@ -94,7 +94,7 @@ class HdfAddDriver(object): file_lines.append(device_enable) else: file_lines = file_lines_old - file_lines[-1] = file_lines[-1].strip() + "\n" + file_lines[-1] = "{}\n".format(file_lines[-1].strip()) if new_demo_config not in file_lines: file_lines.append(new_demo_config) hdf_utils.write_file_lines(dot_file, file_lines) diff --git a/framework/tools/hdf_dev_eco_tool/command_line/driver_add/linux/mk_file_add_config.py b/framework/tools/hdf_dev_eco_tool/command_line/driver_add/linux/mk_file_add_config.py index bffbfd14d33d3f102b32aa66822cd2590de76774..1455953fdc438b6e8edc53e2195f6adb96d7dcd8 100644 --- a/framework/tools/hdf_dev_eco_tool/command_line/driver_add/linux/mk_file_add_config.py +++ b/framework/tools/hdf_dev_eco_tool/command_line/driver_add/linux/mk_file_add_config.py @@ -44,13 +44,13 @@ def audio_linux_makefile_operation(path, args_tuple): return if len(source_path) > 1: sources_line = "" - obj_first_line = "\nobj-$(CONFIG_DRIVERS_HDF_${model_name_upper}_${driver_name_upper}) += \\"+"\n" + obj_first_line = "\nobj-$(CONFIG_DRIVERS_HDF_${model_name_upper}_${driver_name_upper}) += \\" + "\n" temp_line = "\t\t\t\t$(${file_parent_path})/${source_path}.o" for source in source_path: temp_handle = Template(temp_line.replace("$(", "temp_flag")) temp_dict = analyze_parent_path( date_lines, source, "", devices, root) - temp_dict['source_path'] = temp_dict['source_path'].strip(".c") + temp_dict['source_path'] = temp_dict.get('source_path').strip(".c") if source == source_path[-1]: sources_line += temp_handle.substitute(temp_dict).replace("temp_flag", "$(") + "\n" else: @@ -72,10 +72,9 @@ def audio_linux_makefile_operation(path, args_tuple): date_lines, "", head_file, devices, root) if head_file == head_path[-1]: temp_str = "".join([temp_handle.substitute(temp_dict).replace("temp_flag", "$("), "\n"]) - head_line.append(temp_str) else: temp_str = "".join([temp_handle.substitute(temp_dict).replace("temp_flag", "$("), " \\", "\n"]) - head_line.append(temp_str) + head_line.append(temp_str) build_head = ccflags_first_line + "".join(head_line) makefile_add_template = build_resource + build_head temp_handle = Template(makefile_add_template.replace("$(", "temp_flag")) @@ -124,7 +123,7 @@ def linux_makefile_operation(path, driver_file_path, head_path, module, driver): second_line = " $(${model_name_upper}_ROOT_DIR)/${source_file_path}\n" third_line = "ccflags-y += -I$(srctree)/drivers/hdf/framework/model/${head_file_path}\n" makefile_add_template = first_line + second_line + third_line - include_model_info = model_dir_value.split("model")[-1].strip('"')+"/" + include_model_info = model_dir_value.split("model")[-1].strip('"') + "/" makefile_path_config = source_file_path.split(include_model_info) temp_handle = Template(makefile_add_template.replace("$(", "temp_flag")) temp_replace = { diff --git a/framework/tools/hdf_dev_eco_tool/command_line/driver_add/liteos/gn_file_add_config.py b/framework/tools/hdf_dev_eco_tool/command_line/driver_add/liteos/gn_file_add_config.py index 27fb032ade517b0a11d119e8bd820a22b714bc79..fe7da8f7293e384a2d85080309c02374ede0bbb0 100644 --- a/framework/tools/hdf_dev_eco_tool/command_line/driver_add/liteos/gn_file_add_config.py +++ b/framework/tools/hdf_dev_eco_tool/command_line/driver_add/liteos/gn_file_add_config.py @@ -51,7 +51,7 @@ def audio_build_file_operation(path, args_tuple): third_line = ' include_dirs += [ "$${file_parent_path}/${head_path}" ]\n' four_line = " }\n" if len(source_path) > 1: - sources_line = "" + sources_line = [] multi_resource = " sources += [ \n" multi_end = " ]\n" temp_line = r' "$${file_parent_path}/${source_path}",' @@ -59,9 +59,10 @@ def audio_build_file_operation(path, args_tuple): temp_handle = Template(temp_line.replace("\"$", "temp_flag")) parent_temp_dict = analyze_parent_path( date_lines, source, "", devices, root) - sources_line += temp_handle.substitute( - parent_temp_dict).replace("temp_flag", "\"$") + "\n" - build_resource = multi_resource + sources_line + multi_end + sources_line.append(temp_handle.substitute( + parent_temp_dict).replace("temp_flag", "\"$") + "\n") + sources_str = ''.join(sources_line) + build_resource = ''.join([multi_resource, sources_str, multi_end]) else: build_resource = ' sources += [ "$${file_parent_path}/${source_path}" ]\n' for source in source_path: @@ -70,7 +71,7 @@ def audio_build_file_operation(path, args_tuple): date_lines, source, "", devices, root) build_resource = temp_handle.substitute( temp_dict).replace("temp_flag", "\"$") - build_add_template = first_line + build_resource + third_line + four_line + build_add_template = ''.join([first_line, build_resource, third_line, four_line]) build_replace_dict = analyze_parent_path( date_lines, "", head_path[0], devices, root, kernel_type=kernel) temp_handle = Template(build_add_template.replace("\"$", "temp_flag")) @@ -167,7 +168,7 @@ def build_file_operation(path, driver_file_path, head_path, module, driver): result_tuple = find_build_file_end_index(date_lines, model_name=module) end_index, frameworks_name, frameworks_value = result_tuple build_add_template = template_str_splice(type_name="framework") - include_model_info = frameworks_value.split("model")[-1].strip('"')+"/" + include_model_info = frameworks_value.split("model")[-1].strip('"') + "/" build_gn_path_config = source_file_path.split(include_model_info) temp_handle = Template( build_add_template.replace("$FRAMEWORKS", "FRAMEWORKS")) @@ -187,7 +188,7 @@ def build_file_operation(path, driver_file_path, head_path, module, driver): end_index, frameworks_name, frameworks_value = result_tuple build_add_template = template_str_splice(type_name=" ") include_model_info = frameworks_value.split("/")[-1].strip("\"") - build_gn_path_config = source_file_path.split(include_model_info+"/", 1) + build_gn_path_config = source_file_path.split(include_model_info + "/", 1) temp_handle = Template( build_add_template.replace("$PERIPHERAL", "PERIPHERAL")) @@ -203,7 +204,7 @@ def build_file_operation(path, driver_file_path, head_path, module, driver): new_line = temp_handle.substitute( temp_replace).replace("PERIPHERAL", "$PERIPHERAL") - date_lines = date_lines[:end_index]+[new_line]+date_lines[end_index:] + date_lines = date_lines[:end_index] + [new_line] + date_lines[end_index:] hdf_utils.write_file_lines(build_gn_path, date_lines) diff --git a/framework/tools/hdf_dev_eco_tool/command_line/driver_add/liteos/mk_file_add_config.py b/framework/tools/hdf_dev_eco_tool/command_line/driver_add/liteos/mk_file_add_config.py index af63524bbc8857d84d8a62c23f2b09ff6025961e..c665b482300121c1bcb1280c15ff30f3d874bf74 100644 --- a/framework/tools/hdf_dev_eco_tool/command_line/driver_add/liteos/mk_file_add_config.py +++ b/framework/tools/hdf_dev_eco_tool/command_line/driver_add/liteos/mk_file_add_config.py @@ -51,7 +51,7 @@ def audio_makefile_file_operation(path, args_tuple): four_line = "endif\n" if len(source_path) > 1: - sources_line = "" + sources_line_items = [] multi_resource = "LOCAL_SRCS += " temp_line = r'$(${file_parent_path})/${source_path}' for source in source_path: @@ -59,10 +59,13 @@ def audio_makefile_file_operation(path, args_tuple): temp_dict = analyze_parent_path( date_lines, source, "", devices, root) if source == source_path[-1]: - sources_line += len(multi_resource)*" " + temp_handle.substitute(temp_dict).replace("temp_flag", "$(")+"\n" + sources_line_items.append(len(multi_resource) * " ") + sources_line_items.append(temp_handle.substitute(temp_dict).replace("temp_flag", "$(")) + sources_line_items.append("\n") else: - sources_line += temp_handle.substitute(temp_dict).replace("temp_flag", "$(")+" \\"+"\n" - build_resource = multi_resource + sources_line + sources_line_items.append(temp_handle.substitute(temp_dict).replace("temp_flag", "$(")) + sources_line_items.append(" \\\n") + build_resource = "{}{}".format(multi_resource, "".join(sources_line_items)) else: build_resource = "LOCAL_SRCS += $(${file_parent_path})/${source_path}\n" for source in source_path: @@ -70,7 +73,7 @@ def audio_makefile_file_operation(path, args_tuple): temp_dict = analyze_parent_path( date_lines, source, "", devices, root) build_resource = temp_handle.substitute(temp_dict).replace("temp_flag", "$(") - makefile_add_template = first_line + build_resource + third_line + four_line + makefile_add_template = "{}{}{}{}".format(first_line, build_resource, third_line, four_line) makefile_replace_dict = analyze_parent_path( date_lines, "", head_path[0], devices, root, kernel_type=kernel) temp_handle = Template(makefile_add_template.replace("$(", "temp_flag")) @@ -80,7 +83,7 @@ def audio_makefile_file_operation(path, args_tuple): } makefile_replace_dict.update(model_dict) new_line = temp_handle.substitute(makefile_replace_dict).replace("temp_flag", "$(") - date_lines = date_lines[:end_index-1] + [new_line] + date_lines[end_index-1:] + date_lines = date_lines[:end_index - 1] + [new_line] + date_lines[end_index - 1:] hdf_utils.write_file_lines(makefile_gn_path, date_lines) diff --git a/framework/tools/hdf_dev_eco_tool/command_line/hdf_add_handler.py b/framework/tools/hdf_dev_eco_tool/command_line/hdf_add_handler.py index fc42e0a0d2e0bdd754e60ad535eac693c473dbb1..cbc5e47533499deda69636d30ce3b89f9c13d4bf 100644 --- a/framework/tools/hdf_dev_eco_tool/command_line/hdf_add_handler.py +++ b/framework/tools/hdf_dev_eco_tool/command_line/hdf_add_handler.py @@ -224,7 +224,7 @@ class HdfAddHandler(HdfCommandHandlerBase): {"module_upper_case": converter.upper_case()}) for dot_file in dot_file_list: file_lines = hdf_utils.read_file_lines(dot_file) - file_lines[-1] = file_lines[-1].strip() + "\n" + file_lines[-1] = "{}\n".format(file_lines[-1].strip()) if new_demo_config != file_lines[-1]: file_lines.append(new_demo_config) hdf_utils.write_file_lines(dot_file, file_lines) @@ -299,7 +299,7 @@ class HdfAddHandler(HdfCommandHandlerBase): else: driver_file_name = "//" + user_file_path.replace("\\", "/") data_model = { - "model_path": "//drivers/hdf_core/adapter/uhdf2/" + module, + "model_path": os.path.join("//drivers/hdf_core/adapter/uhdf2/", module), "driver_file_name": driver_file_name, "model_name": module, } diff --git a/framework/tools/hdf_dev_eco_tool/command_line/hdf_command_handler_base.py b/framework/tools/hdf_dev_eco_tool/command_line/hdf_command_handler_base.py index 4b4e239f6421d2432c0acde58238051472b8cb3f..ff71de5b5782662165140df2f8c9f48e9e7e959b 100644 --- a/framework/tools/hdf_dev_eco_tool/command_line/hdf_command_handler_base.py +++ b/framework/tools/hdf_dev_eco_tool/command_line/hdf_command_handler_base.py @@ -73,7 +73,7 @@ class HdfCommandHandlerBase(object): if arg == "runmode": value = self._get_arg(arg) if value: - board_index = args.index('board_name')+1 + board_index = args.index('board_name') + 1 ret[board_index] = '_'.join([ret[board_index], value]) else: res_value = self.board_args_format_operation(arg) diff --git a/framework/tools/hdf_dev_eco_tool/command_line/hdf_device_info_hcs.py b/framework/tools/hdf_dev_eco_tool/command_line/hdf_device_info_hcs.py index 0446685673f051e51e08ef7ae30110f36d7e71d7..b5890c5aababa790b23eb9346d28849c804ae0b1 100644 --- a/framework/tools/hdf_dev_eco_tool/command_line/hdf_device_info_hcs.py +++ b/framework/tools/hdf_dev_eco_tool/command_line/hdf_device_info_hcs.py @@ -101,7 +101,7 @@ class HdfDeviceInfoHcsFile(object): 'User_device_info_hcs.template') lines = list(map(lambda x: "\t\t" + x, hdf_utils.read_file_lines(template_path))) - lines[-1] = "\t\t"+lines[-1].strip()+"\n" + lines[-1] = "\t\t" + lines[-1].strip() + "\n" old_lines = list(filter(lambda x: x != "\n", hdf_utils.read_file_lines(self.hcspath))) diff --git a/framework/tools/hdf_dev_eco_tool/command_line/hdf_get_handler.py b/framework/tools/hdf_dev_eco_tool/command_line/hdf_get_handler.py index a5cc8f6ee18117e3b1d9f07602af9b23d3af3b19..669d5c08cbae1b09777ca9b16287aa60314c0023 100644 --- a/framework/tools/hdf_dev_eco_tool/command_line/hdf_get_handler.py +++ b/framework/tools/hdf_dev_eco_tool/command_line/hdf_get_handler.py @@ -2,12 +2,11 @@ # -*- coding: utf-8 -*- # Copyright (c) 2020-2021 Huawei Device Co., Ltd. -# +# # HDF is dual licensed: you can use it either under the terms of # the GPL, or the BSD license, at your option. # See the LICENSE file in the root of this repository for complete details. - import os import json @@ -16,6 +15,7 @@ import hdf_tool_version from command_line.hdf_command_error_code import CommandErrorCode from hdf_tool_settings import HdfToolSettings from hdf_tool_exception import HdfToolException +from hdf_tool_version import GetToolVersion from .hdf_command_handler_base import HdfCommandHandlerBase from .hdf_linux_scann import HdfLinuxScan from .hdf_lite_mk_file import HdfLiteMkFile @@ -26,9 +26,6 @@ from .hdf_driver_config_file import HdfDriverConfigFile class HdfGetHandler(HdfCommandHandlerBase): - HDF_VERSION_MAJOR = 0 - HDF_VERSION_MINOR = 1 - def __init__(self, args): super(HdfGetHandler, self).__init__() self.cmd = 'get' @@ -165,8 +162,7 @@ class HdfGetHandler(HdfCommandHandlerBase): def __get_version(self): version_end = "\nCopyright (c) 2020-2021 Huawei Device Co., Ltd." version_head = "hdf_dev_eco_tool version : " - return version_head + str(self.HDF_VERSION_MAJOR) \ - + "." + str(self.HDF_VERSION_MINOR) + version_end + return version_head + GetToolVersion().get_version() + version_end def _mode_scan(self): self.check_arg_raise_if_not_exist("root_dir") diff --git a/framework/tools/hdf_dev_eco_tool/command_line/hdf_liteos_scann.py b/framework/tools/hdf_dev_eco_tool/command_line/hdf_liteos_scann.py index 434314dffd5059da3eb986c8c14e2585cff75e6c..a0cb59a86f3c91337e8eb6bb501eb18746589aac 100644 --- a/framework/tools/hdf_dev_eco_tool/command_line/hdf_liteos_scann.py +++ b/framework/tools/hdf_dev_eco_tool/command_line/hdf_liteos_scann.py @@ -79,7 +79,7 @@ class HdfLiteScan(object): end_index = index + 1 model_list = [] - for i in self.contents[start_index+1: end_index-1]: + for i in self.contents[start_index + 1: end_index - 1]: model_name = re.compile(self.re_temp_model).match(i.strip()) if model_name: model_list.append(i.strip()) diff --git a/framework/tools/hdf_dev_eco_tool/command_line/hdf_vendor_kconfig_file.py b/framework/tools/hdf_dev_eco_tool/command_line/hdf_vendor_kconfig_file.py index 895fa6caf55a61841eb2130d9a8b30e021a17fba..9370d0829a885768919e87d23ab42432106cb625 100644 --- a/framework/tools/hdf_dev_eco_tool/command_line/hdf_vendor_kconfig_file.py +++ b/framework/tools/hdf_dev_eco_tool/command_line/hdf_vendor_kconfig_file.py @@ -68,7 +68,7 @@ class HdfVendorKconfigFile(object): def add_module(self, module_to_k_path_parts): module_k_part = '/'.join(module_to_k_path_parts) - index, line = self._find_line("model/"+module_k_part) + index, line = self._find_line("model/" + module_k_part) if line: return line = '\n%s/%s"\n' % (self.line_prefix, module_k_part) diff --git a/framework/tools/hdf_dev_eco_tool/hdf_tool_version.py b/framework/tools/hdf_dev_eco_tool/hdf_tool_version.py index 862fcd5029325ed5cd10236ccf175a0caf6622af..52b04228907713a2c6220e7e089371883032a7c5 100644 --- a/framework/tools/hdf_dev_eco_tool/hdf_tool_version.py +++ b/framework/tools/hdf_dev_eco_tool/hdf_tool_version.py @@ -7,9 +7,10 @@ # the GPL, or the BSD license, at your option. # See the LICENSE file in the root of this repository for complete details. +class GetToolVersion(object): + def __init__(self): + self.hdf_version_major = 0 + self.hdf_version_minor = 1 -HDF_TOOL_VERSION = '1.0.0' - - -def get_version(): - return HDF_TOOL_VERSION + def get_version(self): + return "{}.{}".format(self.hdf_version_major, self.hdf_version_minor) diff --git a/framework/tools/hdf_dev_eco_tool/hdf_utils.py b/framework/tools/hdf_dev_eco_tool/hdf_utils.py index 5ab73a62a0d7c0e50222ba80621765fc4aaaf8ac..e29c016019e5963536fce2269d088ceb303ba59a 100644 --- a/framework/tools/hdf_dev_eco_tool/hdf_utils.py +++ b/framework/tools/hdf_dev_eco_tool/hdf_utils.py @@ -355,13 +355,24 @@ def template_filename_filtrate(dir_path, kernal): return filename_list -def model_info(path_dict, root, model_file_path, key): - if isinstance(path_dict, dict): - for k_filename, file_path in path_dict.items(): - if not os.path.exists(os.path.join(root, file_path)): +def type_judge(file_path, root, model_file_path, k_filename, path_dict): + if isinstance(file_path, list): + for file_name in file_path: + if not os.path.exists(os.path.join(root, file_name)): model_file_path[k_filename] = " " else: model_file_path[k_filename] = path_dict[k_filename] + else: + if not os.path.exists(os.path.join(root, file_path)): + model_file_path[k_filename] = " " + else: + model_file_path[k_filename] = path_dict[k_filename] + + +def model_info(path_dict, root, model_file_path, key): + if isinstance(path_dict, dict): + for k_filename, file_path in path_dict.items(): + type_judge(file_path, root, model_file_path, k_filename, path_dict) else: hcs_file_path = os.path.join(root, path_dict) if not os.path.exists(hcs_file_path): @@ -402,7 +413,7 @@ def judge_file_path_exists(temp_path): def write_config(root_path, config_file_json, config_name): if platform.system() == "Windows": config_file_replace = json.dumps(config_file_json, indent=4). \ - replace(root_path.replace('\\', '\\\\') + '\\\\', "") + replace("{}\\\\".format(root_path.replace('\\', '\\\\')), "") write_file(os.path.join('resources', config_name), config_file_replace.replace('\\\\', '/')) if platform.system() == "Linux": @@ -433,13 +444,13 @@ def ini_file_write_operation(model, operation_object, model_child_dir_list): def judge_enable_line(enable_line, device_base): if isinstance(enable_line, bytes): if enable_line.find((device_base + " ").encode("utf-8")) == -1 and \ - enable_line.find((device_base+"=").encode("utf-8")) == -1: + enable_line.find((device_base + "=").encode("utf-8")) == -1: return enable_line else: if enable_line.find(device_base + " ") == -1 and \ - enable_line.find(device_base+"=") == -1: + enable_line.find(device_base + "=") == -1: return enable_line def get_passwd_group_path(root_path): - return os.path.join(root_path, "base", "startup", "init_lite", "services", "etc") + return os.path.join(root_path, "base", "startup", "init", "services", "etc") diff --git a/framework/tools/hdf_dev_eco_tool/main.py b/framework/tools/hdf_dev_eco_tool/main.py index 041d32d924c57a4f1cd8312e3b8e18a1b6039fea..059f0bc40d48ed854bdec8bec365cf2ca190acf8 100644 --- a/framework/tools/hdf_dev_eco_tool/main.py +++ b/framework/tools/hdf_dev_eco_tool/main.py @@ -24,6 +24,7 @@ def check_python_version(): def main(): + sys.path.append("..") check_python_version() commands = HdfToolCommands() help_info = 'Tools backend for hdf driver development.' diff --git a/framework/tools/hdi-gen/Makefile b/framework/tools/hdi-gen/Makefile index 8ee6d4b8272f0edef35d55834a6d971bec5151e2..437bd00b5ec509a4147ec17dd2f8748c468fdbf7 100644 --- a/framework/tools/hdi-gen/Makefile +++ b/framework/tools/hdi-gen/Makefile @@ -16,7 +16,7 @@ else export TARGET:=$(TARGET_DIR)/hdi-gen endif -export CXXFLAGS = -std=c++14 -O2 -Wall -fno-common -fno-strict-aliasing +export CXXFLAGS = -std=c++14 -O2 -Wall -fno-common -fno-strict-aliasing -s export Q := @ export MAKEFLAGS += --no-print-directory diff --git a/framework/tools/hdi-gen/MakefileLinux b/framework/tools/hdi-gen/MakefileLinux index 5a0380658b105a8274fc5e004ee19496886c3603..9fca0a33c795e80479f2d2463bd5d5d2e58da2c9 100644 --- a/framework/tools/hdi-gen/MakefileLinux +++ b/framework/tools/hdi-gen/MakefileLinux @@ -46,6 +46,7 @@ MAIN_SOURCE := $(wildcard *.cpp) MAIN_OBJS := $(addprefix $(BUILD_DIR)/, $(patsubst %.cpp, %.o, $(MAIN_SOURCE))) all:$(TARGET) + $(TARGET) : $(BOUNDS_CHECK_OBJS) $(UTIL_OBJS) $(AST_OBJS) $(LEXER_OBJS) $(PREPROCESSOR_OBJS) $(PARSER_OBJS) $(CODEGEN_OBJS) $(MAIN_OBJS) $(Q) $(CXX) $(CXXFLAGS) $(INCLUDES) $^ -o $@ $(Q) echo $(TARGET):build successful. diff --git a/framework/tools/hdi-gen/MakefileWin b/framework/tools/hdi-gen/MakefileWin index 713bca6fc88b463035e9a9b805facf8dd5f724fb..2949f9b70f9ed4c4538f9a3171cc2ea2bccbc753 100644 --- a/framework/tools/hdi-gen/MakefileWin +++ b/framework/tools/hdi-gen/MakefileWin @@ -46,6 +46,7 @@ MAIN_SOURCE:=$(wildcard *.cpp) MAIN_OBJS:=$(addprefix $(BUILD_DIR)\, $(patsubst %.cpp, %.o, $(MAIN_SOURCE))) all : $(TARGET) + $(TARGET) : $(BOUNDS_CHECK_OBJS) $(UTIL_OBJS) $(AST_OBJS) $(LEXER_OBJS) $(PREPROCESSOR_OBJS) $(PARSER_OBJS) $(CODEGEN_OBJS) $(MAIN_OBJS) $(Q) $(CXX) $(CXXFLAGS) $(INCLUDES) $^ -o $@ $(Q) echo $(TARGET):build successful. diff --git a/framework/tools/hdi-gen/ast/ast_attribute.cpp b/framework/tools/hdi-gen/ast/ast_attribute.cpp index 79e66eff15d1a78b5766de7f1a7ef77077e8c85e..f9e864c7c775081d7276a096b81351217ab87ce7 100644 --- a/framework/tools/hdi-gen/ast/ast_attribute.cpp +++ b/framework/tools/hdi-gen/ast/ast_attribute.cpp @@ -11,7 +11,7 @@ namespace OHOS { namespace HDI { -static void AttributesFormat(StringBuilder &sb, const std::vector attrs) +static void AttributesFormat(StringBuilder &sb, const std::vector &attrs) { if (attrs.empty()) { return; diff --git a/framework/tools/hdi-gen/ast/ast_namespace.cpp b/framework/tools/hdi-gen/ast/ast_namespace.cpp index bc28a517420cb187fea9fb2f69d980d7629472bb..d17e0d1dc2743d423362ad1e57d2f593a40408e8 100644 --- a/framework/tools/hdi-gen/ast/ast_namespace.cpp +++ b/framework/tools/hdi-gen/ast/ast_namespace.cpp @@ -7,6 +7,9 @@ */ #include "ast/ast_namespace.h" + +#include + #include "ast/ast_interface_type.h" #include "ast/ast_sequenceable_type.h" @@ -30,12 +33,11 @@ AutoPtr ASTNamespace::FindNamespace(const std::string &nspaceStr) return nullptr; } - for (auto nspace : innerNamespaces_) { - if (nspace->name_ == nspaceStr) { - return nspace; - } - } - return nullptr; + auto resIter = std::find_if( + innerNamespaces_.begin(), innerNamespaces_.end(), [nspaceStr](const AutoPtr &element) { + return element->name_ == nspaceStr; + }); + return resIter != innerNamespaces_.end() ? *resIter : nullptr; } AutoPtr ASTNamespace::GetNamespace(size_t index) diff --git a/framework/tools/hdi-gen/codegen/c_client_proxy_code_emitter.cpp b/framework/tools/hdi-gen/codegen/c_client_proxy_code_emitter.cpp index 8474027366f80b0bdde4b25141824e8e4199b3e2..bd8bfca0fe9e66ed43c6a2770884525312295b7c 100644 --- a/framework/tools/hdi-gen/codegen/c_client_proxy_code_emitter.cpp +++ b/framework/tools/hdi-gen/codegen/c_client_proxy_code_emitter.cpp @@ -461,7 +461,8 @@ void CClientProxyCodeEmitter::EmitKernelProxyGetMethodImpl(StringBuilder &sb) { sb.AppendFormat("struct %s *%sGet()\n", interfaceName_.c_str(), interfaceName_.c_str()); sb.Append("{\n"); - sb.Append(TAB).AppendFormat("return %sGetInstance(\"%s\");\n", interfaceName_.c_str(), FileName(implName_).c_str()); + sb.Append(TAB).AppendFormat("return %sGetInstance(\"%s\");\n", interfaceName_.c_str(), + FileName(implName_).c_str()); sb.Append("}\n"); } @@ -575,7 +576,7 @@ void CClientProxyCodeEmitter::EmitProxyGetInstanceMethodImpl(const std::string & sb.AppendFormat("struct %s *%sGetInstance(const char *%s, bool isStub)\n", interfaceName_.c_str(), interfaceName_.c_str(), serviceName.c_str()); sb.Append("{\n"); - EmitProxyLoadHdiImpl(serviceName, sb, TAB); + EmitProxyLoadOrUnLoadHdiImpl(serviceName, true, sb, TAB); sb.Append("\n"); EmitProxyGetRemoteService(remoteName, serviceName, sb, TAB); sb.Append("\n"); @@ -589,21 +590,6 @@ void CClientProxyCodeEmitter::EmitProxyGetInstanceMethodImpl(const std::string & sb.Append("}\n"); } -void CClientProxyCodeEmitter::EmitProxyLoadHdiImpl(const std::string &serviceName, StringBuilder &sb, - const std::string &prefix) -{ - std::string instName = "instName"; - sb.Append(prefix).Append("if (isStub) {\n"); - sb.Append(prefix + TAB).AppendFormat("const char *%s = %s;\n", instName.c_str(), serviceName.c_str()); - sb.Append(prefix + TAB) - .AppendFormat("if (strcmp(%s, \"%s\") == 0) {\n", instName.c_str(), FileName(implName_).c_str()); - sb.Append(prefix + TAB + TAB).AppendFormat("%s = \"service\";\n", instName.c_str()); - sb.Append(prefix + TAB).Append("}\n"); - sb.Append(prefix + TAB) - .AppendFormat("return LoadHdiImpl(%s, %s);\n", interface_->EmitDescMacroName().c_str(), instName.c_str()); - sb.Append(prefix).Append("}\n"); -} - void CClientProxyCodeEmitter::EmitProxyGetRemoteService( const std::string &remoteName, const std::string &serviceName, StringBuilder &sb, const std::string &prefix) { @@ -714,7 +700,7 @@ void CClientProxyCodeEmitter::EmitProxyReleaseInstanceMethodImpl(const std::stri sb.Append(TAB).Append("if (instance == NULL) {\n"); sb.Append(TAB).Append(TAB).Append("return;\n"); sb.Append(TAB).Append("}\n\n"); - EmitProxyUnLoadHdiImpl(serviceName, sb, TAB); + EmitProxyLoadOrUnLoadHdiImpl(serviceName, false, sb, TAB); sb.Append("\n"); sb.Append(TAB).AppendFormat("struct %sProxy *proxy = CONTAINER_OF(instance, struct %sProxy, impl);\n", baseName_.c_str(), baseName_.c_str()); @@ -723,8 +709,8 @@ void CClientProxyCodeEmitter::EmitProxyReleaseInstanceMethodImpl(const std::stri sb.Append("}\n"); } -void CClientProxyCodeEmitter::EmitProxyUnLoadHdiImpl(const std::string &serviceName, StringBuilder &sb, - const std::string &prefix) +void CClientProxyCodeEmitter::EmitProxyLoadOrUnLoadHdiImpl(const std::string &serviceName, bool isLoad, + StringBuilder &sb, const std::string &prefix) { std::string instName = "instName"; sb.Append(prefix).Append("if (isStub) {\n"); @@ -733,9 +719,14 @@ void CClientProxyCodeEmitter::EmitProxyUnLoadHdiImpl(const std::string &serviceN .AppendFormat("if (strcmp(%s, \"%s\") == 0) {\n", instName.c_str(), FileName(implName_).c_str()); sb.Append(prefix + TAB + TAB).AppendFormat("%s = \"service\";\n", instName.c_str()); sb.Append(prefix + TAB).Append("}\n"); - sb.Append(prefix + TAB) - .AppendFormat("UnloadHdiImpl(%s, %s, instance);\n", interface_->EmitDescMacroName().c_str(), instName.c_str()); - sb.Append(prefix + TAB).Append("return;\n"); + if (isLoad) { + sb.Append(prefix + TAB).AppendFormat("return LoadHdiImpl(%s, %s);\n", + interface_->EmitDescMacroName().c_str(), instName.c_str()); + } else { + sb.Append(prefix + TAB).AppendFormat("UnloadHdiImpl(%s, %s, instance);\n", + interface_->EmitDescMacroName().c_str(), instName.c_str()); + sb.Append(prefix + TAB).Append("return;\n"); + } sb.Append(prefix).Append("}\n"); } diff --git a/framework/tools/hdi-gen/codegen/c_client_proxy_code_emitter.h b/framework/tools/hdi-gen/codegen/c_client_proxy_code_emitter.h index 5f06ba3832afee9dd87d350070a9463a8f91cb84..b0d097132c7f7db635d3a1fce0e3675b1707b054 100644 --- a/framework/tools/hdi-gen/codegen/c_client_proxy_code_emitter.h +++ b/framework/tools/hdi-gen/codegen/c_client_proxy_code_emitter.h @@ -95,8 +95,6 @@ private: const std::string &serMinorName, const std::string &remoteName, const std::string &serviceName, StringBuilder &sb); - void EmitProxyLoadHdiImpl(const std::string &serviceName, StringBuilder &sb, const std::string &prefix); - void EmitProxyGetRemoteService( const std::string &remoteName, const std::string &serviceName, StringBuilder &sb, const std::string &prefix); @@ -115,7 +113,8 @@ private: void EmitProxyReleaseInstanceMethodImpl(const std::string &serviceName, const std::string &remoteName, const std::string &recycleFuncName, StringBuilder &sb); - void EmitProxyUnLoadHdiImpl(const std::string &serviceName, StringBuilder &sb, const std::string &prefix); + void EmitProxyLoadOrUnLoadHdiImpl(const std::string &serviceName, bool isLoad, StringBuilder &sb, + const std::string &prefix); void GetUtilMethods(UtilMethodMap &methods) override; diff --git a/framework/tools/hdi-gen/codegen/c_code_emitter.cpp b/framework/tools/hdi-gen/codegen/c_code_emitter.cpp index 1100b31aaebe960f20bd2f48e9f7d22e9cc176d6..ceb9b3ad2eb2c7c5523709b6d09752c2fdce44c2 100644 --- a/framework/tools/hdi-gen/codegen/c_code_emitter.cpp +++ b/framework/tools/hdi-gen/codegen/c_code_emitter.cpp @@ -23,7 +23,6 @@ void CCodeEmitter::GetImportInclusions(HeaderFile::HeaderFileSet &headerFiles) void CCodeEmitter::EmitInterfaceMethodParameter( const AutoPtr ¶meter, StringBuilder &sb, const std::string &prefix) { - AutoPtr type = parameter->GetType(); sb.Append(prefix).Append(parameter->EmitCParameter()); } diff --git a/framework/tools/hdi-gen/codegen/c_custom_types_code_emitter.cpp b/framework/tools/hdi-gen/codegen/c_custom_types_code_emitter.cpp index 7548b7ad8eb2154167716c99c684c68791cdf4ad..bcdc24cb30e5c04a13876693647c0b462f4a5016 100644 --- a/framework/tools/hdi-gen/codegen/c_custom_types_code_emitter.cpp +++ b/framework/tools/hdi-gen/codegen/c_custom_types_code_emitter.cpp @@ -231,7 +231,8 @@ void CCustomTypesCodeEmitter::EmitCustomTypeMarshallingImpl(StringBuilder &sb, c type->EmitCType().c_str(), objName.c_str()); sb.Append("{\n"); EmitMarshallingVarDecl(type, objName, sb, TAB); - EmitMarshallingParamCheck(objName, sb, TAB); + EmitParamCheck(objName, sb, TAB); + sb.Append("\n"); if (type->IsPod()) { if (Options::GetInstance().DoGenerateKernelCode()) { sb.Append(TAB).AppendFormat("if (!HdfSbufWriteBuffer(data, (const void *)%s, sizeof(%s))) {\n", @@ -265,7 +266,8 @@ void CCustomTypesCodeEmitter::EmitCustomTypeUnmarshallingImpl(StringBuilder &sb, type->EmitCType().c_str(), objName.c_str()); sb.Append("{\n"); EmitUnmarshallingVarDecl(type, objName, sb, TAB); - EmitUnmarshallingParamCheck(objName, sb, TAB); + EmitParamCheck(objName, sb, TAB); + sb.Append("\n"); if (type->IsPod()) { EmitPodTypeUnmarshalling(type, objName, sb, TAB); } else { @@ -317,22 +319,16 @@ void CCustomTypesCodeEmitter::EmitUnmarshallingVarDecl( } } -void CCustomTypesCodeEmitter::EmitMarshallingParamCheck( - const std::string &name, StringBuilder &sb, const std::string &prefix) +void CCustomTypesCodeEmitter::EmitParamCheck(const std::string &name, StringBuilder &sb, const std::string &prefix) { - sb.Append(prefix).AppendFormat("if (data == NULL || %s == NULL) {\n", name.c_str()); - sb.Append(prefix + TAB).Append("HDF_LOGE(\"%{public}s: invalid sbuf or data block\", __func__);\n"); + sb.Append(prefix).Append("if (data == NULL) {\n"); + sb.Append(prefix + TAB).Append("HDF_LOGE(\"%{public}s: invalid sbuf\", __func__);\n"); sb.Append(prefix + TAB).Append("return false;\n"); sb.Append(prefix).Append("}\n\n"); -} - -void CCustomTypesCodeEmitter::EmitUnmarshallingParamCheck( - const std::string &name, StringBuilder &sb, const std::string &prefix) -{ - sb.Append(prefix).AppendFormat("if (data == NULL || %s == NULL) {\n", name.c_str()); - sb.Append(prefix + TAB).Append("HDF_LOGE(\"%{public}s: invalid sbuf or data block\", __func__);\n"); - sb.Append(prefix + TAB).AppendFormat("goto %s;\n", errorsLabelName_); - sb.Append(prefix).Append("}\n\n"); + sb.Append(prefix).AppendFormat("if (%s == NULL) {\n", name.c_str()); + sb.Append(prefix + TAB).Append("HDF_LOGE(\"%{public}s: invalid data block\", __func__);\n"); + sb.Append(prefix + TAB).Append("return false;\n"); + sb.Append(prefix).Append("}\n"); } void CCustomTypesCodeEmitter::EmitPodTypeUnmarshalling( diff --git a/framework/tools/hdi-gen/codegen/c_custom_types_code_emitter.h b/framework/tools/hdi-gen/codegen/c_custom_types_code_emitter.h index 2dbdf5bb63be1a088d8a393b62e05ffff18e3baa..0aad6feebbb39f7d3f23388f3e21214fa95d57be 100644 --- a/framework/tools/hdi-gen/codegen/c_custom_types_code_emitter.h +++ b/framework/tools/hdi-gen/codegen/c_custom_types_code_emitter.h @@ -62,9 +62,7 @@ private: void EmitUnmarshallingVarDecl( const AutoPtr &type, const std::string &name, StringBuilder &sb, const std::string &prefix); - void EmitMarshallingParamCheck(const std::string &name, StringBuilder &sb, const std::string &prefix); - - void EmitUnmarshallingParamCheck(const std::string &name, StringBuilder &sb, const std::string &prefix); + void EmitParamCheck(const std::string &name, StringBuilder &sb, const std::string &prefix); void EmitPodTypeUnmarshalling( const AutoPtr &type, const std::string &name, StringBuilder &sb, const std::string &prefix); diff --git a/framework/tools/hdi-gen/codegen/c_service_driver_code_emitter.cpp b/framework/tools/hdi-gen/codegen/c_service_driver_code_emitter.cpp index 39c41d0e714ab61f67389ce9f1f6826509a3085a..6700859e9c25f7e84612f59f6f4b66c912a9d873 100644 --- a/framework/tools/hdi-gen/codegen/c_service_driver_code_emitter.cpp +++ b/framework/tools/hdi-gen/codegen/c_service_driver_code_emitter.cpp @@ -13,6 +13,11 @@ namespace OHOS { namespace HDI { +CServiceDriverCodeEmitter::CServiceDriverCodeEmitter() : CCodeEmitter() +{ + hostName_ = StringHelper::StrToLower(baseName_) + "Host"; +} + bool CServiceDriverCodeEmitter::ResolveDirectory(const std::string &targetDirectory) { if (ast_->GetASTFileType() != ASTFileType::AST_IFACE) { @@ -121,39 +126,37 @@ void CServiceDriverCodeEmitter::EmitDriverServiceDecl(StringBuilder &sb) void CServiceDriverCodeEmitter::EmitKernelDriverDispatch(StringBuilder &sb) { - std::string hostName = StringHelper::StrToLower(baseName_) + "Host"; sb.AppendFormat( "static int32_t %sDriverDispatch(struct HdfDeviceIoClient *client, int cmdId,\n", baseName_.c_str()); sb.Append(TAB).Append("struct HdfSBuf *data, struct HdfSBuf *reply)\n"); sb.Append("{\n"); - sb.Append(TAB).AppendFormat("struct Hdf%sHost *%s = CONTAINER_OF(\n", baseName_.c_str(), hostName.c_str()); + sb.Append(TAB).AppendFormat("struct Hdf%sHost *%s = CONTAINER_OF(\n", baseName_.c_str(), hostName_.c_str()); sb.Append(TAB).Append(TAB).AppendFormat( "client->device->service, struct Hdf%sHost, ioService);\n", baseName_.c_str()); sb.Append(TAB).AppendFormat("if (%s->service == NULL || %s->service->stub.OnRemoteRequest == NULL) {\n", - hostName.c_str(), hostName.c_str()); + hostName_.c_str(), hostName_.c_str()); sb.Append(TAB).Append(TAB).Append("HDF_LOGE(\"%{public}s: invalid service obj\", __func__);\n"); sb.Append(TAB).Append(TAB).Append("return HDF_ERR_INVALID_OBJECT;\n"); sb.Append(TAB).Append("}\n\n"); - sb.Append(TAB).AppendFormat("return %s->service->stub.OnRemoteRequest(", hostName.c_str()); - sb.AppendFormat("&%s->service->stub.interface, cmdId, data, reply);\n", hostName.c_str()); + sb.Append(TAB).AppendFormat("return %s->service->stub.OnRemoteRequest(", hostName_.c_str()); + sb.AppendFormat("&%s->service->stub.interface, cmdId, data, reply);\n", hostName_.c_str()); sb.Append("}\n"); } void CServiceDriverCodeEmitter::EmitDriverDispatch(StringBuilder &sb) { - std::string hostName = StringHelper::StrToLower(baseName_) + "Host"; sb.AppendFormat( "static int32_t %sDriverDispatch(struct HdfDeviceIoClient *client, int cmdId,\n", baseName_.c_str()); sb.Append(TAB).Append("struct HdfSBuf *data, struct HdfSBuf *reply)\n"); sb.Append("{\n"); - sb.Append(TAB).AppendFormat("struct Hdf%sHost *%s = CONTAINER_OF(", baseName_.c_str(), hostName.c_str()); + sb.Append(TAB).AppendFormat("struct Hdf%sHost *%s = CONTAINER_OF(", baseName_.c_str(), hostName_.c_str()); sb.AppendFormat("client->device->service, struct Hdf%sHost, ioService);\n", baseName_.c_str()); sb.Append(TAB).AppendFormat("if (%s->service == NULL || %s->stubObject == NULL) {\n", - hostName.c_str(), hostName.c_str()); + hostName_.c_str(), hostName_.c_str()); sb.Append(TAB).Append(TAB).Append("HDF_LOGE(\"%{public}s: invalid service obj\", __func__);\n"); sb.Append(TAB).Append(TAB).Append("return HDF_ERR_INVALID_OBJECT;\n"); sb.Append(TAB).Append("}\n\n"); - sb.Append(TAB).AppendFormat("struct HdfRemoteService *stubObj = *%s->stubObject;\n", hostName.c_str()); + sb.Append(TAB).AppendFormat("struct HdfRemoteService *stubObj = *%s->stubObject;\n", hostName_.c_str()); sb.Append(TAB).AppendFormat("if (stubObj == NULL || stubObj->dispatcher == NULL || "); sb.Append("stubObj->dispatcher->Dispatch == NULL) {\n"); sb.Append(TAB).Append(TAB).Append("return HDF_ERR_INVALID_OBJECT;\n"); @@ -167,132 +170,125 @@ void CServiceDriverCodeEmitter::EmitDriverInit(StringBuilder &sb) { sb.AppendFormat("static int Hdf%sDriverInit(struct HdfDeviceObject *deviceObject)\n", baseName_.c_str()); sb.Append("{\n"); - sb.Append(TAB).AppendFormat("HDF_LOGI(\"Hdf%sDriverInit enter.\");\n", baseName_.c_str()); + sb.Append(TAB).Append("HDF_LOGI(\"%{public}s: driver init start\", __func__);\n"); sb.Append(TAB).Append("return HDF_SUCCESS;\n"); sb.Append("}\n"); } void CServiceDriverCodeEmitter::EmitKernelDriverBind(StringBuilder &sb) { - std::string hostName = StringHelper::StrToLower(baseName_) + "Host"; sb.AppendFormat("static int Hdf%sDriverBind(struct HdfDeviceObject *deviceObject)\n", baseName_.c_str()); sb.Append("{\n"); - sb.Append(TAB).AppendFormat("HDF_LOGI(\"Hdf%sDriverBind enter.\");\n", baseName_.c_str()); + sb.Append(TAB).Append("HDF_LOGI(\"%{public}s: driver bind start\", __func__);\n"); sb.Append("\n"); sb.Append(TAB).AppendFormat("struct Hdf%sHost *%s = (struct Hdf%sHost *)OsalMemAlloc(", baseName_.c_str(), - hostName.c_str(), baseName_.c_str()); + hostName_.c_str(), baseName_.c_str()); sb.AppendFormat("sizeof(struct Hdf%sHost));\n", baseName_.c_str()); - sb.Append(TAB).AppendFormat("if (%s == NULL) {\n", hostName.c_str()); + sb.Append(TAB).AppendFormat("if (%s == NULL) {\n", hostName_.c_str()); sb.Append(TAB).Append(TAB).AppendFormat( "HDF_LOGE(\"Hdf%sDriverBind create Hdf%sHost object failed!\");\n", baseName_.c_str(), baseName_.c_str()); sb.Append(TAB).Append(TAB).Append("return HDF_FAILURE;\n"); sb.Append(TAB).Append("}\n"); sb.Append("\n"); - sb.Append(TAB).AppendFormat("%s->ioService.Dispatch = %sDriverDispatch;\n", hostName.c_str(), baseName_.c_str()); - sb.Append(TAB).AppendFormat("%s->ioService.Open = NULL;\n", hostName.c_str()); - sb.Append(TAB).AppendFormat("%s->ioService.Release = NULL;\n", hostName.c_str()); - sb.Append(TAB).AppendFormat("%s->service = %sServiceGet();\n", hostName.c_str(), baseName_.c_str()); - sb.Append(TAB).AppendFormat("if (%s->service == NULL) {\n", hostName.c_str()); - sb.Append(TAB).Append(TAB).AppendFormat("OsalMemFree(%s);\n", hostName.c_str()); + sb.Append(TAB).AppendFormat("%s->ioService.Dispatch = %sDriverDispatch;\n", hostName_.c_str(), baseName_.c_str()); + sb.Append(TAB).AppendFormat("%s->ioService.Open = NULL;\n", hostName_.c_str()); + sb.Append(TAB).AppendFormat("%s->ioService.Release = NULL;\n", hostName_.c_str()); + sb.Append(TAB).AppendFormat("%s->service = %sServiceGet();\n", hostName_.c_str(), baseName_.c_str()); + sb.Append(TAB).AppendFormat("if (%s->service == NULL) {\n", hostName_.c_str()); + sb.Append(TAB).Append(TAB).AppendFormat("OsalMemFree(%s);\n", hostName_.c_str()); + sb.Append(TAB).Append(TAB).Append("HDF_LOGE(\"%{public}s: failed to get service object\", __func__);\n"); sb.Append(TAB).Append(TAB).Append("return HDF_FAILURE;\n"); sb.Append(TAB).Append("}\n"); sb.Append("\n"); - sb.Append(TAB).AppendFormat("deviceObject->service = &%s->ioService;\n", hostName.c_str()); + sb.Append(TAB).AppendFormat("deviceObject->service = &%s->ioService;\n", hostName_.c_str()); sb.Append(TAB).Append("return HDF_SUCCESS;\n"); sb.Append("}\n"); } void CServiceDriverCodeEmitter::EmitDriverBind(StringBuilder &sb) { - std::string hostName = StringHelper::StrToLower(baseName_) + "Host"; sb.AppendFormat("static int Hdf%sDriverBind(struct HdfDeviceObject *deviceObject)\n", baseName_.c_str()); sb.Append("{\n"); - sb.Append(TAB).AppendFormat("HDF_LOGI(\"Hdf%sDriverBind enter.\");\n", baseName_.c_str()); - sb.Append("\n"); + sb.Append(TAB).Append("HDF_LOGI(\"%{public}s: driver bind start\", __func__);\n"); sb.Append(TAB).AppendFormat("int32_t ret = HdfDeviceObjectSetInterfaceDesc(deviceObject, %s);\n", interface_->EmitDescMacroName().c_str()); sb.Append(TAB).Append("if (ret != HDF_SUCCESS) {\n"); - sb.Append(TAB).Append(TAB).Append("HDF_LOGE(\"failed to set interface descriptor of device object\");\n"); + sb.Append(TAB).Append(TAB).Append( + "HDF_LOGE(\"%{public}s: failed to set interface descriptor of device object\", __func__);\n"); sb.Append(TAB).Append(TAB).Append("return ret;\n"); sb.Append(TAB).Append("}\n\n"); sb.Append(TAB).AppendFormat("struct Hdf%sHost *%s = (struct Hdf%sHost *)OsalMemAlloc(", baseName_.c_str(), - hostName.c_str(), baseName_.c_str()); + hostName_.c_str(), baseName_.c_str()); sb.AppendFormat("sizeof(struct Hdf%sHost));\n", baseName_.c_str()); - sb.Append(TAB).AppendFormat("if (%s == NULL) {\n", hostName.c_str()); - sb.Append(TAB).Append(TAB).AppendFormat( - "HDF_LOGE(\"Hdf%sDriverBind create Hdf%sHost object failed!\");\n", baseName_.c_str(), baseName_.c_str()); + sb.Append(TAB).AppendFormat("if (%s == NULL) {\n", hostName_.c_str()); + sb.Append(TAB).Append(TAB).AppendFormat("HDF_LOGE(\"%%{public}s: create Hdf%sHost object failed!\", __func__);\n", + baseName_.c_str()); sb.Append(TAB).Append(TAB).Append("return HDF_FAILURE;\n"); sb.Append(TAB).Append("}\n\n"); sb.Append(TAB).AppendFormat("struct %s *serviceImpl = %sGet(true);\n", interfaceName_.c_str(), interfaceName_.c_str()); sb.Append(TAB).Append("if (serviceImpl == NULL) {\n"); - sb.Append(TAB).Append(TAB).AppendFormat("HDF_LOGE(\"Hdf%sDriverBind create serviceImpl failed!\");\n", - baseName_.c_str()); - sb.Append(TAB).Append(TAB).AppendFormat("OsalMemFree(%s);\n", hostName.c_str()); + sb.Append(TAB).Append(TAB).Append("HDF_LOGE(\"%{public}s: create serviceImpl failed!\", __func__);\n"); + sb.Append(TAB).Append(TAB).AppendFormat("OsalMemFree(%s);\n", hostName_.c_str()); sb.Append(TAB).Append(TAB).Append("return HDF_FAILURE;\n"); sb.Append(TAB).Append("}\n\n"); - sb.Append(TAB).Append(TAB).AppendFormat("HDF_LOGE(\"Hdf%sDriverBind create stub object failed!\");\n", - baseName_.c_str()); sb.Append(TAB).AppendFormat("struct HdfRemoteService **stubObj = StubCollectorGetOrNewObject("); sb.AppendFormat("%s, serviceImpl);\n", interface_->EmitDescMacroName().c_str()); sb.Append(TAB).Append("if (stubObj == NULL) {\n"); - sb.Append(TAB).Append(TAB).AppendFormat("OsalMemFree(%s);\n", hostName.c_str()); - sb.Append(TAB).Append(TAB).AppendFormat("%sRelease(true, serviceImpl);\n", interfaceName_.c_str()); + sb.Append(TAB).Append(TAB).Append("HDF_LOGE(\"%{public}s: failed to get stub object\", __func__);\n"); + sb.Append(TAB).Append(TAB).AppendFormat("OsalMemFree(%s);\n", hostName_.c_str()); + sb.Append(TAB).Append(TAB).AppendFormat("%sRelease(serviceImpl, true);\n", interfaceName_.c_str()); sb.Append(TAB).Append(TAB).Append("return HDF_FAILURE;\n"); sb.Append(TAB).Append("}\n\n"); - sb.Append(TAB).AppendFormat("%s->ioService.Dispatch = %sDriverDispatch;\n", hostName.c_str(), baseName_.c_str()); - sb.Append(TAB).AppendFormat("%s->ioService.Open = NULL;\n", hostName.c_str()); - sb.Append(TAB).AppendFormat("%s->ioService.Release = NULL;\n", hostName.c_str()); - sb.Append(TAB).AppendFormat("%s->service = serviceImpl;\n", hostName.c_str()); - sb.Append(TAB).AppendFormat("%s->stubObject = stubObj;\n", hostName.c_str()); - sb.Append(TAB).AppendFormat("deviceObject->service = &%s->ioService;\n", hostName.c_str()); + sb.Append(TAB).AppendFormat("%s->ioService.Dispatch = %sDriverDispatch;\n", hostName_.c_str(), baseName_.c_str()); + sb.Append(TAB).AppendFormat("%s->ioService.Open = NULL;\n", hostName_.c_str()); + sb.Append(TAB).AppendFormat("%s->ioService.Release = NULL;\n", hostName_.c_str()); + sb.Append(TAB).AppendFormat("%s->service = serviceImpl;\n", hostName_.c_str()); + sb.Append(TAB).AppendFormat("%s->stubObject = stubObj;\n", hostName_.c_str()); + sb.Append(TAB).AppendFormat("deviceObject->service = &%s->ioService;\n", hostName_.c_str()); sb.Append(TAB).Append("return HDF_SUCCESS;\n"); sb.Append("}\n"); } void CServiceDriverCodeEmitter::EmitKernelDriverRelease(StringBuilder &sb) { - std::string hostName = StringHelper::StrToLower(baseName_) + "Host"; sb.AppendFormat("static void Hdf%sDriverRelease(struct HdfDeviceObject *deviceObject)\n", baseName_.c_str()); sb.Append("{\n"); sb.Append(TAB).AppendFormat("HDF_LOGI(\"Hdf%sDriverRelease enter.\");\n", baseName_.c_str()); - sb.Append(TAB).Append("if (deviceObject->service != NULL) {\n"); + sb.Append(TAB).Append("HDF_LOGI(\"%{public}s: driver release start\", __func__);\n"); sb.Append(TAB).Append(TAB).Append("return;\n"); sb.Append(TAB).Append("}\n\n"); - sb.Append(TAB).AppendFormat("struct Hdf%sHost *%s = CONTAINER_OF(", baseName_.c_str(), hostName.c_str()); + sb.Append(TAB).AppendFormat("struct Hdf%sHost *%s = CONTAINER_OF(", baseName_.c_str(), hostName_.c_str()); sb.AppendFormat("deviceObject->service, struct Hdf%sHost, ioService);\n", baseName_.c_str()); - sb.Append(TAB).AppendFormat("if (%s == NULL) {\n", hostName.c_str()); - sb.Append(TAB).Append(TAB).Append("return;\n"); - sb.Append(TAB).Append("}\n\n"); - sb.Append(TAB).AppendFormat("%sServiceRelease(%s->service);\n", baseName_.c_str(), hostName.c_str()); - sb.Append(TAB).AppendFormat("OsalMemFree(%s);\n", hostName.c_str()); + sb.Append(TAB).AppendFormat("if (%s != NULL) {\n", hostName_.c_str()); + sb.Append(TAB).Append(TAB).AppendFormat("%sServiceRelease(%s->service);\n", baseName_.c_str(), hostName_.c_str()); + sb.Append(TAB).Append(TAB).AppendFormat("OsalMemFree(%s);\n", hostName_.c_str()); + sb.Append(TAB).Append("}\n"); sb.Append("}\n"); } void CServiceDriverCodeEmitter::EmitDriverRelease(StringBuilder &sb) { - std::string hostName = StringHelper::StrToLower(baseName_) + "Host"; sb.AppendFormat("static void Hdf%sDriverRelease(struct HdfDeviceObject *deviceObject)\n", baseName_.c_str()); sb.Append("{\n"); - sb.Append(TAB).AppendFormat("HDF_LOGI(\"Hdf%sDriverRelease enter.\");\n", baseName_.c_str()); + sb.Append(TAB).Append("HDF_LOGI(\"%{public}s: driver release start\", __func__);\n"); - sb.Append(TAB).Append("if (deviceObject->service != NULL) {\n"); + sb.Append(TAB).Append("if (deviceObject->service == NULL) {\n"); sb.Append(TAB).Append(TAB).Append("return;\n"); sb.Append(TAB).Append("}\n\n"); - sb.Append(TAB).AppendFormat("struct Hdf%sHost *%s = CONTAINER_OF(", baseName_.c_str(), hostName.c_str()); + sb.Append(TAB).AppendFormat("struct Hdf%sHost *%s = CONTAINER_OF(", baseName_.c_str(), hostName_.c_str()); sb.AppendFormat("deviceObject->service, struct Hdf%sHost, ioService);\n", baseName_.c_str()); - sb.Append(TAB).AppendFormat("if (%s == NULL) {\n", hostName.c_str()); - sb.Append(TAB).Append(TAB).Append("return;\n"); - sb.Append(TAB).Append("}\n\n"); - - sb.Append(TAB).AppendFormat("StubCollectorRemoveObject(%s, %s->service);\n", - interface_->EmitDescMacroName().c_str(), hostName.c_str()); - sb.Append(TAB).AppendFormat("%sRelease(%s->service, true);\n", interfaceName_.c_str(), hostName.c_str()); - sb.Append(TAB).AppendFormat("OsalMemFree(%s);\n", hostName.c_str()); + sb.Append(TAB).AppendFormat("if (%s != NULL) {\n", hostName_.c_str()); + sb.Append(TAB).Append(TAB).AppendFormat("StubCollectorRemoveObject(%s, %s->service);\n", + interface_->EmitDescMacroName().c_str(), hostName_.c_str()); + sb.Append(TAB).Append(TAB).AppendFormat("%sRelease(%s->service, true);\n", interfaceName_.c_str(), + hostName_.c_str()); + sb.Append(TAB).Append(TAB).AppendFormat("OsalMemFree(%s);\n", hostName_.c_str()); + sb.Append(TAB).Append("}\n"); sb.Append("}\n"); } @@ -305,7 +301,7 @@ void CServiceDriverCodeEmitter::EmitDriverEntryDefinition(StringBuilder &sb) sb.Append(TAB).AppendFormat(".Init = Hdf%sDriverInit,\n", baseName_.c_str()); sb.Append(TAB).AppendFormat(".Release = Hdf%sDriverRelease,\n", baseName_.c_str()); sb.Append("};\n\n"); - sb.AppendFormat("HDF_INIT(g_%sDriverEntry);", StringHelper::StrToLower(baseName_).c_str()); + sb.AppendFormat("HDF_INIT(g_%sDriverEntry);\n", StringHelper::StrToLower(baseName_).c_str()); } } // namespace HDI } // namespace OHOS \ No newline at end of file diff --git a/framework/tools/hdi-gen/codegen/c_service_driver_code_emitter.h b/framework/tools/hdi-gen/codegen/c_service_driver_code_emitter.h index 481c0443b50daaaf3e681dec6e61e3166296b97d..f267ce6420bc11b05bb58a40d26bc9186f81494d 100644 --- a/framework/tools/hdi-gen/codegen/c_service_driver_code_emitter.h +++ b/framework/tools/hdi-gen/codegen/c_service_driver_code_emitter.h @@ -15,7 +15,7 @@ namespace OHOS { namespace HDI { class CServiceDriverCodeEmitter : public CCodeEmitter { public: - CServiceDriverCodeEmitter() : CCodeEmitter() {} + CServiceDriverCodeEmitter(); virtual ~CServiceDriverCodeEmitter() = default; @@ -47,6 +47,8 @@ private: void EmitDriverRelease(StringBuilder &sb); void EmitDriverEntryDefinition(StringBuilder &sb); +private: + std::string hostName_; }; } // namespace HDI } // namespace OHOS diff --git a/framework/tools/hdi-gen/codegen/c_service_impl_code_emitter.cpp b/framework/tools/hdi-gen/codegen/c_service_impl_code_emitter.cpp index d89f34c72d580a6f8f8d1fb9292be773ff9222a9..57c50a6fda057f6867d995cce524eac14646e1b7 100644 --- a/framework/tools/hdi-gen/codegen/c_service_impl_code_emitter.cpp +++ b/framework/tools/hdi-gen/codegen/c_service_impl_code_emitter.cpp @@ -269,7 +269,6 @@ void CServiceImplCodeEmitter::EmitKernelServiceImplReleaseMethod(StringBuilder & { std::string implTypeName = StringHelper::Format("%sService", baseName_.c_str()); std::string instName = "instance"; - std::string objName = "service"; sb.AppendFormat( "void %sRelease(struct %s *%s)\n", implTypeName.c_str(), implTypeName.c_str(), instName.c_str()); sb.Append("{\n"); diff --git a/framework/tools/hdi-gen/codegen/c_service_stub_code_emitter.cpp b/framework/tools/hdi-gen/codegen/c_service_stub_code_emitter.cpp index 16a11c8411109cfe055b144877ec25ae71b5edce..08c01a440cdbfe3fb8a1e75951685822583a1f0c 100644 --- a/framework/tools/hdi-gen/codegen/c_service_stub_code_emitter.cpp +++ b/framework/tools/hdi-gen/codegen/c_service_stub_code_emitter.cpp @@ -585,7 +585,6 @@ void CServiceStubCodeEmitter::EmitKernelStubConstruct(StringBuilder &sb) void CServiceStubCodeEmitter::EmitStubOnRequestMethodImpl(StringBuilder &sb, const std::string &prefix) { std::string remoteName = "remote"; - std::string implName = "serviceImpl"; std::string codeName = "code"; std::string funcName = StringHelper::Format("%sOnRemoteRequest", baseName_.c_str()); sb.Append(prefix).AppendFormat("static int32_t %s(struct HdfRemoteService *%s, ", funcName.c_str(), diff --git a/framework/tools/hdi-gen/codegen/cpp_service_driver_code_emitter.cpp b/framework/tools/hdi-gen/codegen/cpp_service_driver_code_emitter.cpp index 29924d756e8bdf35dff49a447f80ff08954ab896..9a8dc0f775fde67a18ea0682c27775764f137390 100644 --- a/framework/tools/hdi-gen/codegen/cpp_service_driver_code_emitter.cpp +++ b/framework/tools/hdi-gen/codegen/cpp_service_driver_code_emitter.cpp @@ -112,11 +112,11 @@ void CppServiceDriverCodeEmitter::EmitDriverDispatch(StringBuilder &sb) sb.Append(TAB).Append("OHOS::MessageOption option;\n\n"); sb.Append(TAB).Append("if (SbufToParcel(data, &dataParcel) != HDF_SUCCESS) {\n"); - sb.Append(TAB).Append(TAB).Append("HDF_LOGE(\"%{public}s:invalid data sbuf object to dispatch\", __func__);\n"); + sb.Append(TAB).Append(TAB).Append("HDF_LOGE(\"%{public}s: invalid data sbuf object to dispatch\", __func__);\n"); sb.Append(TAB).Append(TAB).Append("return HDF_ERR_INVALID_PARAM;\n"); sb.Append(TAB).Append("}\n"); sb.Append(TAB).Append("if (SbufToParcel(reply, &replyParcel) != HDF_SUCCESS) {\n"); - sb.Append(TAB).Append(TAB).Append("HDF_LOGE(\"%{public}s:invalid reply sbuf object to dispatch\", __func__);\n"); + sb.Append(TAB).Append(TAB).Append("HDF_LOGE(\"%{public}s: invalid reply sbuf object to dispatch\", __func__);\n"); sb.Append(TAB).Append(TAB).Append("return HDF_ERR_INVALID_PARAM;\n"); sb.Append(TAB).Append("}\n\n"); @@ -129,7 +129,7 @@ void CppServiceDriverCodeEmitter::EmitDriverInit(StringBuilder &sb) { sb.AppendFormat("static int Hdf%sDriverInit(struct HdfDeviceObject *deviceObject)\n", baseName_.c_str()); sb.Append("{\n"); - sb.Append(TAB).AppendFormat("HDF_LOGI(\"Hdf%sDriverInit enter\");\n", baseName_.c_str()); + sb.Append(TAB).Append("HDF_LOGI(\"%{public}s: driver init start\", __func__);\n"); sb.Append(TAB).Append("return HDF_SUCCESS;\n"); sb.Append("}\n"); } @@ -139,7 +139,7 @@ void CppServiceDriverCodeEmitter::EmitDriverBind(StringBuilder &sb) std::string objName = StringHelper::Format("hdf%sHost", baseName_.c_str()); sb.AppendFormat("static int Hdf%sDriverBind(struct HdfDeviceObject *deviceObject)\n", baseName_.c_str()); sb.Append("{\n"); - sb.Append(TAB).AppendFormat("HDF_LOGI(\"Hdf%sDriverBind enter\");\n\n", baseName_.c_str()); + sb.Append(TAB).Append("HDF_LOGI(\"%{public}s: driver bind start\", __func__);\n"); sb.Append(TAB).AppendFormat("auto *%s = new (std::nothrow) Hdf%sHost;\n", objName.c_str(), baseName_.c_str()); sb.Append(TAB).AppendFormat("if (%s == nullptr) {\n", objName.c_str()); @@ -176,16 +176,17 @@ void CppServiceDriverCodeEmitter::EmitDriverBind(StringBuilder &sb) void CppServiceDriverCodeEmitter::EmitDriverRelease(StringBuilder &sb) { std::string objName = StringHelper::Format("hdf%sHost", baseName_.c_str()); - sb.AppendFormat("static void Hdf%sDriverRelease(struct HdfDeviceObject *deviceObject)", baseName_.c_str()); + sb.AppendFormat("static void Hdf%sDriverRelease(struct HdfDeviceObject *deviceObject)\n", baseName_.c_str()); sb.Append("{\n"); - sb.Append(TAB).AppendFormat("HDF_LOGI(\"Hdf%sDriverRelease enter\");\n", baseName_.c_str()); + sb.Append(TAB).Append("HDF_LOGI(\"%{public}s: driver release start\", __func__);\n"); sb.Append(TAB).AppendFormat("if (deviceObject->service == nullptr) {\n"); - sb.Append(TAB).Append(TAB).AppendFormat("HDF_LOGE(\"Hdf%sDriverRelease not initted\");\n", baseName_.c_str()); sb.Append(TAB).Append(TAB).AppendFormat("return;\n"); sb.Append(TAB).Append("}\n\n"); sb.Append(TAB).AppendFormat("auto *%s = CONTAINER_OF(", objName.c_str()); sb.AppendFormat("deviceObject->service, struct Hdf%sHost, ioService);\n", baseName_.c_str()); - sb.Append(TAB).AppendFormat("delete %s;\n", objName.c_str()); + sb.Append(TAB).AppendFormat("if (%s != nullptr) {\n", objName.c_str()); + sb.Append(TAB).Append(TAB).AppendFormat("delete %s;\n", objName.c_str()); + sb.Append(TAB).Append("}\n"); sb.Append("}\n"); } @@ -197,8 +198,7 @@ void CppServiceDriverCodeEmitter::EmitDriverEntryDefinition(StringBuilder &sb) sb.Append(TAB).AppendFormat(".Bind = Hdf%sDriverBind,\n", baseName_.c_str()); sb.Append(TAB).AppendFormat(".Init = Hdf%sDriverInit,\n", baseName_.c_str()); sb.Append(TAB).AppendFormat(".Release = Hdf%sDriverRelease,\n", baseName_.c_str()); - sb.Append("};\n"); - sb.Append("\n"); + sb.Append("};\n\n"); EmitHeadExternC(sb); sb.AppendFormat("HDF_INIT(g_%sDriverEntry);\n", StringHelper::StrToLower(baseName_).c_str()); EmitTailExternC(sb); diff --git a/framework/tools/hdi-gen/lexer/lexer.cpp b/framework/tools/hdi-gen/lexer/lexer.cpp index ba10d42ab41afc3e6af58c1b55df8b3b5dcb7b2b..bb1e9c59f3be5364d721ab404a4fc1cc07223e7c 100644 --- a/framework/tools/hdi-gen/lexer/lexer.cpp +++ b/framework/tools/hdi-gen/lexer/lexer.cpp @@ -172,12 +172,11 @@ void Lexer::SkipEof() void Lexer::ReadToken(Token &token, bool skipComment) { - char c = 0; if (!file_->IsEof()) { InitCurToken(token); } while (!file_->IsEof()) { - c = file_->PeekChar(); + char c = file_->PeekChar(); if (isspace(c)) { file_->GetChar(); continue; @@ -287,7 +286,7 @@ void Lexer::ReadBinaryNum(Token &token) bool err = true; while (!file_->IsEof()) { - char c = file_->PeekChar(); + c = file_->PeekChar(); if (c == '0' || c == '1') { sb.Append(c); file_->GetChar(); diff --git a/framework/tools/hdi-gen/lexer/token.cpp b/framework/tools/hdi-gen/lexer/token.cpp index bc41d5c63a8c80924e9cd0c18fc314df5affc459..8a79864c5eab32efd19a4e7c75512e986282b392 100644 --- a/framework/tools/hdi-gen/lexer/token.cpp +++ b/framework/tools/hdi-gen/lexer/token.cpp @@ -32,78 +32,5 @@ std::string LocInfo(const Token &token) (index == std::string::npos) ? token.location_.filePath_ : token.location_.filePath_.substr(index + 1); return StringHelper::Format("%s:%u:%u", fileName.c_str(), token.location_.row_, token.location_.col_); } - -std::string TokenTypeToString(TokenType type) -{ - static std::unordered_map tokenStrMap = { - {TokenType::BOOLEAN, "boolean" }, - {TokenType::BYTE, "byte" }, - {TokenType::SHORT, "short" }, - {TokenType::INT, "int" }, - {TokenType::LONG, "long" }, - {TokenType::STRING, "String" }, - {TokenType::FLOAT, "float" }, - {TokenType::DOUBLE, "double" }, - {TokenType::FD, "FileDescriptor"}, - {TokenType::ASHMEM, "Ashmem" }, - {TokenType::BUFFER_HANDLE, "BufferHandle" }, - {TokenType::LIST, "List" }, - {TokenType::MAP, "Map" }, - {TokenType::SMQ, "SharedMemQueue"}, - {TokenType::CHAR, "char" }, - {TokenType::UNSIGNED, "unsigned" }, - {TokenType::ENUM, "enum" }, - {TokenType::STRUCT, "struct" }, - {TokenType::UNION, "union" }, - {TokenType::PACKAGE, "package" }, - {TokenType::SEQ, "sequenceable" }, - {TokenType::IMPORT, "import" }, - {TokenType::INTERFACE, "interface" }, - {TokenType::EXTENDS, "extends" }, - {TokenType::ONEWAY, "oneway" }, - {TokenType::CALLBACK, "callback" }, - {TokenType::FULL, "full" }, - {TokenType::LITE, "lite" }, - {TokenType::IN, "in" }, - {TokenType::OUT, "out" }, - {TokenType::DOT, "." }, - {TokenType::COMMA, "," }, - {TokenType::COLON, ":" }, - {TokenType::ASSIGN, "=" }, - {TokenType::SEMICOLON, ";" }, - {TokenType::BRACES_LEFT, "{" }, - {TokenType::BRACES_RIGHT, "}" }, - {TokenType::BRACKETS_LEFT, "[" }, - {TokenType::BRACKETS_RIGHT, "]" }, - {TokenType::PARENTHESES_LEFT, "(" }, - {TokenType::PARENTHESES_RIGHT, ")" }, - {TokenType::ANGLE_BRACKETS_LEFT, "<" }, - {TokenType::ANGLE_BRACKETS_RIGHT, ">" }, - }; - auto it = tokenStrMap.find(type); - return (it != tokenStrMap.end()) ? it->second : ""; -} - -int TokenTypeToChar(TokenType type) -{ - static std::unordered_map tokenCharMap = { - {TokenType::DOT, '.'}, - {TokenType::COMMA, '.'}, - {TokenType::COLON, ':'}, - {TokenType::ASSIGN, '='}, - {TokenType::SEMICOLON, ';'}, - {TokenType::BRACES_LEFT, '{'}, - {TokenType::BRACES_RIGHT, '}'}, - {TokenType::BRACKETS_LEFT, '['}, - {TokenType::BRACKETS_RIGHT, ']'}, - {TokenType::PARENTHESES_LEFT, '('}, - {TokenType::PARENTHESES_RIGHT, ')'}, - {TokenType::ANGLE_BRACKETS_LEFT, '<'}, - {TokenType::ANGLE_BRACKETS_RIGHT, '>'}, - }; - - auto it = tokenCharMap.find(type); - return (it != tokenCharMap.end()) ? it->second : -1; -} } // namespace HDI } // namespace OHOS \ No newline at end of file diff --git a/framework/tools/hdi-gen/lexer/token.h b/framework/tools/hdi-gen/lexer/token.h index 2e157866b565fab8709b9fcd4eb07ec7f4f946fe..7aeb7f3db0cdd2d418317e5cb2f0ed2c07e6b5ad 100644 --- a/framework/tools/hdi-gen/lexer/token.h +++ b/framework/tools/hdi-gen/lexer/token.h @@ -107,10 +107,6 @@ struct TokenTypeCompare { }; std::string LocInfo(const Token &token); - -std::string TokenTypeToString(TokenType type); - -int TokenTypeToChar(TokenType type); } // namespace HDI } // namespace OHOS diff --git a/framework/tools/hdi-gen/main.cpp b/framework/tools/hdi-gen/main.cpp index ed8ca20df362cac3125b93936d474854c5ca714f..683ce59158abb43b20e4b3aed45580727afa18d5 100644 --- a/framework/tools/hdi-gen/main.cpp +++ b/framework/tools/hdi-gen/main.cpp @@ -17,20 +17,19 @@ using namespace OHOS::HDI; static bool GetHashKey() { - Options &options = Options::GetInstance(); - for (const auto &sourceFile : options.GetSourceFiles()) { + for (const auto &sourceFile : Options::GetInstance().GetSourceFiles()) { std::unique_ptr idlFile = std::make_unique(sourceFile, int(File::READ)); if (!idlFile->IsValid()) { Logger::E("hdi-gen", "failed to open idl file"); - return -1; + return false; } printf("%s:%lu\n", idlFile->GetPath().c_str(), idlFile->GetHashKey()); } - return 0; + return true; } int main(int argc, char **argv) { - Options &options = Options::GetInstance().Parse(argc, argv); + const Options &options = Options::GetInstance().Parse(argc, argv); if (options.HasErrors()) { options.ShowErrors(); return 0; @@ -47,7 +46,7 @@ int main(int argc, char **argv) return 0; } if (options.DoGetHashKey()) { - return GetHashKey(); + return GetHashKey() ? 0 : -1; } Preprocessor preprocessor; diff --git a/framework/tools/hdi-gen/parser/parser.cpp b/framework/tools/hdi-gen/parser/parser.cpp index ff5dff2d05ed6344932434f53a48968e23dcab0d..2b4510c700f4ab95f1d6b81a2b268dff2fd5c54b 100644 --- a/framework/tools/hdi-gen/parser/parser.cpp +++ b/framework/tools/hdi-gen/parser/parser.cpp @@ -31,9 +31,9 @@ namespace OHOS { namespace HDI { -static const std::regex rePackage(RE_IDENTIFIER "(?:\\." RE_IDENTIFIER ")*\\.[V|v]" +static const std::regex RE_PACKAGE(RE_IDENTIFIER "(?:\\." RE_IDENTIFIER ")*\\.[V|v]" "(" RE_DIGIT ")_(" RE_DIGIT ")"); -static const std::regex reImport( +static const std::regex RE_IMPORT( RE_IDENTIFIER "(?:\\." RE_IDENTIFIER ")*\\.[V|v]" RE_DIGIT "_" RE_DIGIT "." RE_IDENTIFIER); bool Parser::Parse(const std::vector &sourceFiles) @@ -155,7 +155,7 @@ bool Parser::ParsePackage() bool Parser::ParserPackageInfo(const std::string &packageName) { std::cmatch result; - if (!std::regex_match(packageName.c_str(), result, rePackage)) { + if (!std::regex_match(packageName.c_str(), result, RE_PACKAGE)) { return false; } @@ -979,7 +979,7 @@ AutoPtr Parser::ParseEnumBaseType() lexer_.GetToken(); } else { lexer_.GetToken(); - AutoPtr baseType = ast_->FindType("int"); + baseType = ast_->FindType("int"); } return baseType; } @@ -1543,7 +1543,7 @@ bool Parser::CheckPackageName(const std::string &filePath, const std::string &pa bool Parser::CheckImport(const std::string &importName) { - if (!std::regex_match(importName.c_str(), reImport)) { + if (!std::regex_match(importName.c_str(), RE_IMPORT)) { LogError(StringHelper::Format("invalid impirt name '%s'", importName.c_str())); return false; } diff --git a/framework/tools/hdi-gen/preprocessor/preprocessor.cpp b/framework/tools/hdi-gen/preprocessor/preprocessor.cpp index 3797a89c062f04128a4a7b1259af4ca784b7cfd7..244c3dc88bf2ea2e0b1a36bff8a3d4bef002004a 100644 --- a/framework/tools/hdi-gen/preprocessor/preprocessor.cpp +++ b/framework/tools/hdi-gen/preprocessor/preprocessor.cpp @@ -170,6 +170,11 @@ bool Preprocessor::ParseImports(Lexer &lexer, FileDetail &info) return false; } + if (!File::CheckValid(Options::GetInstance().GetImportFilePath(token.value_))) { + Logger::E(TAG, "%s: import invalid package '%s'", LocInfo(token).c_str(), token.value_.c_str()); + return false; + } + info.imports_.emplace(token.value_); lexer.GetToken(); @@ -252,9 +257,9 @@ void Preprocessor::PrintCyclefInfo(FileDetailMap &allFileDetails) { for (FileDetailMap::iterator it = allFileDetails.begin(); it != allFileDetails.end();) { if (it->second.imports_.size() == 0) { - allFileDetails.erase(it++); + it = allFileDetails.erase(it); } else { - it++; + ++it; } } @@ -266,7 +271,7 @@ void Preprocessor::PrintCyclefInfo(FileDetailMap &allFileDetails) void Preprocessor::FindCycle(const std::string &curNode, FileDetailMap &allFiles, std::vector &trace) { - auto iter = std::find_if(trace.begin(), trace.end(), [curNode](std::string name) { + auto iter = std::find_if(trace.begin(), trace.end(), [curNode](const std::string &name) { return name == curNode; }); if (iter != trace.end()) { diff --git a/framework/tools/hdi-gen/util/options.cpp b/framework/tools/hdi-gen/util/options.cpp index 65950f1e0a293ed72720ed6d9dfbc345ca1421ba..c6ba6443cdc42a54dd499c36797f6ec4ff0f78c2 100644 --- a/framework/tools/hdi-gen/util/options.cpp +++ b/framework/tools/hdi-gen/util/options.cpp @@ -63,12 +63,10 @@ void Options::SetOptionData(char op) { switch (op) { case 'c': - doCompile_ = true; - sourceFiles_.push_back(optarg); + AddSources(optarg); break; case 'd': - doOutDir_ = true; - generationDirectory_ = optarg; + SetOutDir(optarg); break; case 'h': doShowUsage_ = true; @@ -137,6 +135,18 @@ void Options::AddPackagePath(const std::string &packagePath) packagePath_[package] = path; } +void Options::AddSources(const std::string &sourceFile) +{ + doCompile_ = true; + sourceFiles_.push_back(sourceFile); +} + +void Options::SetOutDir(const std::string &dir) +{ + doOutDir_ = true; + generationDirectory_ = dir; +} + void Options::SetLanguage(Language kind) { doGenerateCode_ = true; diff --git a/framework/tools/hdi-gen/util/options.h b/framework/tools/hdi-gen/util/options.h index 0de53404d2e01d9caf21a5b7f04caa4def88e8e2..c9d235d57f2c9faca6b4d7b47e0b760e6086099e 100644 --- a/framework/tools/hdi-gen/util/options.h +++ b/framework/tools/hdi-gen/util/options.h @@ -146,6 +146,10 @@ private: void AddPackagePath(const std::string &packagePath); + void AddSources(const std::string &sourceFile); + + void SetOutDir(const std::string &dir); + void SetLanguage(Language language); void SetCodePart(const std::string &part); diff --git a/framework/tools/idl-gen/OWNER b/framework/tools/idl-gen/OWNER index 7803cb924fad28e87e1e7c388f80acba230472d2..7ee1810f807c61982bd056bff24d65220f907a8e 100644 --- a/framework/tools/idl-gen/OWNER +++ b/framework/tools/idl-gen/OWNER @@ -5,4 +5,5 @@ * the GPL, or the BSD license, at your option. * See the LICENSE file in the root of this repository for complete details. """ + 巴延兴 bayanxing@kaihongdigi.com \ No newline at end of file diff --git a/framework/tools/idl-gen/idl_generator.py b/framework/tools/idl-gen/idl_generator.py index 0105cd3e22d1dcde74ac94610e8ae63a68b30659..0cb3308bd138a9c5afcd95b5eccafb8c2a89e163 100644 --- a/framework/tools/idl-gen/idl_generator.py +++ b/framework/tools/idl-gen/idl_generator.py @@ -22,26 +22,9 @@ need %s module, try install first: exit() -try: - import CppHeaderParser - from _header_parser import HeaderParser -except ImportError: - pip.main(["--disable-pip-version-check", "install", "robotpy-cppheaderparser"]) - try: - import CppHeaderParser - from _header_parser import HeaderParser - except ImportError: - HeaderParser = None - lost_module("robotpy-cppheaderparser") - finally: - pass -finally: - pass - - class IDLGenerator: def __init__(self): - self._idl = "" + self._idl = [] self._output_path = "" self._file_list = [] self._key_list = {} @@ -91,8 +74,8 @@ class IDLGenerator: if result is None: continue self._parse_results[result.get("name")] = result - for file_name in result["import"]: # 把include的文件加入列表 - if file_name in self._parse_results: # 解析过的不重复解析 + for file_name in result.get("import", None): # 把include的文件加入列表 + if file_name in self._parse_results and file_name is not None: # 解析过的不重复解析 continue file_path = self._search_file(root_path, file_name) if file_path is not None: @@ -151,24 +134,25 @@ class IDLGenerator: original_idl = self._idl for file_name in header["import"]: if file_name not in self._parse_results: - self._idl += "// can't import %s\n" % file_name + self._idl.append("// can't import %s\n" % file_name) print("[IDLGenerator]: %s[line ?] can't find %s" % (os.path.normpath(header["path"] + "/" + header["name"]), file_name)) continue include_file = self._parse_results[file_name] if self._has_user_define_type(include_file): - tt = re.search("import\\s+\\S+.Types", self._idl) + tt = re.search("import\\s+\\S+.Types", "".join(self._idl)) if tt is None: - self._idl += "import " + self._get_package(include_file['path']) + ".Types;\n" + self._idl.append("import %s.Types;\n" % self._get_package(include_file['path'])) for iface in include_file["interface"]: - self._idl += "import " + self._get_package(include_file['path']) + ".%s;\n" % iface["name"] + self._idl.append("import %s.%s;\n" % (self._get_package(include_file['path']), iface["name"])) + # self._idl += for cb in include_file["callback"]: - self._idl += "import " + self._get_package(include_file['path']) + ".%s;\n" % cb["name"] + self._idl.append("import %s.%s;\n" % (self._get_package(include_file['path']), cb["name"])) for cb in header['callback']: - self._idl += "import " + self._get_package(header['path']) + ".%s;\n" % cb["name"] + self._idl.append("import %s.%s;\n" % (self._get_package(header['path']), cb["name"])) - if original_idl != self._idl: - self._idl += "\n" + if original_idl != "".join(self._idl): + self._idl.append("\n") except KeyError: pass finally: @@ -176,32 +160,32 @@ class IDLGenerator: def _install_enum(self, enums): for enum in enums: - self._idl += "enum %s {\n" % enum["name"] + self._idl.append("enum %s {\n" % enum["name"]) for member in enum["members"]: - self._idl += " %s = %s,\n" % (member["name"], member["value"]) - self._idl += "};\n" + self._idl.append(" %s = %s,\n" % (member["name"], member["value"])) + self._idl.append("};\n") def _install_stack(self, stacks): for stack in stacks: - self._idl += stack["type"] + " %s {\n" % stack["name"] + self._idl.append(stack["type"] + " %s {\n" % stack["name"]) for member in stack["members"]: param_type = self._swap_type_c2idl(member["type"]) if "unknown type" in param_type: print("[IDLGenerator]: %s[line %d] %s" % ( os.path.normpath(member["file_name"]), member["line_number"], param_type)) - self._idl += " %s %s;\n" % (param_type, member["name"]) - self._idl += "};\n" + self._idl.append(" %s %s;\n" % (param_type, member["name"])) + self._idl.append("};\n") def _install_interface(self, iface): if re.search("[Cc]all[Bb]ack", iface["name"]): - self._idl += "[callback] " - self._idl += "interface %s {\n" % iface["name"] + self._idl.append("[callback] ") + self._idl.append("interface %s {\n" % iface["name"]) for member in iface["members"]: self._install_function(iface["name"], member) - self._idl += "}\n" + self._idl.append("}\n") def _install_function(self, iface_name, member): - self._idl += " %s(" % member["name"] + self._idl.append(" %s(" % member["name"]) for i, param in enumerate(member["params"]): tt = re.fullmatch(r"(enum)*(union)*(struct)* *%s *\** * *\**" % iface_name, param["type"]) if tt: @@ -210,14 +194,14 @@ class IDLGenerator: if "unknown type" in param_type: print("[IDLGenerator]: %s[line %d] %s" % ( os.path.normpath(member["file_name"]), member["line_number"], param_type)) - self._idl += "%s %s %s," % ( + self._idl.append("%s %s %s," % ( '* *' in param["type"] and "[out]" or "[in]", param_type, - param["name"]) - if self._idl.endswith(','): - self._idl = self._idl[:-1] + ");\n" + param["name"])) + if "".join(self._idl).endswith(','): + self._idl = ["".join(self._idl)[:-1], ");\n"] else: - self._idl += ");\n" + self._idl.append(");\n") @staticmethod def _convert_basic_type(c_type): @@ -310,9 +294,9 @@ class IDLGenerator: def _write_file(self, file_path, file_name): file = os.path.join(self._make_output_dir(file_path), file_name).replace('\\', '/') with open(file, "w", encoding="utf8") as fp: - fp.write(self._idl) + fp.write("".join(self._idl)) print("Generate: --------------------- %s ---------------------\n" % os.path.normpath(file)) - self._idl = "" + self._idl = [] @staticmethod def _split_path(file_path): @@ -347,5 +331,20 @@ class IDLGenerator: if __name__ == "__main__": + try: + import CppHeaderParser + from _header_parser import HeaderParser + except ImportError: + pip.main(["--disable-pip-version-check", "install", "robotpy-cppheaderparser"]) + try: + import CppHeaderParser + from _header_parser import HeaderParser + except ImportError: + HeaderParser = None + lost_module("robotpy-cppheaderparser") + finally: + pass + finally: + pass generator = IDLGenerator() - generator.generate() + generator.generate() \ No newline at end of file diff --git a/framework/tools/idl-gen/testcase/test_idl_generator.py b/framework/tools/idl-gen/testcase/test_idl_generator.py index ee88a293052e9d78313e3583886945b06f0de317..cd91c41362c89da60790e91a208a0cdfb7e92f4b 100644 --- a/framework/tools/idl-gen/testcase/test_idl_generator.py +++ b/framework/tools/idl-gen/testcase/test_idl_generator.py @@ -115,7 +115,10 @@ class IDLGeneratorTestCase(unittest.TestCase): } header = generator._parse_results['audio_test.h'] generator._install_import(header) - self.assertEqual(generator._idl, "import include.AudioInterfaceOne;\nimport include.AudioInterfaceTwo;\n\n") + self.assertEqual( + "".join(generator._idl), + "import include.AudioInterfaceOne;\nimport include.AudioInterfaceTwo;\n\n" + ) def test_install_import_types(self): generator = IDLGenerator() diff --git a/framework/tools/leagecy/hc-gen/src/hcs_ast.c b/framework/tools/leagecy/hc-gen/src/hcs_ast.c index 4348483a79e1091d2215172693181f80a4b0ce6d..bc93085d93028c680b929094a7e3620ebce6d422 100644 --- a/framework/tools/leagecy/hc-gen/src/hcs_ast.c +++ b/framework/tools/leagecy/hc-gen/src/hcs_ast.c @@ -619,7 +619,7 @@ int32_t HcsWalkAst(ParserObject *start, uint32_t walkDirection, AstWalkCallBack backwardCallback = backwardCallback ? backwardCallback : AstWalkCallBackDefault; ParserObject *startObj = start ? start : g_parserRoot; - int32_t ret; + int32_t ret = EFAIL; switch (walkDirection) { case AST_WALK_FORWARD: ret = HcsForwardWalkAst(startObj, forwardCallback); diff --git a/framework/tools/leagecy/hc-gen/src/hcs_file.c b/framework/tools/leagecy/hc-gen/src/hcs_file.c index e3cdedaa73b3c2c8f42d6b5f569a8411f3528fc1..3d7d45ddc261727291863a9a7521a55c78edb2d2 100644 --- a/framework/tools/leagecy/hc-gen/src/hcs_file.c +++ b/framework/tools/leagecy/hc-gen/src/hcs_file.c @@ -448,7 +448,6 @@ int32_t HcsFormatOutputWrite(const char *format, ...) va_start(argList, format); int length = vsprintf_s(writeBuffer, WRITE_MAX_PER_TIME, format, argList); va_end(argList); - (void)argList; if (length < 0) { HCS_ERROR("Output too long in one time"); diff --git a/framework/tools/leagecy/hc-gen/src/hcs_middle.c b/framework/tools/leagecy/hc-gen/src/hcs_middle.c index aa239b88183c0cc81a67ac7a9db4ae77c2694c9c..25363d8db84342dc01e9481f09e6995540c67cc9 100644 --- a/framework/tools/leagecy/hc-gen/src/hcs_middle.c +++ b/framework/tools/leagecy/hc-gen/src/hcs_middle.c @@ -443,13 +443,13 @@ int32_t HcsDoOptimize(void) /* redefine check */ int32_t ret = HcsWalkAst(root, AST_WALK_BACKEND, NULL, HcsMiddleRedefineCheckCallback); - if (ret) { + if (ret != NOERR) { return ret; } /* merge multi file objects */ ret = HcsMiddleMerge(&root); - if (ret) { + if (ret != NOERR) { return ret; } @@ -460,12 +460,12 @@ int32_t HcsDoOptimize(void) HCS_DEBUG("compile module : %s", moduleName); /* expend node ref and node copy */ ret = HcsWalkAst(root, AST_WALK_BACKEND, NULL, HcsMiddleProcessCallback); - if (ret) { + if (ret != NOERR) { return ret; } ret = HcsWalkAst(root, AST_WALK_FORWARD, HcsMiddleInheritExpandCallback, NULL); - if (ret) { + if (ret != NOERR) { return ret; } diff --git a/framework/utils/src/hcs_parser/hcs_tree_if.c b/framework/utils/src/hcs_parser/hcs_tree_if.c index 2b760a492f19e0fb4da362054cf7e7c2a3f86071..3335eb0acf01e87132c6b80cad692a1cd29bd2ff 100644 --- a/framework/utils/src/hcs_parser/hcs_tree_if.c +++ b/framework/utils/src/hcs_parser/hcs_tree_if.c @@ -116,7 +116,7 @@ static const char *GetArrayElem(const struct DeviceResourceAttr *attr, uint32_t return NULL; } if (index >= count) { - HDF_LOGE("%s failed, index: %u >= count: %u", __func__, index, count); + HDF_LOGE("%s failed, index: %u >= count: %hu", __func__, index, count); return NULL; } for (i = 0; i < index; i++) { diff --git a/framework/utils/src/hdf_map.c b/framework/utils/src/hdf_map.c index 25ea77657ae5c7a92b938602c64413671b47ca9b..ae44e2fd6bf6ce77ca5f5627637c8023b5e21231 100644 --- a/framework/utils/src/hdf_map.c +++ b/framework/utils/src/hdf_map.c @@ -116,16 +116,28 @@ static struct MapNode *MapCreateNode(const char *key, uint32_t hash, return node; } -int32_t MapSet(Map *map, const char *key, const void *value, uint32_t valueSize) +static int32_t MapSetCheckPara(const Map *map, const char *key, const void *value, uint32_t valueSize) { - struct MapNode *node = NULL; - uint32_t hash; if (map == NULL || key == NULL || value == NULL || valueSize == 0) { return HDF_ERR_INVALID_PARAM; } + if (valueSize > HDF_MAP_KEY_MAX_SIZE || strlen(key) > HDF_MAP_VALUE_MAX_SIZE) { return HDF_ERR_INVALID_PARAM; } + + return HDF_SUCCESS; +} + +int32_t MapSet(Map *map, const char *key, const void *value, uint32_t valueSize) +{ + struct MapNode *node = NULL; + uint32_t hash; + + if (MapSetCheckPara(map, key, value, valueSize) != HDF_SUCCESS) { + return HDF_ERR_INVALID_PARAM; + } + hash = MapHash(key); if (map->nodeSize > 0 && map->nodes != NULL) { uint32_t idx = MapHashIdx(map, hash); @@ -151,13 +163,17 @@ int32_t MapSet(Map *map, const char *key, const void *value, uint32_t valueSize) // Increase the bucket size when nodes is nullptr if (map->nodes == NULL) { MapInit(map); - MapResize(map, HDF_MIN_MAP_SIZE); + if (MapResize(map, HDF_MIN_MAP_SIZE) != HDF_SUCCESS) { + return HDF_FAILURE; + } } // Increase the bucket size to decrease the possibility of map search conflict. if (map->nodeSize >= map->bucketSize) { uint32_t size = (map->bucketSize < HDF_MIN_MAP_SIZE) ? HDF_MIN_MAP_SIZE : \ (map->bucketSize << HDF_ENLARGE_FACTOR); - MapResize(map, size); + if (MapResize(map, size) != HDF_SUCCESS) { + return HDF_FAILURE; + } } node = MapCreateNode(key, hash, value, valueSize); if (node == NULL) {