From de9bd1a0916187621cf6933d0aa2ff78751c1b07 Mon Sep 17 00:00:00 2001 From: huyx Date: Mon, 15 Jul 2024 17:00:55 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=91=8A=E8=AD=A6=E6=B8=85=E7=90=86?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huyx --- adapter/uhdf2/host/src/devhost_service_stub.c | 2 -- adapter/uhdf2/manager/src/devmgr_uevent.c | 8 +++++++ .../shared/src/dev_attribute_serialize.c | 4 ++++ framework/core/host/src/devhost_service.c | 22 +++++++++---------- framework/core/host/src/hdf_device.c | 6 ++--- framework/core/manager/src/devmgr_service.c | 2 +- 6 files changed, 27 insertions(+), 17 deletions(-) diff --git a/adapter/uhdf2/host/src/devhost_service_stub.c b/adapter/uhdf2/host/src/devhost_service_stub.c index 2ed830204..9cf8e183b 100644 --- a/adapter/uhdf2/host/src/devhost_service_stub.c +++ b/adapter/uhdf2/host/src/devhost_service_stub.c @@ -41,7 +41,6 @@ static int DispatchAddDevice(struct IDevHostService *serviceIf, struct HdfSBuf * HDF_LOGE("Dispatch failed, attribute is null"); return HDF_FAILURE; } - HDF_LOGI("add device 0x%x", attribute->deviceId); int ret = serviceIf->AddDevice(serviceIf, attribute); if (ret != HDF_SUCCESS) { HDF_LOGE("Dispatch failed, add service failed and ret is %{public}d", ret); @@ -63,7 +62,6 @@ static int DispatchDelDevice(struct IDevHostService *serviceIf, struct HdfSBuf * return HDF_FAILURE; } - HDF_LOGI("del device 0x%x", deviceId); int ret = serviceIf->DelDevice(serviceIf, deviceId); if (ret != HDF_SUCCESS) { HDF_LOGE("del service failed, ret is %{public}d", ret); diff --git a/adapter/uhdf2/manager/src/devmgr_uevent.c b/adapter/uhdf2/manager/src/devmgr_uevent.c index 52f630fb2..b69fc0a25 100644 --- a/adapter/uhdf2/manager/src/devmgr_uevent.c +++ b/adapter/uhdf2/manager/src/devmgr_uevent.c @@ -143,6 +143,10 @@ static int32_t DevMgrUeventParseKeyValue(char *str, struct DevMgrMatchKey *match HDF_LOGD("key:%{public}s,value:[%{public}s]", str, value); matchKey->key = strdup(str); matchKey->value = strdup(value); + if (matchKey->key == NULL || matchKey->value == NULL) { + HDF_LOGE("invalid param : matchKey->key or matchKey->value"); + return HDF_FAILURE; + } return HDF_SUCCESS; } @@ -234,6 +238,10 @@ static int32_t DevMgrUeventParseHdfEvent(char *subStr, struct DevMgrUeventRuleCf HDF_LOGD("event:%{public}s:%{public}d\n", event, ruleCfg->action); ruleCfg->serviceName = strdup(event); + if (ruleCfg->serviceName == NULL) { + HDF_LOGE("ruleCfg->serviceName is NULL"); + return HDF_FAILURE; + } if (DListGetCount(&ruleCfg->matchKeyList) == 0) { HDF_LOGE("parse failed, no match key"); return HDF_FAILURE; diff --git a/adapter/uhdf2/shared/src/dev_attribute_serialize.c b/adapter/uhdf2/shared/src/dev_attribute_serialize.c index c7e91d0a4..f8658ee61 100644 --- a/adapter/uhdf2/shared/src/dev_attribute_serialize.c +++ b/adapter/uhdf2/shared/src/dev_attribute_serialize.c @@ -99,6 +99,10 @@ static bool DeviceAttributeSet(struct HdfDeviceInfo *attribute, struct HdfSBuf * return false; } attribute->deviceMatchAttr = strdup(deviceMatchAttr); + if (attribute->deviceMatchAttr == NULL) { + HDF_LOGE("Read from sbuf failed, strdup deviceMatchAttr fail"); + return false; + } } return true; diff --git a/framework/core/host/src/devhost_service.c b/framework/core/host/src/devhost_service.c index 460af613f..166dc7d4a 100644 --- a/framework/core/host/src/devhost_service.c +++ b/framework/core/host/src/devhost_service.c @@ -47,7 +47,7 @@ static struct HdfDevice *DevHostServiceQueryOrAddDevice(struct DevHostService *i { struct HdfDevice *device = DevHostServiceFindDevice(inst, deviceId); if (device == NULL) { - HDF_LOGD("%{public}s can't find device %d, try to create", __func__, deviceId); + HDF_LOGD("%{public}s can't find device, try to create", __func__); device = HdfDeviceNewInstance(); if (device == NULL) { HDF_LOGE("Dev host service failed to create driver instance"); @@ -55,7 +55,7 @@ static struct HdfDevice *DevHostServiceQueryOrAddDevice(struct DevHostService *i } device->deviceId = MK_DEVID(inst->hostId, deviceId, 0); DListInsertHead(&device->node, &inst->devices); - HDF_LOGD("%{public}s add device %d complete", __func__, deviceId); + HDF_LOGD("%{public}s add device complete", __func__); } return device; } @@ -76,12 +76,12 @@ int DevHostServiceAddDevice(struct IDevHostService *inst, const struct HdfDevice device = DevHostServiceQueryOrAddDevice(hostService, DEVICEID(deviceInfo->deviceId)); if (device == NULL || device->super.Attach == NULL) { - HDF_LOGE("failed to add device %d, device or Attach func is null", deviceInfo->deviceId); + HDF_LOGE("failed to add device, device or Attach func is null"); return HDF_DEV_ERR_NO_DEVICE; } devNode = device->super.GetDeviceNode(&device->super, deviceInfo->deviceId); if (devNode != NULL) { - HDF_LOGE("failed to add device %d, device already exist", deviceInfo->deviceId); + HDF_LOGE("failed to add device, device already exist"); return HDF_ERR_DEVICE_BUSY; } driver = driverLoader->GetDriver(deviceInfo->moduleName); @@ -93,7 +93,7 @@ int DevHostServiceAddDevice(struct IDevHostService *inst, const struct HdfDevice devNode = HdfDeviceNodeNewInstance(deviceInfo, driver); if (devNode == NULL) { - HDF_LOGE("failed to add device %d, create devNode failed", deviceInfo->deviceId); + HDF_LOGE("failed to add device, create devNode failed"); driverLoader->ReclaimDriver(driver); return HDF_DEV_ERR_NO_MEMORY; } @@ -103,11 +103,11 @@ int DevHostServiceAddDevice(struct IDevHostService *inst, const struct HdfDevice devNode->driver = driver; ret = device->super.Attach(&device->super, devNode); if (ret != HDF_SUCCESS) { - HDF_LOGE("failed to add device %d, attach devNode failed", deviceInfo->deviceId); + HDF_LOGE("failed to add device, attach devNode failed"); HdfDeviceNodeFreeInstance(devNode); goto ERROR; } - HDF_LOGD("%{public}s add device %d success", __func__, deviceInfo->deviceId); + HDF_LOGD("%{public}s add device success", __func__); return HDF_SUCCESS; ERROR: @@ -132,17 +132,17 @@ int DevHostServiceDelDevice(struct IDevHostService *inst, devid_t devId) devNode = device->super.GetDeviceNode(&device->super, devId); if (devNode == NULL) { - HDF_LOGI("failed to del device %u, not exist", devId); + HDF_LOGI("failed to del device, not exist"); return HDF_DEV_ERR_NO_DEVICE; } if (device->super.Detach == NULL) { - HDF_LOGE("failed to del device %u, invalid device", devId); + HDF_LOGE("failed to del device, invalid device"); return HDF_ERR_INVALID_OBJECT; } if (device->super.Detach(&device->super, devNode) != HDF_SUCCESS) { - HDF_LOGE("failed to detach device %u", devId); + HDF_LOGE("failed to detach device"); return HDF_FAILURE; } HdfDeviceNodeFreeInstance(devNode); @@ -150,7 +150,7 @@ int DevHostServiceDelDevice(struct IDevHostService *inst, devid_t devId) if (DListIsEmpty(&device->devNodes)) { DevHostServiceFreeDevice(hostService, device); } - HDF_LOGD("%{public}s add device %u success", __func__, devId); + HDF_LOGD("%{public}s add device success", __func__); return HDF_SUCCESS; } diff --git a/framework/core/host/src/hdf_device.c b/framework/core/host/src/hdf_device.c index c6913f5ea..b795b243e 100644 --- a/framework/core/host/src/hdf_device.c +++ b/framework/core/host/src/hdf_device.c @@ -111,8 +111,8 @@ int HdfDeviceDetach(struct IHdfDevice *devInst, struct HdfDeviceNode *devNode) device = CONTAINER_OF(devInst, struct HdfDevice, super); if (DEVICEID(device->deviceId) != DEVICEID(devNode->devId)) { - HDF_LOGE("%{public}s: device %x detach unknown devnode %x", - __func__, device->deviceId, devNode->devId); + HDF_LOGE("%{public}s: device detach unknown devnode ", + __func__); return HDF_DEV_ERR_NO_DEVICE; } @@ -143,7 +143,7 @@ static int HdfDeviceDetachWithDevid(struct IHdfDevice *device, devid_t devid) struct HdfDevice *dev = CONTAINER_OF(device, struct HdfDevice, super); struct HdfDeviceNode *devNode = HdfDeviceGetDeviceNode(device, devid); if (devNode == NULL) { - HDF_LOGE("detach device node %x not in device %x", devid, dev->deviceId); + HDF_LOGE("devNode is NULL"); return HDF_DEV_ERR_NO_DEVICE; } diff --git a/framework/core/manager/src/devmgr_service.c b/framework/core/manager/src/devmgr_service.c index 5e07f39cc..902ce8f54 100644 --- a/framework/core/manager/src/devmgr_service.c +++ b/framework/core/manager/src/devmgr_service.c @@ -277,7 +277,7 @@ static int DevmgrServiceDetachDevice(struct IDevmgrService *inst, devid_t devid) } tokenClntNode = HdfSListSearch(&hostClnt->devices, devid, HdfSListHostSearchDeviceTokenComparer); if (tokenClntNode == NULL) { - HDF_LOGE("devmgr detach device %x not found", devid); + HDF_LOGE("devmgr detach devic not found"); return HDF_DEV_ERR_NO_DEVICE; } tokenClnt = CONTAINER_OF(tokenClntNode, struct DeviceTokenClnt, node); -- Gitee From 76cec76ddb51e2f861e7ac925d6bbe9b51310dfc Mon Sep 17 00:00:00 2001 From: huyx Date: Mon, 15 Jul 2024 19:39:13 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=91=8A=E8=AD=A6=E6=B8=85=E7=90=86?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huyx --- framework/core/host/src/hdf_device.c | 1 + 1 file changed, 1 insertion(+) diff --git a/framework/core/host/src/hdf_device.c b/framework/core/host/src/hdf_device.c index b795b243e..04e899ff6 100644 --- a/framework/core/host/src/hdf_device.c +++ b/framework/core/host/src/hdf_device.c @@ -141,6 +141,7 @@ static struct HdfDeviceNode *HdfDeviceGetDeviceNode(struct IHdfDevice *device, d static int HdfDeviceDetachWithDevid(struct IHdfDevice *device, devid_t devid) { struct HdfDevice *dev = CONTAINER_OF(device, struct HdfDevice, super); + (void)dev; struct HdfDeviceNode *devNode = HdfDeviceGetDeviceNode(device, devid); if (devNode == NULL) { HDF_LOGE("devNode is NULL"); -- Gitee