Re: [PATCH 4/4] iio: buffer: fix timestamp alignment when quaternion in scan
From: David Lechner
Date: Mon Mar 02 2026 - 10:45:36 EST
On 3/2/26 2:47 AM, Andy Shevchenko wrote:
> On Sun, Mar 01, 2026 at 02:24:53PM -0600, David Lechner wrote:
>> Fix timestamp alignment when a scan buffer contains an element larger
>> than sizeof(int64_t). Currently s32 quaternions are the only such
>> element, and the one driver that has this (hid-sensor-rotation) has a
>> workaround in place already so this change does not affect it.
>>
>> Previously, we assumed that the timestamp would always be 8-byte aligned
>> relative to the end of the scan buffer, but in the case of a scan buffer
>> a 16-byte quaternion vector, scan_bytes == 32, but the timestamp needs
>> to be placed at offset 16, not 24.
>
> ...
>
>> - ((int64_t *)data)[ts_offset] = timestamp;
>
>> + *(int64_t *)(data + ts_offset) = timestamp;
>
> What's the point in modifying this? The comment you added suffice for
> the original line.
>
ts_offset is now in bytes rather than number of int64_t elements.
So ((int64_t *)data)[ts_offset] would now 8x past the end of the array.