!101 fix DeviceNode release interface not called issue

Merge pull request !101 from yuanbo/master
This commit is contained in:
openharmony_ci
2021-07-01 09:33:25 +00:00
committed by Gitee
3 changed files with 14 additions and 22 deletions
+10 -12
View File
@@ -17,15 +17,15 @@
#define HDF_LOG_TAG devhost_service
static struct HdfDevice *DevHostServiceFindDevice(struct DevHostService *inst, uint16_t deviceId)
static struct HdfDevice *DevHostServiceFindDevice(struct DevHostService *hostService, uint16_t deviceId)
{
struct HdfDevice *deviceNode = NULL;
if (inst == NULL) {
HDF_LOGE("failed to find driver, inst is null");
if (hostService == NULL) {
HDF_LOGE("failed to find driver, hostService is null");
return NULL;
}
DLIST_FOR_EACH_ENTRY(deviceNode, &inst->devices, struct HdfDevice, node) {
DLIST_FOR_EACH_ENTRY(deviceNode, &hostService->devices, struct HdfDevice, node) {
if (deviceNode->deviceId == deviceId) {
return deviceNode;
}
@@ -33,12 +33,12 @@ static struct HdfDevice *DevHostServiceFindDevice(struct DevHostService *inst, u
return NULL;
}
static void DevHostServiceFreeDevice(struct DevHostService *inst, uint16_t deviceId)
static void DevHostServiceFreeDevice(struct DevHostService *hostService, uint16_t deviceId)
{
struct HdfDevice *deviceNode = DevHostServiceFindDevice(inst, deviceId);
if (deviceNode != NULL) {
DListRemove(&deviceNode->node);
HdfDeviceFreeInstance(deviceNode);
struct HdfDevice *device = DevHostServiceFindDevice(hostService, deviceId);
if (device != NULL) {
DListRemove(&device->node);
HdfDeviceFreeInstance(device);
}
}
@@ -90,9 +90,7 @@ int DevHostServiceAddDevice(struct IDevHostService *inst, const struct HdfDevice
return HDF_SUCCESS;
error:
if (DListIsEmpty(&hostService->devices)) {
DevHostServiceFreeDevice(hostService, hostService->hostId);
}
DevHostServiceFreeDevice(hostService, device->deviceId);
return ret;
}
+1 -1
View File
@@ -68,7 +68,7 @@ struct HdfDevice *HdfDeviceNewInstance()
void HdfDeviceFreeInstance(struct HdfDevice *device)
{
if (device != NULL) {
HdfObjectManagerFreeObject((struct HdfObject *)device);
HdfObjectManagerFreeObject(&device->super.object);
}
}
+3 -9
View File
@@ -86,24 +86,15 @@ int HdfDeviceLaunchNode(struct HdfDeviceNode *devNode, struct IHdfDevice *devIns
}
int ret = driverEntry->Init(&devNode->deviceObject);
if (ret != HDF_SUCCESS) {
if (driverEntry->Release != NULL) {
driverEntry->Release(&devNode->deviceObject);
}
return HDF_DEV_ERR_DEV_INIT_FAIL;
}
ret = HdfDeviceNodePublishService(devNode, deviceInfo, devInst);
if (ret != HDF_SUCCESS) {
if (driverEntry->Release != NULL) {
driverEntry->Release(&devNode->deviceObject);
}
return HDF_DEV_ERR_PUBLISH_FAIL;
}
deviceToken = devNode->token;
ret = DevmgrServiceClntAttachDevice(deviceInfo, deviceToken);
if (ret != HDF_SUCCESS) {
if (driverEntry->Release != NULL) {
driverEntry->Release(&devNode->deviceObject);
}
return HDF_DEV_ERR_ATTACHDEV_FAIL;
}
return ret;
@@ -186,6 +177,9 @@ void HdfDeviceNodeDelete(struct HdfSListNode *deviceEntry)
}
struct HdfDeviceNode *devNode =
HDF_SLIST_CONTAINER_OF(struct HdfSListNode, deviceEntry, struct HdfDeviceNode, entry);
if (devNode->driverEntry->Release != NULL) {
devNode->driverEntry->Release(&devNode->deviceObject);
}
HdfDeviceNodeFreeInstance(devNode);
}