Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

iio: buffer: Fix demux update

When updating the buffer demux, we will skip a scan element from the
device in the case `in_ind != out_ind` and we enter the while loop.
in_ind should only be refreshed with `find_next_bit()` in the end of the
loop.

Note, to cause problems we need a situation where we are skippig over
an element (channel not enabled) that happens to not have the same size
as the next element. Whilst this is a possible situation we haven't
actually identified any cases in mainline where it happens as most drivers
have consistent channel storage sizes with the exception of the timestamp
which is the last element and hence never skipped over.

Fixes: 5ada4ea9be16 ("staging:iio: add demux optionally to path from device to buffer")
Signed-off-by: Nuno Sá <nuno.sa@analog.com>
Link: https://lore.kernel.org/r/20201112144323.28887-1-nuno.sa@analog.com
Cc: <Stable@vger.kernel.org>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Nuno Sá and committed by
Jonathan Cameron
19ef7b70 e08b60d3

+3 -3
+3 -3
drivers/iio/industrialio-buffer.c
··· 853 853 indio_dev->masklength, 854 854 in_ind + 1); 855 855 while (in_ind != out_ind) { 856 - in_ind = find_next_bit(indio_dev->active_scan_mask, 857 - indio_dev->masklength, 858 - in_ind + 1); 859 856 length = iio_storage_bytes_for_si(indio_dev, in_ind); 860 857 /* Make sure we are aligned */ 861 858 in_loc = roundup(in_loc, length) + length; 859 + in_ind = find_next_bit(indio_dev->active_scan_mask, 860 + indio_dev->masklength, 861 + in_ind + 1); 862 862 } 863 863 length = iio_storage_bytes_for_si(indio_dev, in_ind); 864 864 out_loc = roundup(out_loc, length);