diff --git a/model/misc/vibrator/driver/chipset/vibrator_linear_driver.c b/model/misc/vibrator/driver/chipset/vibrator_linear_driver.c index 6f126069ece6d8f5dcfc15bc5e2689d0cc6e7584..b6959fca1960f76259fc71cfc29b166fb24dbe4a 100644 --- a/model/misc/vibrator/driver/chipset/vibrator_linear_driver.c +++ b/model/misc/vibrator/driver/chipset/vibrator_linear_driver.c @@ -82,9 +82,11 @@ static int32_t DispatchLinearVibrator(struct HdfDeviceIoClient *client, int32_t BindLinearVibratorDriver(struct HdfDeviceObject *device) { + struct VibratorLinearDriverData *drvData = NULL; + CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(device, HDF_FAILURE); - struct VibratorLinearDriverData *drvData = (struct VibratorLinearDriverData *)OsalMemCalloc(sizeof(*drvData)); + drvData = (struct VibratorLinearDriverData *)OsalMemCalloc(sizeof(*drvData)); CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_MALLOC_FAIL); drvData->ioService.Dispatch = DispatchLinearVibrator; @@ -99,6 +101,7 @@ static int32_t ParserLinearConfig(const struct DeviceResourceNode *node, struct { int32_t ret; struct DeviceResourceIface *parser = NULL; + const struct DeviceResourceNode *configNode = NULL; CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(node, HDF_FAILURE); CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(drvData, HDF_FAILURE); @@ -107,7 +110,7 @@ static int32_t ParserLinearConfig(const struct DeviceResourceNode *node, struct CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(parser, HDF_ERR_INVALID_PARAM); CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(parser->GetChildNode, HDF_ERR_INVALID_PARAM); - const struct DeviceResourceNode *configNode = parser->GetChildNode(node, "vibratorChipConfig"); + configNode = parser->GetChildNode(node, "vibratorChipConfig"); ret = parser->GetUint32(configNode, "busType", &drvData->busType, 0); CHECK_VIBRATOR_PARSER_RESULT_RETURN_VALUE(ret, "busType"); if (drvData->busType == VIBRATOR_BUS_GPIO) { @@ -128,10 +131,11 @@ static int32_t ParserLinearConfig(const struct DeviceResourceNode *node, struct int32_t InitLinearVibratorDriver(struct HdfDeviceObject *device) { static struct VibratorOps ops; + struct VibratorLinearDriverData *drvData = NULL; CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(device, HDF_FAILURE); - struct VibratorLinearDriverData *drvData = (struct VibratorLinearDriverData *)device->service; + drvData = (struct VibratorLinearDriverData *)device->service; CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(drvData, HDF_FAILURE); ops.Start = StartLinearVibrator; @@ -157,11 +161,13 @@ int32_t InitLinearVibratorDriver(struct HdfDeviceObject *device) void ReleaseLinearVibratorDriver(struct HdfDeviceObject *device) { + struct VibratorLinearDriverData *drvData = NULL; + if (device == NULL) { HDF_LOGE("%s: Device is null", __func__); return; } - struct VibratorLinearDriverData *drvData = (struct VibratorLinearDriverData *)device->service; + drvData = (struct VibratorLinearDriverData *)device->service; if (drvData == NULL) { HDF_LOGE("%s: DrvData pointer is null", __func__); return; diff --git a/model/sensor/driver/common/src/sensor_config_parser.c b/model/sensor/driver/common/src/sensor_config_parser.c index 31efd2f1361ca2ec98d21c19a5ead6f01489f73a..b4984976c61638f34fed045f8abfb26c4a4145af 100644 --- a/model/sensor/driver/common/src/sensor_config_parser.c +++ b/model/sensor/driver/common/src/sensor_config_parser.c @@ -63,18 +63,20 @@ static int32_t ParseSensorRegItem(struct DeviceResourceIface *parser, const stru int32_t ret; int32_t step; int32_t index; + int32_t num; int32_t itemNum = group->itemNum; + uint16_t *buf = NULL; CHECK_NULL_PTR_RETURN_VALUE(group->regCfgItem, HDF_ERR_INVALID_PARAM); CHECK_NULL_PTR_RETURN_VALUE(groupName, HDF_ERR_INVALID_PARAM); - int32_t num = parser->GetElemNum(regNode, groupName); + num = parser->GetElemNum(regNode, groupName); if (num <= 0 || num > SENSOR_CONFIG_MAX_ITEM) { HDF_LOGE("%s: parser %s element num failed", __func__, groupName); return HDF_SUCCESS; } - uint16_t *buf = (uint16_t *)OsalMemCalloc(sizeof(uint16_t) * num); + buf = (uint16_t *)OsalMemCalloc(sizeof(uint16_t) * num); CHECK_NULL_PTR_RETURN_VALUE(buf, HDF_ERR_MALLOC_FAIL); ret = parser->GetUint16Array(regNode, groupName, buf, num, 0); @@ -108,6 +110,7 @@ static int32_t ParseSensorRegItem(struct DeviceResourceIface *parser, const stru static int32_t ParseSensorRegGroup(struct DeviceResourceIface *parser, const struct DeviceResourceNode *regCfgNode, const char *groupName, struct SensorRegCfgGroupNode **groupNode) { + int32_t num; struct SensorRegCfgGroupNode *group = NULL; CHECK_NULL_PTR_RETURN_VALUE(parser, HDF_ERR_INVALID_PARAM); @@ -115,7 +118,7 @@ static int32_t ParseSensorRegGroup(struct DeviceResourceIface *parser, const str CHECK_NULL_PTR_RETURN_VALUE(groupName, HDF_ERR_INVALID_PARAM); CHECK_NULL_PTR_RETURN_VALUE(groupNode, HDF_ERR_INVALID_PARAM); - int32_t num = parser->GetElemNum(regCfgNode, groupName); + num = parser->GetElemNum(regCfgNode, groupName); group = *groupNode; if (num > 0) { @@ -246,13 +249,14 @@ int32_t DetectSensorDevice(struct SensorCfgData *config) uint8_t value = 0; uint16_t chipIdReg; uint16_t chipIdValue; + int32_t ret; CHECK_NULL_PTR_RETURN_VALUE(config, HDF_ERR_INVALID_PARAM); chipIdReg = config->sensorAttr.chipIdReg; chipIdValue = config->sensorAttr.chipIdValue; - int32_t ret = GetSensorBusHandle(&config->busCfg); + ret = GetSensorBusHandle(&config->busCfg); if (ret != HDF_SUCCESS) { HDF_LOGE("%s: get sensor bus handle failed", __func__); (void)ReleaseSensorBusHandle(&config->busCfg); @@ -280,6 +284,8 @@ static int32_t ParseSensorInfo(struct DeviceResourceIface *parser, const struct struct SensorCfgData *config) { int32_t ret; + uint16_t id; + int32_t value; const char *name = NULL; ret = parser->GetString(infoNode, "sensorName", &name, NULL); @@ -310,7 +316,6 @@ static int32_t ParseSensorInfo(struct DeviceResourceIface *parser, const struct return HDF_FAILURE; } - uint16_t id; ret = parser->GetUint16(infoNode, "sensorTypeId", &id, 0); CHECK_PARSER_RESULT_RETURN_VALUE(ret, "sensorTypeId"); config->sensorInfo.sensorTypeId = id; @@ -318,7 +323,6 @@ static int32_t ParseSensorInfo(struct DeviceResourceIface *parser, const struct CHECK_PARSER_RESULT_RETURN_VALUE(ret, "sensorId"); config->sensorInfo.sensorId = id; - int32_t value; ret = parser->GetUint32(infoNode, "maxRange", (uint32_t *)&value, 0); CHECK_PARSER_RESULT_RETURN_VALUE(ret, "maxRange"); config->sensorInfo.maxRange = value; @@ -377,6 +381,9 @@ int32_t GetSensorBaseConfigData(const struct DeviceResourceNode *node, struct Se { int32_t ret; struct DeviceResourceIface *parser = NULL; + const struct DeviceResourceNode *infoNode = NULL; + const struct DeviceResourceNode *busNode = NULL; + const struct DeviceResourceNode *attrNode = NULL; CHECK_NULL_PTR_RETURN_VALUE(node, HDF_ERR_INVALID_PARAM); CHECK_NULL_PTR_RETURN_VALUE(config, HDF_ERR_INVALID_PARAM); @@ -387,19 +394,19 @@ int32_t GetSensorBaseConfigData(const struct DeviceResourceNode *node, struct Se config->root = node; CHECK_NULL_PTR_RETURN_VALUE(parser->GetChildNode, HDF_ERR_INVALID_PARAM); - const struct DeviceResourceNode *infoNode = parser->GetChildNode(node, "sensorInfo"); + infoNode = parser->GetChildNode(node, "sensorInfo"); if (infoNode != NULL) { ret = ParseSensorInfo(parser, infoNode, config); CHECK_PARSER_RESULT_RETURN_VALUE(ret, "sensorInfo"); } - const struct DeviceResourceNode *busNode = parser->GetChildNode(node, "sensorBusConfig"); + busNode = parser->GetChildNode(node, "sensorBusConfig"); if (busNode != NULL) { ret = ParseSensorBus(parser, busNode, config); CHECK_PARSER_RESULT_RETURN_VALUE(ret, "sensorBusConfig"); } - const struct DeviceResourceNode *attrNode = parser->GetChildNode(node, "sensorIdAttr"); + attrNode = parser->GetChildNode(node, "sensorIdAttr"); if (attrNode != NULL) { ret = ParseSensorAttr(parser, attrNode, config); CHECK_PARSER_RESULT_RETURN_VALUE(ret, "sensorIdAttr"); diff --git a/model/sensor/driver/common/src/sensor_device_manager.c b/model/sensor/driver/common/src/sensor_device_manager.c index 8c3389392029b559e09845fdc80652cccd77b259..e72dd5db2e4a56d6930abd200adacc4c2669bfaa 100644 --- a/model/sensor/driver/common/src/sensor_device_manager.c +++ b/model/sensor/driver/common/src/sensor_device_manager.c @@ -88,14 +88,16 @@ int32_t DeleteSensorDevice(const struct SensorBasicInfo *sensorBaseInfo) int32_t ReportSensorEvent(const struct SensorReportEvent *events) { int32_t ret; + struct SensorDevMgrData *manager = NULL; + struct HdfSBuf *msg = NULL; CHECK_NULL_PTR_RETURN_VALUE(events, HDF_ERR_INVALID_PARAM); - struct SensorDevMgrData *manager = GetSensorDeviceManager(); + manager = GetSensorDeviceManager(); CHECK_NULL_PTR_RETURN_VALUE(manager, HDF_ERR_INVALID_PARAM); (void)OsalMutexLock(&manager->eventMutex); - struct HdfSBuf *msg = HdfSBufObtain(HDF_SENSOR_EVENT_MAX_BUF); + msg = HdfSBufObtain(HDF_SENSOR_EVENT_MAX_BUF); if (msg == NULL) { (void)OsalMutexUnlock(&manager->eventMutex); return HDF_ERR_INVALID_PARAM; @@ -128,11 +130,14 @@ EXIT: static int32_t GetAllSensorInfo(struct HdfSBuf *data, struct HdfSBuf *reply) { - (void)data; + int32_t count = 0; struct SensorDevInfoNode *pos = NULL; struct SensorBasicInfo *sensorInfo = NULL; - struct SensorDevMgrData *manager = GetSensorDeviceManager(); - int32_t count = 0; + struct SensorDevMgrData *manager = NULL; + + (void)data; + + manager = GetSensorDeviceManager(); CHECK_NULL_PTR_RETURN_VALUE(reply, HDF_ERR_INVALID_PARAM); CHECK_NULL_PTR_RETURN_VALUE(manager, HDF_ERR_INVALID_PARAM); @@ -303,9 +308,11 @@ static int32_t DispatchSensor(struct HdfDeviceIoClient *client, int32_t BindSensorDevManager(struct HdfDeviceObject *device) { + struct SensorDevMgrData *manager = NULL; + CHECK_NULL_PTR_RETURN_VALUE(device, HDF_ERR_INVALID_PARAM); - struct SensorDevMgrData *manager = (struct SensorDevMgrData *)OsalMemCalloc(sizeof(*manager)); + manager = (struct SensorDevMgrData *)OsalMemCalloc(sizeof(*manager)); if (manager == NULL) { HDF_LOGE("%s: malloc manager fail!", __func__); return HDF_ERR_MALLOC_FAIL; @@ -321,8 +328,10 @@ int32_t BindSensorDevManager(struct HdfDeviceObject *device) int32_t InitSensorDevManager(struct HdfDeviceObject *device) { + struct SensorDevMgrData *manager = NULL; + CHECK_NULL_PTR_RETURN_VALUE(device, HDF_ERR_INVALID_PARAM); - struct SensorDevMgrData *manager = (struct SensorDevMgrData *)device->service; + manager = (struct SensorDevMgrData *)device->service; CHECK_NULL_PTR_RETURN_VALUE(manager, HDF_ERR_INVALID_PARAM); DListHeadInit(&manager->sensorDevInfoHead); @@ -347,11 +356,13 @@ int32_t InitSensorDevManager(struct HdfDeviceObject *device) void ReleaseSensorDevManager(struct HdfDeviceObject *device) { - CHECK_NULL_PTR_RETURN(device); - struct SensorDevInfoNode *pos = NULL; struct SensorDevInfoNode *tmp = NULL; - struct SensorDevMgrData *manager = (struct SensorDevMgrData *)device->service; + struct SensorDevMgrData *manager = NULL; + + CHECK_NULL_PTR_RETURN(device); + + manager = (struct SensorDevMgrData *)device->service; CHECK_NULL_PTR_RETURN(manager); DLIST_FOR_EACH_ENTRY_SAFE(pos, tmp, &manager->sensorDevInfoHead, struct SensorDevInfoNode, node) { diff --git a/test/unittest/common/hdf_main_test.c b/test/unittest/common/hdf_main_test.c index 19911d9f77b8898855d5d954d2aabc6f7aea455a..d7931a49e6e3029048411ebce7823d580b6a6d66 100644 --- a/test/unittest/common/hdf_main_test.c +++ b/test/unittest/common/hdf_main_test.c @@ -190,13 +190,14 @@ void HdfTestDriverDispatch(struct HdfDeviceObject *device) int HdfTestDriverBind(struct HdfDeviceObject *device) { + static struct TestService testService; + if (device == NULL) { return -1; } - static struct TestService testService = { - .testRemoteService.Dispatch = HdfTestCaseProcess, - }; + testService.testRemoteService.Dispatch = HdfTestCaseProcess; + device->service = &testService.testRemoteService; return 0; } diff --git a/test/unittest/sensor/hdf_sensor_test.c b/test/unittest/sensor/hdf_sensor_test.c index ce89c9eb3dcb9e0db9ed96cffbe9178214b1ae89..85871a99886260c14bc98f0b1d7a56e4532825df 100644 --- a/test/unittest/sensor/hdf_sensor_test.c +++ b/test/unittest/sensor/hdf_sensor_test.c @@ -141,8 +141,10 @@ static int32_t SensorDisableTest(void) static int32_t SensorSetBatchTest(int64_t samplingInterval, int64_t interval) { + struct SensorTestDrvData *drvData = NULL; (void)interval; - struct SensorTestDrvData *drvData = GetSensorTestDrvData(); + + drvData = GetSensorTestDrvData(); drvData->interval = samplingInterval; return HDF_SUCCESS; @@ -172,12 +174,13 @@ static int32_t SensorTestDispatch(struct HdfDeviceIoClient *client, int32_t BindSensorDriverTest(struct HdfDeviceObject *device) { - CHECK_NULL_PTR_RETURN_VALUE(device, HDF_ERR_INVALID_PARAM); - static struct IDeviceIoService service = { .object = {0}, .Dispatch = SensorTestDispatch, }; + + CHECK_NULL_PTR_RETURN_VALUE(device, HDF_ERR_INVALID_PARAM); + device->service = &service; return HDF_SUCCESS; } @@ -185,8 +188,6 @@ int32_t BindSensorDriverTest(struct HdfDeviceObject *device) int32_t InitSensorDriverTest(struct HdfDeviceObject *device) { int32_t ret; - (void)device; - struct SensorDeviceInfo deviceInfo = { .sensorInfo = { .sensorName = "sensor_test", @@ -208,6 +209,8 @@ int32_t InitSensorDriverTest(struct HdfDeviceObject *device) }, }; + (void)device; + ret = SensorInitTestConfig(); if (ret != HDF_SUCCESS) { HDF_LOGE("%s: sensor test config failed", __func__); @@ -226,9 +229,8 @@ int32_t InitSensorDriverTest(struct HdfDeviceObject *device) void ReleaseSensorDriverTest(struct HdfDeviceObject *device) { - (void)device; int32_t ret; - struct SensorTestDrvData *drvData = GetSensorTestDrvData(); + struct SensorTestDrvData *drvData = NULL; struct SensorDeviceInfo deviceInfo = { .sensorInfo = { .sensorName = "sensor_test", @@ -242,6 +244,8 @@ void ReleaseSensorDriverTest(struct HdfDeviceObject *device) .power = SENSOR_TEST_MAX_POWER, } }; + drvData = GetSensorTestDrvData(); + (void)device; (void)DeleteSensorDevice(&deviceInfo.sensorInfo); if (drvData->timer.realTimer != NULL) {