From 46ea549630dcbca5429e0ad6db2b4dafd8788f6a Mon Sep 17 00:00:00 2001 From: Jiuzhu Dong Date: Sun, 7 Feb 2021 17:13:31 +0800 Subject: [PATCH] driver/sensor: Fetch(with O_NONBLOCK) will directly return. when sensor is disable. Change-Id: I02c02aa447ee0b0d681082b4209ecd36e10f2547 Signed-off-by: Jiuzhu Dong --- drivers/sensors/sensor.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/sensors/sensor.c b/drivers/sensors/sensor.c index e6ed29ad74..f54bf8a2b6 100644 --- a/drivers/sensors/sensor.c +++ b/drivers/sensors/sensor.c @@ -273,6 +273,11 @@ static ssize_t sensor_read(FAR struct file *filep, FAR char *buffer, return ret; } } + else if (!upper->enabled) + { + ret = -EAGAIN; + goto out; + } ret = lower->ops->fetch(lower, buffer, len); } @@ -289,7 +294,7 @@ static ssize_t sensor_read(FAR struct file *filep, FAR char *buffer, if (filep->f_oflags & O_NONBLOCK) { ret = -EAGAIN; - goto again; + goto out; } else { @@ -324,7 +329,7 @@ static ssize_t sensor_read(FAR struct file *filep, FAR char *buffer, } } -again: +out: nxsem_post(&upper->exclsem); return ret; }