Commit 883f6165 authored by Lars Möllendorf's avatar Lars Möllendorf Committed by Greg Kroah-Hartman

iio: buffer: align the size of scan bytes to size of the largest element

Previous versions of `iio_compute_scan_bytes` only aligned each element
to its own length (i.e. its own natural alignment). Because multiple
consecutive sets of scan elements are buffered this does not work in
case the computed scan bytes do not align with the natural alignment of
the first scan element in the set.

This commit fixes this by aligning the scan bytes to the natural
alignment of the largest scan element in the set.

Fixes: 959d2952 ("staging:iio: make iio_sw_buffer_preenable much more general.")
Signed-off-by: default avatarLars Möllendorf <lars.moellendorf@plating.de>
Reviewed-by: default avatarLars-Peter Clausen <lars@metafoo.de>
Cc: <Stable@vger.kernel.org>
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 217afe63
...@@ -566,7 +566,7 @@ static int iio_compute_scan_bytes(struct iio_dev *indio_dev, ...@@ -566,7 +566,7 @@ static int iio_compute_scan_bytes(struct iio_dev *indio_dev,
const unsigned long *mask, bool timestamp) const unsigned long *mask, bool timestamp)
{ {
unsigned bytes = 0; unsigned bytes = 0;
int length, i; int length, i, largest = 0;
/* How much space will the demuxed element take? */ /* How much space will the demuxed element take? */
for_each_set_bit(i, mask, for_each_set_bit(i, mask,
...@@ -574,13 +574,17 @@ static int iio_compute_scan_bytes(struct iio_dev *indio_dev, ...@@ -574,13 +574,17 @@ static int iio_compute_scan_bytes(struct iio_dev *indio_dev,
length = iio_storage_bytes_for_si(indio_dev, i); length = iio_storage_bytes_for_si(indio_dev, i);
bytes = ALIGN(bytes, length); bytes = ALIGN(bytes, length);
bytes += length; bytes += length;
largest = max(largest, length);
} }
if (timestamp) { if (timestamp) {
length = iio_storage_bytes_for_timestamp(indio_dev); length = iio_storage_bytes_for_timestamp(indio_dev);
bytes = ALIGN(bytes, length); bytes = ALIGN(bytes, length);
bytes += length; bytes += length;
largest = max(largest, length);
} }
bytes = ALIGN(bytes, largest);
return bytes; return bytes;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment