diff --git a/support/platform/include/fwk/platform_device.h b/support/platform/include/fwk/platform_device.h index 36d666c5e81125aa9f09127e3f8c90739abfe179..43a2efa35d0bb7dfaac09dab31932501373514c4 100644 --- a/support/platform/include/fwk/platform_device.h +++ b/support/platform/include/fwk/platform_device.h @@ -231,21 +231,22 @@ int32_t PlatformDeviceBind(struct PlatformDevice *device, struct HdfDeviceObject * @brief Unbind from a hdf device object. * * @param device Indicates the pointer to the platform device. + * @param hdfDevice Indicates the pointer to the hdf device object. * * @since 1.0 */ -void PlatformDeviceUnbind(struct PlatformDevice *device); +void PlatformDeviceUnbind(struct PlatformDevice *device, struct HdfDeviceObject *hdfDevice); /** - * @brief Get the platform device from a hdf device object. + * @brief Transform a hdf device object to a platform device object. * * @param device Indicates the pointer to the platform device. * - * @return Returns 0 if get successfully; returns a negative value otherwise. + * @return Returns the pointer to the platform device object on success; otherwise null. * @since 1.0 */ -int32_t PlatformDeviceGetFromHdfDev(struct HdfDeviceObject *hdfDev, struct PlatformDevice **device); +struct PlatformDevice *PlatformDeviceFromHdfDev(struct HdfDeviceObject *hdfDev); #ifdef __cplusplus #if __cplusplus diff --git a/support/platform/include/gpio/gpio_core.h b/support/platform/include/gpio/gpio_core.h index 15d78a8e18b446c35117acfcc85fc908a2555b21..c7b981bf61b48194a1da3adcf3a836a62307c2cc 100644 --- a/support/platform/include/gpio/gpio_core.h +++ b/support/platform/include/gpio/gpio_core.h @@ -166,9 +166,9 @@ void GpioCntlrRemove(struct GpioCntlr *cntlr); * @return Retrns the pointer of the GpioCntlr on success; returns NULL otherwise. * @since 1.0 */ -static inline struct GpioCntlr *GpioCntlrFromDevice(struct HdfDeviceObject *device) +static inline struct GpioCntlr *GpioCntlrFromHdfDev(struct HdfDeviceObject *device) { - return (device == NULL) ? NULL : (struct GpioCntlr *)device->service; + return (struct GpioCntlr *)PlatformDeviceFromHdfDev(device); } int32_t GpioCntlrWrite(struct GpioCntlr *cntlr, uint16_t local, uint16_t val); @@ -193,7 +193,7 @@ void GpioCntlrIrqCallback(struct GpioCntlr *cntlr, uint16_t local); struct PlatformManager *GpioManagerGet(void); -struct GpioCntlr *GpioCntlrGet(uint16_t gpio); +struct GpioCntlr *GpioCntlrGetByGpio(uint16_t gpio); static inline void GpioCntlrPut(struct GpioCntlr *cntlr) { diff --git a/support/platform/src/fwk/platform_device.c b/support/platform/src/fwk/platform_device.c index f5416f9fd8848b539d60110b8f204bb26158a1fc..5e6b13339851a4ff07dbd34ba3b8157d0b396395 100644 --- a/support/platform/src/fwk/platform_device.c +++ b/support/platform/src/fwk/platform_device.c @@ -288,7 +288,7 @@ int32_t PlatformDeviceBind(struct PlatformDevice *device, struct HdfDeviceObject return HDF_SUCCESS; } -void PlatformDeviceUnbind(struct PlatformDevice *device) +void PlatformDeviceUnbind(struct PlatformDevice *device, struct HdfDeviceObject *hdfDev) { if (device == NULL) { return; @@ -296,23 +296,24 @@ void PlatformDeviceUnbind(struct PlatformDevice *device) if (device->hdfDev == NULL) { return; } + if (device->hdfDev != hdfDev) { + PLAT_LOGW("PlatformDeviceUnbind: hdf device not match!"); + return; + } device->hdfDev->service = NULL; device->hdfDev->priv = NULL; device->hdfDev = NULL; } -int32_t PlatformDeviceGetFromHdfDev(struct HdfDeviceObject *hdfDev, struct PlatformDevice **device) +struct PlatformDevice *PlatformDeviceFromHdfDev(struct HdfDeviceObject *hdfDev) { if (hdfDev == NULL || hdfDev->priv == NULL) { - return HDF_ERR_INVALID_OBJECT; - } - if (device == NULL) { - return HDF_ERR_INVALID_PARAM; + PLAT_LOGE("PlatformDeviceFromHdfDev: hdf device or priv null"); + return NULL; } - *device = (struct PlatformDevice *)hdfDev->priv; - return HDF_SUCCESS; + return (struct PlatformDevice *)hdfDev->priv; } int32_t PlatformDevicePostEvent(struct PlatformDevice *device, uint32_t events) diff --git a/support/platform/src/gpio/gpio_if.c b/support/platform/src/gpio/gpio_if.c index 24d904e1b6bbf0610fc47e24a85f528da97388ec..23841842d6478f96f615ab45bcdea3a31dee64e9 100644 --- a/support/platform/src/gpio/gpio_if.c +++ b/support/platform/src/gpio/gpio_if.c @@ -19,7 +19,7 @@ #include "hdf_base.h" -#define PLAT_LOG_TAG gpio_if +#define HDF_LOG_TAG gpio_if #ifdef __USER__ @@ -247,7 +247,7 @@ int32_t GpioDisableIrq(uint16_t gpio) int32_t GpioRead(uint16_t gpio, uint16_t *val) { int32_t ret; - struct GpioCntlr *cntlr = GpioCntlrGet(gpio); + struct GpioCntlr *cntlr = GpioCntlrGetByGpio(gpio); ret = GpioCntlrRead(cntlr, GpioCntlrGetLocal(cntlr, gpio), val); @@ -258,7 +258,7 @@ int32_t GpioRead(uint16_t gpio, uint16_t *val) int32_t GpioWrite(uint16_t gpio, uint16_t val) { int32_t ret; - struct GpioCntlr *cntlr = GpioCntlrGet(gpio); + struct GpioCntlr *cntlr = GpioCntlrGetByGpio(gpio); ret = GpioCntlrWrite(cntlr, GpioCntlrGetLocal(cntlr, gpio), val); @@ -269,7 +269,7 @@ int32_t GpioWrite(uint16_t gpio, uint16_t val) int32_t GpioSetDir(uint16_t gpio, uint16_t dir) { int32_t ret; - struct GpioCntlr *cntlr = GpioCntlrGet(gpio); + struct GpioCntlr *cntlr = GpioCntlrGetByGpio(gpio); ret = GpioCntlrSetDir(cntlr, GpioCntlrGetLocal(cntlr, gpio), dir); @@ -280,7 +280,7 @@ int32_t GpioSetDir(uint16_t gpio, uint16_t dir) int32_t GpioGetDir(uint16_t gpio, uint16_t *dir) { int32_t ret; - struct GpioCntlr *cntlr = GpioCntlrGet(gpio); + struct GpioCntlr *cntlr = GpioCntlrGetByGpio(gpio); ret = GpioCntlrGetDir(cntlr, GpioCntlrGetLocal(cntlr, gpio), dir); @@ -291,7 +291,7 @@ int32_t GpioGetDir(uint16_t gpio, uint16_t *dir) int32_t GpioSetIrq(uint16_t gpio, uint16_t mode, GpioIrqFunc func, void *arg) { int32_t ret; - struct GpioCntlr *cntlr = GpioCntlrGet(gpio); + struct GpioCntlr *cntlr = GpioCntlrGetByGpio(gpio); ret = GpioCntlrSetIrq(cntlr, GpioCntlrGetLocal(cntlr, gpio), mode, func, arg); @@ -302,7 +302,7 @@ int32_t GpioSetIrq(uint16_t gpio, uint16_t mode, GpioIrqFunc func, void *arg) int32_t GpioUnsetIrq(uint16_t gpio, void *arg) { int32_t ret; - struct GpioCntlr *cntlr = GpioCntlrGet(gpio); + struct GpioCntlr *cntlr = GpioCntlrGetByGpio(gpio); ret = GpioCntlrUnsetIrq(cntlr, GpioCntlrGetLocal(cntlr, gpio), arg); @@ -313,7 +313,7 @@ int32_t GpioUnsetIrq(uint16_t gpio, void *arg) int32_t GpioEnableIrq(uint16_t gpio) { int32_t ret; - struct GpioCntlr *cntlr = GpioCntlrGet(gpio); + struct GpioCntlr *cntlr = GpioCntlrGetByGpio(gpio); ret = GpioCntlrEnableIrq(cntlr, GpioCntlrGetLocal(cntlr, gpio)); @@ -324,7 +324,7 @@ int32_t GpioEnableIrq(uint16_t gpio) int32_t GpioDisableIrq(uint16_t gpio) { int32_t ret; - struct GpioCntlr *cntlr = GpioCntlrGet(gpio); + struct GpioCntlr *cntlr = GpioCntlrGetByGpio(gpio); ret = GpioCntlrDisableIrq(cntlr, GpioCntlrGetLocal(cntlr, gpio)); diff --git a/support/platform/src/gpio/gpio_manager.c b/support/platform/src/gpio/gpio_manager.c index 808d6c379ac765924e225c56a75aee884ac6fd00..4c4e0afd78d956aef2941024a5d9be09be865f60 100644 --- a/support/platform/src/gpio/gpio_manager.c +++ b/support/platform/src/gpio/gpio_manager.c @@ -199,20 +199,20 @@ static bool GpioCntlrFindMatch(struct PlatformDevice *device, void *data) return false; } -struct GpioCntlr *GpioCntlrGet(uint16_t gpio) +struct GpioCntlr *GpioCntlrGetByGpio(uint16_t gpio) { struct PlatformManager *gpioMgr = NULL; struct PlatformDevice *device = NULL; gpioMgr = GpioManagerGet(); if (gpioMgr == NULL) { - PLAT_LOGE("GpioCntlrRemove: get gpio manager failed"); + PLAT_LOGE("GpioCntlrGetByGpio: get gpio manager failed"); return NULL; } device = PlatformManagerFindDevice(gpioMgr, (void *)(uintptr_t)gpio, GpioCntlrFindMatch); if (device == NULL) { - PLAT_LOGE("%s: gpio %u not in any controllers!", __func__, gpio); + PLAT_LOGE("GpioCntlrGetByGpio: gpio %u not in any controllers!", gpio); return NULL; } return CONTAINER_OF(device, struct GpioCntlr, device); diff --git a/support/platform/src/gpio/gpio_service.c b/support/platform/src/gpio/gpio_service.c index 524c94b72ba4988d65e4fe5e1d350ed100ede8ba..658937777c76197795101f256fc85aca1fb00b97 100644 --- a/support/platform/src/gpio/gpio_service.c +++ b/support/platform/src/gpio/gpio_service.c @@ -207,7 +207,7 @@ static void GpioServiceRelease(struct HdfDeviceObject *device) return; } - (void)PlatformDeviceUnbind(&gpioMgr->device); + (void)PlatformDeviceUnbind(&gpioMgr->device, device); (void)PlatformDeviceDestroyService(&gpioMgr->device); PLAT_LOGI("GpioServiceRelease: done"); } diff --git a/test/unittest/platform/common/platform_device_test.c b/test/unittest/platform/common/platform_device_test.c index afe037b358a1988d2246e23490491958b739ffca..3ab51edc312e6e1ac1af636cb4795ea00c5ce05a 100644 --- a/test/unittest/platform/common/platform_device_test.c +++ b/test/unittest/platform/common/platform_device_test.c @@ -194,11 +194,10 @@ static int32_t PlatformDeviceTestBindDevice(struct PlatformDevice *device) CHECK_EQ_RETURN(device->hdfDev, &hdfDev, HDF_FAILURE); CHECK_EQ_RETURN(device->service, hdfDev.service, HDF_FAILURE); - ret = PlatformDeviceGetFromHdfDev(&hdfDev, &devFromHdf); - CHECK_EQ_RETURN(ret, HDF_SUCCESS, ret); + devFromHdf = PlatformDeviceFromHdfDev(&hdfDev); CHECK_EQ_RETURN(device, devFromHdf, HDF_FAILURE); - PlatformDeviceUnbind(device); + PlatformDeviceUnbind(device, &hdfDev); CHECK_EQ_RETURN(device->hdfDev, NULL, ret); CHECK_EQ_RETURN(hdfDev.service, NULL, ret); @@ -252,12 +251,11 @@ static int32_t PlatformDeviceTestReliability(struct PlatformDevice *device) CHECK_NE_RETURN(ret, HDF_SUCCESS, HDF_FAILURE); ret = PlatformDeviceBind(NULL, &hdfDev); CHECK_NE_RETURN(ret, HDF_SUCCESS, HDF_FAILURE); - PlatformDeviceUnbind(NULL); + PlatformDeviceUnbind(device, NULL); + PlatformDeviceUnbind(NULL, NULL); - ret = PlatformDeviceGetFromHdfDev(&hdfDev, NULL); - CHECK_NE_RETURN(ret, HDF_SUCCESS, HDF_FAILURE); - ret = PlatformDeviceGetFromHdfDev(NULL, &devGet); - CHECK_NE_RETURN(ret, HDF_SUCCESS, HDF_FAILURE); + devGet = PlatformDeviceFromHdfDev(NULL); + CHECK_NULL_RETURN(devGet, HDF_FAILURE); PLAT_LOGD("%s: exit", __func__); return HDF_SUCCESS;