diff options
| author | guozhanxin <[email protected]> | 2019-06-13 16:01:20 +0800 |
|---|---|---|
| committer | guozhanxin <[email protected]> | 2019-06-13 16:01:23 +0800 |
| commit | 2600f82e397b1fba2b127511ef775f813875f0f6 (patch) | |
| tree | e0eedcdd437e3bdb6a20f684ccbf6ce332218522 /components/drivers | |
| parent | 44abc9099028c86c1bb9f53c3fb67b7b81dd837a (diff) | |
[sensor] Fixed error with mutex_lock take and release not matching.| 修复锁的获取和释放不对应的错误.
Diffstat (limited to 'components/drivers')
| -rw-r--r-- | components/drivers/sensors/sensor.c | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/components/drivers/sensors/sensor.c b/components/drivers/sensors/sensor.c index 67539d9410..818bf23164 100644 --- a/components/drivers/sensors/sensor.c +++ b/components/drivers/sensors/sensor.c @@ -139,6 +139,7 @@ static rt_err_t rt_sensor_open(rt_device_t dev, rt_uint16_t oflag) { rt_sensor_t sensor = (rt_sensor_t)dev; RT_ASSERT(dev != RT_NULL); + rt_err_t res = RT_EOK; if (sensor->module) { @@ -152,7 +153,8 @@ static rt_err_t rt_sensor_open(rt_device_t dev, rt_uint16_t oflag) sensor->data_buf = rt_malloc(sizeof(struct rt_sensor_data) * sensor->info.fifo_max); if (sensor->data_buf == RT_NULL) { - return -RT_ENOMEM; + res = -RT_ENOMEM; + goto __exit; } } @@ -186,12 +188,8 @@ static rt_err_t rt_sensor_open(rt_device_t dev, rt_uint16_t oflag) } else { - if (sensor->module) - { - /* release the module mutex */ - rt_mutex_release(sensor->module->lock); - } - return -RT_EINVAL; + res = -RT_EINVAL; + goto __exit; } /* Configure power mode to normal mode */ @@ -200,13 +198,14 @@ static rt_err_t rt_sensor_open(rt_device_t dev, rt_uint16_t oflag) sensor->config.power = RT_SENSOR_POWER_NORMAL; } +__exit: if (sensor->module) { /* release the module mutex */ rt_mutex_release(sensor->module->lock); } - return RT_EOK; + return res; } static rt_err_t rt_sensor_close(rt_device_t dev) |
