[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20200618010805.600873-127-sashal@kernel.org>
Date: Wed, 17 Jun 2020 21:03:44 -0400
From: Sasha Levin <sashal@...nel.org>
To: linux-kernel@...r.kernel.org, stable@...r.kernel.org
Cc: Lars-Peter Clausen <lars@...afoo.de>,
Alexandru Ardelean <alexandru.ardelean@...log.com>,
Jonathan Cameron <Jonathan.Cameron@...wei.com>,
Sasha Levin <sashal@...nel.org>, linux-iio@...r.kernel.org
Subject: [PATCH AUTOSEL 5.7 127/388] iio: buffer: Don't allow buffers without any channels enabled to be activated
From: Lars-Peter Clausen <lars@...afoo.de>
[ Upstream commit b7329249ea5b08b2a1c2c3f24a2f4c495c4f14b8 ]
Before activating a buffer make sure that at least one channel is enabled.
Activating a buffer with 0 channels enabled doesn't make too much sense and
disallowing this case makes sure that individual driver don't have to add
special case code to handle it.
Currently, without this patch enabling a buffer is possible and no error is
produced. With this patch -EINVAL is returned.
An example of execution with this patch and some instrumented print-code:
root@...log:~# cd /sys/bus/iio/devices/iio\:device3/buffer
root@...log:/sys/bus/iio/devices/iio:device3/buffer# echo 1 > enable
0: iio_verify_update 748 indio_dev->masklength 2 *insert_buffer->scan_mask 00000000
1: iio_verify_update 753
2:__iio_update_buffers 1115 ret -22
3: iio_buffer_store_enable 1241 ret -22
-bash: echo: write error: Invalid argument
1, 2 & 3 are exit-error paths. 0 the first print in iio_verify_update()
rergardless of error path.
Without this patch (and same instrumented print-code):
root@...log:~# cd /sys/bus/iio/devices/iio\:device3/buffer
root@...log:/sys/bus/iio/devices/iio:device3/buffer# echo 1 > enable
0: iio_verify_update 748 indio_dev->masklength 2 *insert_buffer->scan_mask 00000000
root@...log:/sys/bus/iio/devices/iio:device3/buffer#
Buffer is enabled with no error.
Note from Jonathan: Probably not suitable for automatic application to stable.
This has been there from the very start. It tidies up an odd corner
case but won't effect any 'real' users.
Fixes: 84b36ce5f79c0 ("staging:iio: Add support for multiple buffers")
Signed-off-by: Lars-Peter Clausen <lars@...afoo.de>
Signed-off-by: Alexandru Ardelean <alexandru.ardelean@...log.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@...wei.com>
Signed-off-by: Sasha Levin <sashal@...nel.org>
---
drivers/iio/industrialio-buffer.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c
index 4ada5592aa2b..7c0004b5a4bb 100644
--- a/drivers/iio/industrialio-buffer.c
+++ b/drivers/iio/industrialio-buffer.c
@@ -687,6 +687,13 @@ static int iio_verify_update(struct iio_dev *indio_dev,
bool scan_timestamp;
unsigned int modes;
+ if (insert_buffer &&
+ bitmap_empty(insert_buffer->scan_mask, indio_dev->masklength)) {
+ dev_dbg(&indio_dev->dev,
+ "At least one scan element must be enabled first\n");
+ return -EINVAL;
+ }
+
memset(config, 0, sizeof(*config));
config->watermark = ~0;
--
2.25.1
Powered by blists - more mailing lists