[sensor] Fixed error with mutex_lock take and release not matching.| 修复锁的获取和释放不对应的错误.

This commit is contained in:
guozhanxin 2019-06-13 16:01:20 +08:00
parent 44abc90990
commit 2600f82e39
1 changed files with 7 additions and 8 deletions

View File

@ -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)