Re: [PATCH 1/4] iio: orientation: hid-sensor-rotation: add timestamp hack to not break userspace

From: Andy Shevchenko

Date: Mon Mar 02 2026 - 03:51:30 EST


On Sun, Mar 01, 2026 at 02:24:50PM -0600, David Lechner wrote:
> Add a hack to push two timestamps in the hid-sensor-rotation scan data
> to avoid breaking userspace applications that depend on the timestamp
> being at the incorrect location in the scan data due to unintentional
> misalignment in older kernels.
>
> When this driver was written, the timestamp was in the correct location
> because of the way iio_compute_scan_bytes() was implemented at the time.
> (Samples were 24 bytes each.) Then commit 883f61653069 ("iio: buffer:
> align the size of scan bytes to size of the largest element") changed
> the computed scan_bytes to be a different size (32 bytes), which caused
> iio_push_to_buffers_with_timestamp() to place the timestamp at an
> incorrect offset.
>
> There have been long periods of time (6 years each) where the timestamp
> was in either location, so to not break either case, we open-code the
> timestamps to be pushed to both locations in the scan data.

...

> + /*
> + * HACK: There are two copies of the same timestamp in case of

Usually we use FIXME in such cases. HACK is something which goes with
"do not apply".

Does it mean it will stay forever?

> + * userspace depending on broken alignment from older kernels.
> + */
> + aligned_s64 timestamp[2];

...

> + /*
> + * HACK: IIO previously had an incorrect implementation of

Ditto.

> + * iio_push_to_buffers_with_timestamp() that put the timestamp
> + * in the last 8 bytes of the buffer, which was incorrect
> + * according to the IIO ABI. To avoid breaking userspace that
> + * depended on this broken behavior, we put the timestamp in
> + * both the correct place and the old incorrect place.
> + */
> + rot_state->scan.timestamp[0] = rot_state->timestamp;
> + rot_state->scan.timestamp[1] = rot_state->timestamp;

--
With Best Regards,
Andy Shevchenko