From 2600f82e397b1fba2b127511ef775f813875f0f6 Mon Sep 17 00:00:00 2001 From: guozhanxin Date: Thu, 13 Jun 2019 16:01:20 +0800 Subject: [PATCH] =?UTF-8?q?[sensor]=20Fixed=20error=20with=20mutex=5Flock?= =?UTF-8?q?=20take=20and=20release=20not=20matching.|=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E9=94=81=E7=9A=84=E8=8E=B7=E5=8F=96=E5=92=8C=E9=87=8A=E6=94=BE?= =?UTF-8?q?=E4=B8=8D=E5=AF=B9=E5=BA=94=E7=9A=84=E9=94=99=E8=AF=AF.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/drivers/sensors/sensor.c | 15 +++++++-------- 1 file 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)