Skip to content

Commit b732924

Browse files
larsclausenJonathan Cameron
authored andcommitted
iio: buffer: Don't allow buffers without any channels enabled to be activated
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@analog:~# cd /sys/bus/iio/devices/iio\:device3/buffer root@analog:/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@analog:~# cd /sys/bus/iio/devices/iio\:device3/buffer root@analog:/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@analog:/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: 84b36ce ("staging:iio: Add support for multiple buffers") Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
1 parent 3dee042 commit b732924

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

‎drivers/iio/industrialio-buffer.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,13 @@ static int iio_verify_update(struct iio_dev *indio_dev,
686686
bool scan_timestamp;
687687
unsigned int modes;
688688

689+
if (insert_buffer &&
690+
bitmap_empty(insert_buffer->scan_mask, indio_dev->masklength)) {
691+
dev_dbg(&indio_dev->dev,
692+
"At least one scan element must be enabled first\n");
693+
return -EINVAL;
694+
}
695+
689696
memset(config, 0, sizeof(*config));
690697
config->watermark = ~0;
691698

0 commit comments

Comments
 (0)