Re: [PATCH v4 1/5] tools: iio: iio_generic_buffer ensure alignment
From: Andy Shevchenko
Date: Wed Sep 27 2023 - 08:28:15 EST
On Wed, Sep 27, 2023 at 11:26:07AM +0300, Matti Vaittinen wrote:
> The iio_generic_buffer can return garbage values when the total size of
> scan data is not a multiple of the largest element in the scan. This can be
> demonstrated by reading a scan, consisting, for example of one 4-byte and
> one 2-byte element, where the 4-byte element is first in the buffer.
>
> The IIO generic buffer code does not take into account the last two
> padding bytes that are needed to ensure that the 4-byte data for next
> scan is correctly aligned.
>
> Add the padding bytes required to align the next sample with the scan size.
...
> + /*
> + * We wan't the data in next sample to also be properly aligned so
Pardon me, won't or want, I didn't get?..
> + * we'll add padding at the end if needed.
> + *
> + * Please note, this code does ensure alignment to maximum channel
> + * size. It works only as long as the channel sizes are 1, 2, 4 or 8
> + * bytes. Also, on 32 bit platforms it might be enough to align also
32-bit
> + * the 8 byte elements to 4 byte boundary - which this code is not
8-byte
4-byte
> + * doing.
> + */
--
With Best Regards,
Andy Shevchenko