From a03495013902038e9a6cd97d71581ce87678a62d Mon Sep 17 00:00:00 2001 From: YOUR_NAME Date: Mon, 26 Jul 2021 07:11:32 +0000 Subject: [PATCH] Deal with CodeDex warning Signed-off-by: YOUR_NAME --- model/input/driver/hdf_hid_adapter.c | 38 ++++++++++++++----- model/input/driver/hdf_input_device_manager.c | 2 +- model/input/driver/hdf_touch.c | 4 +- 3 files changed, 31 insertions(+), 13 deletions(-) diff --git a/model/input/driver/hdf_hid_adapter.c b/model/input/driver/hdf_hid_adapter.c index bfd7a771a..3446117c4 100644 --- a/model/input/driver/hdf_hid_adapter.c +++ b/model/input/driver/hdf_hid_adapter.c @@ -14,6 +14,13 @@ #include "hdf_input_device_manager.h" #include "hdf_hid_adapter.h" +#define MEMCPY_CHECK_RETURN(ret) do { \ + if ((ret) != 0) { \ + HDF_LOGE("%s: memcpy failed, line %d", __func__, __LINE__); \ + return; \ + } \ +} while (0) + InputDevice *cachedHid[MAX_INPUT_DEV_NUM]; HidInfo *g_cachedInfo[MAX_INPUT_DEV_NUM]; @@ -94,6 +101,7 @@ static void SetInputDevAbility(InputDevice *inputDev) HidInfo *info = NULL; int32_t id = 0; uint32_t len; + int32_t ret; while (id < MAX_INPUT_DEV_NUM) { if(g_cachedInfo[id] != NULL && !strcmp(inputDev->devName, g_cachedInfo[id]->devName)) { info = g_cachedInfo[id]; @@ -106,26 +114,36 @@ static void SetInputDevAbility(InputDevice *inputDev) return; } len = sizeof(unsigned long); - memcpy_s(inputDev->abilitySet.devProp, len * BITS_TO_LONG(INPUT_PROP_CNT), + ret = memcpy_s(inputDev->abilitySet.devProp, len * BITS_TO_LONG(INPUT_PROP_CNT), info->devProp, len * BITS_TO_LONG(INPUT_PROP_CNT)); - memcpy_s(inputDev->abilitySet.eventType, len * BITS_TO_LONG(EV_CNT), + MEMCPY_CHECK_RETURN(ret); + ret = memcpy_s(inputDev->abilitySet.eventType, len * BITS_TO_LONG(EV_CNT), info->eventType, len * BITS_TO_LONG(EV_CNT)); - memcpy_s(inputDev->abilitySet.absCode, len * BITS_TO_LONG(ABS_CNT), + MEMCPY_CHECK_RETURN(ret); + ret = memcpy_s(inputDev->abilitySet.absCode, len * BITS_TO_LONG(ABS_CNT), info->absCode, len * BITS_TO_LONG(ABS_CNT)); - memcpy_s(inputDev->abilitySet.relCode, len * BITS_TO_LONG(REL_CNT), + MEMCPY_CHECK_RETURN(ret); + ret = memcpy_s(inputDev->abilitySet.relCode, len * BITS_TO_LONG(REL_CNT), info->relCode, len * BITS_TO_LONG(REL_CNT)); - memcpy_s(inputDev->abilitySet.keyCode, len * BITS_TO_LONG(KEY_CNT), + MEMCPY_CHECK_RETURN(ret); + ret = memcpy_s(inputDev->abilitySet.keyCode, len * BITS_TO_LONG(KEY_CNT), info->keyCode, len * BITS_TO_LONG(KEY_CNT)); - memcpy_s(inputDev->abilitySet.ledCode, len * BITS_TO_LONG(LED_CNT), + MEMCPY_CHECK_RETURN(ret); + ret = memcpy_s(inputDev->abilitySet.ledCode, len * BITS_TO_LONG(LED_CNT), info->ledCode, len * BITS_TO_LONG(LED_CNT)); - memcpy_s(inputDev->abilitySet.miscCode, len * BITS_TO_LONG(MSC_CNT), + MEMCPY_CHECK_RETURN(ret); + ret = memcpy_s(inputDev->abilitySet.miscCode, len * BITS_TO_LONG(MSC_CNT), info->miscCode, len * BITS_TO_LONG(MSC_CNT)); - memcpy_s(inputDev->abilitySet.soundCode, len * BITS_TO_LONG(SND_CNT), + MEMCPY_CHECK_RETURN(ret); + ret = memcpy_s(inputDev->abilitySet.soundCode, len * BITS_TO_LONG(SND_CNT), info->soundCode, len * BITS_TO_LONG(SND_CNT)); - memcpy_s(inputDev->abilitySet.forceCode, len * BITS_TO_LONG(FF_CNT), + MEMCPY_CHECK_RETURN(ret); + ret = memcpy_s(inputDev->abilitySet.forceCode, len * BITS_TO_LONG(FF_CNT), info->forceCode, len * BITS_TO_LONG(FF_CNT)); - memcpy_s(inputDev->abilitySet.switchCode, len * BITS_TO_LONG(SW_CNT), + MEMCPY_CHECK_RETURN(ret); + ret = memcpy_s(inputDev->abilitySet.switchCode, len * BITS_TO_LONG(SW_CNT), info->switchCode, len * BITS_TO_LONG(SW_CNT)); + MEMCPY_CHECK_RETURN(ret); inputDev->attrSet.id.busType = info->bustype; inputDev->attrSet.id.vendor = info->vendor; diff --git a/model/input/driver/hdf_input_device_manager.c b/model/input/driver/hdf_input_device_manager.c index 4d449b6c1..7e3a60b6e 100644 --- a/model/input/driver/hdf_input_device_manager.c +++ b/model/input/driver/hdf_input_device_manager.c @@ -91,10 +91,10 @@ static int32_t CreateDeviceNode(InputDevice *inputDev) if (IsHidDevice(inputDev->devType)) { HDF_LOGI("%s: prepare to register hdf device", __func__); inputDev->hdfDevObj = HidRegisterHdfDevice(inputDev); - inputDev->hdfDevObj->priv = (void *)inputDev; if (inputDev->hdfDevObj == NULL) { return HDF_DEV_ERR_NO_DEVICE; } + inputDev->hdfDevObj->priv = (void *)inputDev; } HDF_LOGI("%s: create node succ, devId is %d ", __func__, inputDev->devId); diff --git a/model/input/driver/hdf_touch.c b/model/input/driver/hdf_touch.c index ad862cbd8..8d2f17078 100644 --- a/model/input/driver/hdf_touch.c +++ b/model/input/driver/hdf_touch.c @@ -393,7 +393,7 @@ static int32_t TouchGetDevType(TouchDriver *driver, struct HdfSBuf *reply) static int32_t TouchSetPowerStatus(TouchDriver *driver, struct HdfSBuf *data) { - uint32_t pwrStatus; + uint32_t pwrStatus = 0; bool ret = HdfSbufReadUint32(data, &pwrStatus); if (!ret) { HDF_LOGE("%s: HdfSbufWriteUint32 failed", __func__); @@ -483,7 +483,7 @@ static int32_t TouchGetDeviceAbility(TouchDriver *driver, struct HdfSBuf *reply) static int32_t TouchSetGestureMode(TouchDriver *driver, struct HdfSBuf *data) { - uint32_t gestureMode; + uint32_t gestureMode = 0; bool ret = HdfSbufReadUint32(data, &gestureMode); if (!ret) { HDF_LOGE("%s: HdfSbufWriteUint32 failed", __func__); -- Gitee