diff --git a/support/platform/src/adc/adc_core.c b/support/platform/src/adc/adc_core.c index 19750530..771ef304 100644 --- a/support/platform/src/adc/adc_core.c +++ b/support/platform/src/adc/adc_core.c @@ -178,7 +178,7 @@ static struct AdcDevice *AdcManagerFindDevice(uint32_t number) struct AdcDevice *device = NULL; struct AdcManager *manager = g_adcManager; - if (number < 0 || number >= ADC_DEVICES_MAX) { + if (number >= ADC_DEVICES_MAX) { HDF_LOGE("%s: invalid devNum:%u", __func__, number); return NULL; } @@ -320,7 +320,7 @@ static int32_t AdcManagerIoOpen(struct HdfSBuf *data, struct HdfSBuf *reply) return HDF_ERR_IO; } - if (number < 0 || number >= ADC_DEVICES_MAX || reply == NULL) { + if (number >= ADC_DEVICES_MAX || reply == NULL) { HDF_LOGE("%s: invalid number!", __func__); return HDF_ERR_INVALID_PARAM; } @@ -354,7 +354,7 @@ static int32_t AdcManagerIoClose(struct HdfSBuf *data, struct HdfSBuf *reply) } number = (uint32_t)(number - ADC_HANDLE_SHIFT); - if (number < 0 || number >= ADC_DEVICES_MAX) { + if (number >= ADC_DEVICES_MAX) { HDF_LOGE("%s: get device %u failed", __func__, number); return HDF_ERR_INVALID_PARAM; } diff --git a/support/platform/src/dac/dac_core.c b/support/platform/src/dac/dac_core.c index ec928683..1a1d37b0 100644 --- a/support/platform/src/dac/dac_core.c +++ b/support/platform/src/dac/dac_core.c @@ -145,7 +145,7 @@ static struct DacDevice *DacManagerFindDevice(uint32_t number) struct DacDevice *device = NULL; struct DacManager *manager = g_dacManager; - if (number < 0 || number >= DAC_DEVICES_MAX) { + if (number >= DAC_DEVICES_MAX) { HDF_LOGE("%s: invalid devNum:%u", __func__, number); return NULL; } @@ -334,7 +334,7 @@ static int32_t DacManagerIoOpen(struct HdfSBuf *data, struct HdfSBuf *reply) return HDF_ERR_IO; } - if (number < 0 || number >= DAC_DEVICES_MAX || reply == NULL) { + if (number >= DAC_DEVICES_MAX || reply == NULL) { HDF_LOGE("%s: invalid number %u", __func__, number); return HDF_ERR_INVALID_PARAM; } @@ -367,7 +367,7 @@ static int32_t DacManagerIoClose(struct HdfSBuf *data, struct HdfSBuf *reply) } number = (uint32_t)(number - DAC_HANDLE_SHIFT); - if (number < 0 || number >= DAC_DEVICES_MAX) { + if (number >= DAC_DEVICES_MAX) { HDF_LOGE("%s: invalid number %u", __func__, number); return HDF_ERR_INVALID_PARAM; } @@ -394,7 +394,7 @@ static int32_t DacManagerIoWrite(struct HdfSBuf *data, struct HdfSBuf *reply) } number = (uint32_t)(number - DAC_HANDLE_SHIFT); - if (number < 0 || number >= DAC_DEVICES_MAX) { + if (number >= DAC_DEVICES_MAX) { HDF_LOGE("%s: invalid number %u", __func__, number); return HDF_ERR_INVALID_PARAM; } diff --git a/support/platform/src/gpio/gpio_service.c b/support/platform/src/gpio/gpio_service.c index ecb8fa40..289b6a01 100644 --- a/support/platform/src/gpio/gpio_service.c +++ b/support/platform/src/gpio/gpio_service.c @@ -50,8 +50,9 @@ static int32_t GpioServiceIoWrite(struct HdfSBuf *data, struct HdfSBuf *reply) uint16_t gpio; uint16_t value; - if (data == NULL || reply == NULL) { - HDF_LOGE("%s: data or reply is NULL", __func__); + (void)reply; + if (data == NULL) { + HDF_LOGE("%s: data is NULL", __func__); } if (!HdfSbufReadUint16(data, &gpio)) { @@ -109,8 +110,9 @@ static int32_t GpioServiceIoSetDir(struct HdfSBuf *data, struct HdfSBuf *reply) uint16_t gpio; uint16_t dir; - if (data == NULL || reply == NULL) { - HDF_LOGE("%s: data or reply is NULL", __func__); + (void)reply; + if (data == NULL) { + HDF_LOGE("%s: data is NULL", __func__); return HDF_ERR_INVALID_PARAM; } @@ -138,8 +140,9 @@ static int32_t GpioServiceIoSetIrq(struct HdfSBuf *data, struct HdfSBuf *reply) uint16_t gpio; uint16_t mode; - if (data == NULL || reply == NULL) { - HDF_LOGE("%s: data or reply is NULL", __func__); + (void)reply; + if (data == NULL) { + HDF_LOGE("%s: data is NULL", __func__); return HDF_ERR_INVALID_PARAM; } @@ -159,8 +162,8 @@ static int32_t GpioServiceIoSetIrq(struct HdfSBuf *data, struct HdfSBuf *reply) static int32_t GpioServiceIoUnsetIrq(struct HdfSBuf *data, struct HdfSBuf *reply) { uint16_t gpio; - (void)reply; + (void)reply; if (data == NULL) { HDF_LOGE("%s: data is NULL", __func__); return HDF_ERR_INVALID_PARAM; @@ -178,8 +181,8 @@ static int32_t GpioServiceIoEnableIrq(struct HdfSBuf *data, struct HdfSBuf *repl { int32_t ret; uint16_t gpio; - (void)reply; + (void)reply; if (data == NULL) { HDF_LOGE("%s: data is NULL", __func__); return HDF_ERR_INVALID_PARAM; @@ -203,8 +206,8 @@ static int32_t GpioServiceIoDisableIrq(struct HdfSBuf *data, struct HdfSBuf *rep { int32_t ret; uint16_t gpio; - (void)reply; + (void)reply; if (data == NULL) { HDF_LOGE("%s: data is NULL", __func__); return HDF_ERR_INVALID_PARAM; diff --git a/support/platform/src/hdmi/hdmi_ncts.c b/support/platform/src/hdmi/hdmi_ncts.c index 53a0a916..23c179f4 100644 --- a/support/platform/src/hdmi/hdmi_ncts.c +++ b/support/platform/src/hdmi/hdmi_ncts.c @@ -15,7 +15,7 @@ #define HDMI_NCTS_INVALID_VALUE 0xffffffff /* - * see hdmi1.4 table 7-1、7-2、7-3. + * see hdmi1.4 table 7-1, 7-2, 7-3. * The exact relationship: 128 * fs = tmdsClock * N / CTS. */ static struct HdmiAudioNCts g_audioNctsMap[] = { diff --git a/support/platform/src/i3c/i3c_core.c b/support/platform/src/i3c/i3c_core.c index e8dc70ae..3391ea1c 100644 --- a/support/platform/src/i3c/i3c_core.c +++ b/support/platform/src/i3c/i3c_core.c @@ -680,6 +680,7 @@ int32_t I3cCntlrIbiCallback(struct I3cDevice *device) if (device->ibi->ibiFunc == NULL) { HDF_LOGW("%s: device->ibi or ibiFunc is NULL!", __func__); + OsalMemFree(ibiData); return HDF_ERR_NOT_SUPPORT; } diff --git a/support/platform/src/rtc/rtc_core.c b/support/platform/src/rtc/rtc_core.c index 37a0c960..2da1a0e3 100644 --- a/support/platform/src/rtc/rtc_core.c +++ b/support/platform/src/rtc/rtc_core.c @@ -203,11 +203,13 @@ struct RtcHost *RtcHostCreate(struct HdfDeviceObject *device) void RtcHostDestroy(struct RtcHost *host) { - if (host != NULL) { - host->device = NULL; - host->method = NULL; - host->data = NULL; + if (host == NULL) { + HDF_LOGE("%s: host is NULL!", __func__); return; } + + host->device = NULL; + host->method = NULL; + host->data = NULL; OsalMemFree(host); -} \ No newline at end of file +} diff --git a/support/platform/src/rtc/rtc_if_u.c b/support/platform/src/rtc/rtc_if_u.c index fcc3ebd7..8b232f04 100644 --- a/support/platform/src/rtc/rtc_if_u.c +++ b/support/platform/src/rtc/rtc_if_u.c @@ -15,45 +15,33 @@ #define HDF_LOG_TAG rtc_if_u_c -static void RtcPutObjByPointer(const void *obj) -{ - if (obj == NULL) { - return; - } - HdfIoServiceRecycle((struct HdfIoService *)obj); -}; - DevHandle RtcOpen() { - void *host = NULL; + struct HdfIoService *service = NULL; - host = HdfIoServiceBind("HDF_PLATFORM_RTC"); - if (host == NULL) { + service = HdfIoServiceBind("HDF_PLATFORM_RTC"); + if (service == NULL) { HDF_LOGE("%s: rtc service bind fail", __func__); return NULL; } - return (DevHandle)host; + return (DevHandle)service; } void RtcClose(DevHandle handle) { - struct RtcHost *host = NULL; - if (handle == NULL) { HDF_LOGE("%s: handle is NULL", __func__); return; } - host = (struct RtcHost *)handle; - RtcPutObjByPointer(host); + HdfIoServiceRecycle((struct HdfIoService *)handle); } int32_t RtcReadTime(DevHandle handle, struct RtcTime *time) { int32_t ret; uint32_t len = 0; - struct RtcHost *host = NULL; struct HdfSBuf *reply = NULL; struct HdfIoService *service = NULL; struct RtcTime *temp = NULL; @@ -63,15 +51,13 @@ int32_t RtcReadTime(DevHandle handle, struct RtcTime *time) return HDF_ERR_INVALID_OBJECT; } - host = (struct RtcHost *)handle; - reply = HdfSbufObtainDefaultSize(); if (reply == NULL) { HDF_LOGE("%s: fail to obtain reply!", __func__); return HDF_ERR_MALLOC_FAIL; } - service = (struct HdfIoService *)host; + service = (struct HdfIoService *)handle; if (service == NULL || service->dispatcher == NULL || service->dispatcher->Dispatch == NULL) { HDF_LOGE("%s: service is invalid", __func__); ret = HDF_ERR_MALLOC_FAIL; @@ -110,7 +96,6 @@ EXIT: int32_t RtcWriteTime(DevHandle handle, const struct RtcTime *time) { int32_t ret; - struct RtcHost *host = NULL; struct HdfSBuf *data = NULL; struct HdfIoService *service = NULL; @@ -119,8 +104,6 @@ int32_t RtcWriteTime(DevHandle handle, const struct RtcTime *time) return HDF_ERR_INVALID_OBJECT; } - host = (struct RtcHost *)handle; - data = HdfSbufObtainDefaultSize(); if (data == NULL) { HDF_LOGE("%s: fail to obtain data", __func__); @@ -133,7 +116,7 @@ int32_t RtcWriteTime(DevHandle handle, const struct RtcTime *time) return HDF_ERR_IO; } - service = (struct HdfIoService *)host; + service = (struct HdfIoService *)handle; if (service == NULL || service->dispatcher == NULL || service->dispatcher->Dispatch == NULL) { HDF_LOGE("%s: service is invalid", __func__); HdfSbufRecycle(data); @@ -155,7 +138,6 @@ int32_t RtcReadAlarm(DevHandle handle, enum RtcAlarmIndex alarmIndex, struct Rtc { int32_t ret; uint32_t len = 0; - struct RtcHost *host = NULL; struct HdfSBuf *data = NULL; struct HdfSBuf *reply = NULL; struct RtcTime *temp = NULL; @@ -166,8 +148,6 @@ int32_t RtcReadAlarm(DevHandle handle, enum RtcAlarmIndex alarmIndex, struct Rtc return HDF_ERR_INVALID_OBJECT; } - host = (struct RtcHost *)handle; - data = HdfSbufObtainDefaultSize(); if (data == NULL) { HDF_LOGE("%s: fail to obtain data", __func__); @@ -187,7 +167,7 @@ int32_t RtcReadAlarm(DevHandle handle, enum RtcAlarmIndex alarmIndex, struct Rtc goto EXIT; } - service = (struct HdfIoService *)host; + service = (struct HdfIoService *)handle; if (service == NULL || service->dispatcher == NULL || service->dispatcher->Dispatch == NULL) { HDF_LOGE("%s: service is invalid", __func__); ret = HDF_ERR_MALLOC_FAIL; @@ -227,7 +207,6 @@ EXIT: int32_t RtcWriteAlarm(DevHandle handle, enum RtcAlarmIndex alarmIndex, const struct RtcTime *time) { int32_t ret; - struct RtcHost *host = NULL; struct HdfSBuf *data = NULL; struct HdfIoService *service = NULL; @@ -236,8 +215,6 @@ int32_t RtcWriteAlarm(DevHandle handle, enum RtcAlarmIndex alarmIndex, const str return HDF_ERR_INVALID_OBJECT; } - host = (struct RtcHost *)handle; - data = HdfSbufObtainDefaultSize(); if (data == NULL) { HDF_LOGE("%s: fail to obtain data", __func__); @@ -256,7 +233,7 @@ int32_t RtcWriteAlarm(DevHandle handle, enum RtcAlarmIndex alarmIndex, const str return HDF_ERR_IO; } - service = (struct HdfIoService *)host; + service = (struct HdfIoService *)handle; if (service == NULL || service->dispatcher == NULL || service->dispatcher->Dispatch == NULL) { HDF_LOGE("%s: service is invalid", __func__); HdfSbufRecycle(data); @@ -288,7 +265,6 @@ int32_t RtcRegisterAlarmCallback(DevHandle handle, enum RtcAlarmIndex alarmIndex int32_t RtcAlarmInterruptEnable(DevHandle handle, enum RtcAlarmIndex alarmIndex, uint8_t enable) { int32_t ret; - struct RtcHost *host = NULL; struct HdfSBuf *data = NULL; struct HdfIoService *service = NULL; @@ -297,8 +273,6 @@ int32_t RtcAlarmInterruptEnable(DevHandle handle, enum RtcAlarmIndex alarmIndex, return HDF_ERR_INVALID_OBJECT; } - host = (struct RtcHost *)handle; - data = HdfSbufObtainDefaultSize(); if (data == NULL) { HDF_LOGE("%s: fail to obtain data", __func__); @@ -317,7 +291,7 @@ int32_t RtcAlarmInterruptEnable(DevHandle handle, enum RtcAlarmIndex alarmIndex, return HDF_ERR_IO; } - service = (struct HdfIoService *)host; + service = (struct HdfIoService *)handle; if (service == NULL || service->dispatcher == NULL || service->dispatcher->Dispatch == NULL) { HDF_LOGE("%s: service is invalid", __func__); HdfSbufRecycle(data); @@ -338,7 +312,6 @@ int32_t RtcAlarmInterruptEnable(DevHandle handle, enum RtcAlarmIndex alarmIndex, int32_t RtcGetFreq(DevHandle handle, uint32_t *freq) { int32_t ret; - struct RtcHost *host = NULL; struct HdfSBuf *reply = NULL; struct HdfIoService *service = NULL; @@ -347,15 +320,13 @@ int32_t RtcGetFreq(DevHandle handle, uint32_t *freq) return HDF_ERR_INVALID_OBJECT; } - host = (struct RtcHost *)handle; - reply = HdfSbufObtainDefaultSize(); if (reply == NULL) { HDF_LOGE("%s: fail to obtain data", __func__); return HDF_ERR_MALLOC_FAIL; } - service = (struct HdfIoService *)host; + service = (struct HdfIoService *)handle; if (service == NULL || service->dispatcher == NULL || service->dispatcher->Dispatch == NULL) { HDF_LOGE("%s: service is invalid", __func__); ret = HDF_ERR_MALLOC_FAIL; @@ -381,7 +352,6 @@ EXIT: int32_t RtcSetFreq(DevHandle handle, uint32_t freq) { int32_t ret; - struct RtcHost *host = NULL; struct HdfSBuf *data = NULL; struct HdfIoService *service = NULL; @@ -390,8 +360,6 @@ int32_t RtcSetFreq(DevHandle handle, uint32_t freq) return HDF_ERR_INVALID_OBJECT; } - host = (struct RtcHost *)handle; - data = HdfSbufObtainDefaultSize(); if (data == NULL) { HDF_LOGE("%s: fail to obtain data", __func__); @@ -404,7 +372,7 @@ int32_t RtcSetFreq(DevHandle handle, uint32_t freq) return HDF_ERR_IO; } - service = (struct HdfIoService *)host; + service = (struct HdfIoService *)handle; if (service == NULL || service->dispatcher == NULL || service->dispatcher->Dispatch == NULL) { HDF_LOGE("%s: service is invalid", __func__); HdfSbufRecycle(data); @@ -425,7 +393,6 @@ int32_t RtcSetFreq(DevHandle handle, uint32_t freq) int32_t RtcReset(DevHandle handle) { int32_t ret; - struct RtcHost *host = NULL; struct HdfIoService *service = NULL; if (handle == NULL) { @@ -433,9 +400,7 @@ int32_t RtcReset(DevHandle handle) return HDF_ERR_INVALID_OBJECT; } - host = (struct RtcHost *)handle; - - service = (struct HdfIoService *)host; + service = (struct HdfIoService *)handle; if (service->dispatcher == NULL || service->dispatcher->Dispatch == NULL) { HDF_LOGE("%s: service is invalid", __func__); return HDF_ERR_INVALID_PARAM; @@ -453,7 +418,6 @@ int32_t RtcReset(DevHandle handle) int32_t RtcReadReg(DevHandle handle, uint8_t usrDefIndex, uint8_t *value) { int32_t ret; - struct RtcHost *host = NULL; struct HdfSBuf *data = NULL; struct HdfSBuf *reply = NULL; struct HdfIoService *service = NULL; @@ -463,8 +427,6 @@ int32_t RtcReadReg(DevHandle handle, uint8_t usrDefIndex, uint8_t *value) return HDF_ERR_INVALID_OBJECT; } - host = (struct RtcHost *)handle; - data = HdfSbufObtainDefaultSize(); if (data == NULL) { HDF_LOGE("%s: fail to obtain data", __func__); @@ -484,7 +446,7 @@ int32_t RtcReadReg(DevHandle handle, uint8_t usrDefIndex, uint8_t *value) goto EXIT; } - service = (struct HdfIoService *)host; + service = (struct HdfIoService *)handle; if (service == NULL || service->dispatcher == NULL || service->dispatcher->Dispatch == NULL) { HDF_LOGE("%s: service is invalid", __func__); ret = HDF_ERR_MALLOC_FAIL; @@ -512,7 +474,6 @@ EXIT: int32_t RtcWriteReg(DevHandle handle, uint8_t usrDefIndex, uint8_t value) { int32_t ret; - struct RtcHost *host = NULL; struct HdfSBuf *data = NULL; struct HdfIoService *service = NULL; @@ -521,8 +482,6 @@ int32_t RtcWriteReg(DevHandle handle, uint8_t usrDefIndex, uint8_t value) return HDF_ERR_INVALID_OBJECT; } - host = (struct RtcHost *)handle; - data = HdfSbufObtainDefaultSize(); if (data == NULL) { HDF_LOGE("%s: fail to obtain data", __func__); @@ -541,7 +500,7 @@ int32_t RtcWriteReg(DevHandle handle, uint8_t usrDefIndex, uint8_t value) return HDF_ERR_IO; } - service = (struct HdfIoService *)host; + service = (struct HdfIoService *)handle; if (service == NULL || service->dispatcher == NULL || service->dispatcher->Dispatch == NULL) { HDF_LOGE("%s: service is invalid", __func__); HdfSbufRecycle(data);