[PATCH 2/2] iio: orientation: hid-sensor-rotation: fix quaternion alignment

David Lechner posted 2 patches 1 month, 2 weeks ago
There is a newer version of this series
[PATCH 2/2] iio: orientation: hid-sensor-rotation: fix quaternion alignment
Posted by David Lechner 1 month, 2 weeks ago
Restore the alignment of sampled_vals to 16 bytes by using
IIO_DECLARE_REPEATED_ELEMENT(). This field contains a quaternion value
which scan_type.repeat = 4 and storagebits = 32. So the alignment must
be 16 bytes to match the assumptions of iio_storage_bytes_for_si() and
also to not break userspace.

Reported-by: Lixu Zhang <lixu.zhang@intel.com>
Closes: https://bugzilla.kernel.org/show_bug.cgi?id=221077
Fixes: b31a74075cb4 ("iio: orientation: hid-sensor-rotation: remove unnecessary alignment")
Signed-off-by: David Lechner <dlechner@baylibre.com>
---
 drivers/iio/orientation/hid-sensor-rotation.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iio/orientation/hid-sensor-rotation.c b/drivers/iio/orientation/hid-sensor-rotation.c
index e759f91a710a..9df955ecfbac 100644
--- a/drivers/iio/orientation/hid-sensor-rotation.c
+++ b/drivers/iio/orientation/hid-sensor-rotation.c
@@ -19,7 +19,7 @@ struct dev_rot_state {
 	struct hid_sensor_common common_attributes;
 	struct hid_sensor_hub_attribute_info quaternion;
 	struct {
-		s32 sampled_vals[4];
+		IIO_DECLARE_REPEATED_ELEMENT(s32, sampled_vals, 4);
 		aligned_s64 timestamp;
 	} scan;
 	int scale_pre_decml;

-- 
2.43.0
RE: [PATCH 2/2] iio: orientation: hid-sensor-rotation: fix quaternion alignment
Posted by Zhang, Lixu 1 month, 1 week ago
>-----Original Message-----
>From: David Lechner <dlechner@baylibre.com>
>Sent: Sunday, February 15, 2026 5:00 AM
>To: Jonathan Cameron <jic23@kernel.org>; Nuno Sá <nuno.sa@analog.com>;
>Andy Shevchenko <andy@kernel.org>; Jiri Kosina <jikos@kernel.org>; Srinivas
>Pandruvada <srinivas.pandruvada@linux.intel.com>
>Cc: linux-iio@vger.kernel.org; linux-kernel@vger.kernel.org; Jonathan Cameron
><Jonathan.Cameron@huawei.com>; linux-input@vger.kernel.org; Lechner,
>David <dlechner@baylibre.com>; Zhang, Lixu <lixu.zhang@intel.com>
>Subject: [PATCH 2/2] iio: orientation: hid-sensor-rotation: fix quaternion
>alignment
>
>Restore the alignment of sampled_vals to 16 bytes by using
>IIO_DECLARE_REPEATED_ELEMENT(). This field contains a quaternion value
>which scan_type.repeat = 4 and storagebits = 32. So the alignment must be 16
>bytes to match the assumptions of iio_storage_bytes_for_si() and also to not
>break userspace.
>
>Reported-by: Lixu Zhang <lixu.zhang@intel.com>
>Closes: https://bugzilla.kernel.org/show_bug.cgi?id=221077
>Fixes: b31a74075cb4 ("iio: orientation: hid-sensor-rotation: remove
>unnecessary alignment")
>Signed-off-by: David Lechner <dlechner@baylibre.com>

Tested-by: Lixu Zhang <lixu.zhang@intel.com>

Thanks,
-Lixu
Re: [PATCH 2/2] iio: orientation: hid-sensor-rotation: fix quaternion alignment
Posted by Andy Shevchenko 1 month, 2 weeks ago
On Sat, Feb 14, 2026 at 03:00:21PM -0600, David Lechner wrote:
> Restore the alignment of sampled_vals to 16 bytes by using
> IIO_DECLARE_REPEATED_ELEMENT(). This field contains a quaternion value
> which scan_type.repeat = 4 and storagebits = 32. So the alignment must
> be 16 bytes to match the assumptions of iio_storage_bytes_for_si() and
> also to not break userspace.

...

>  	struct {
> -		s32 sampled_vals[4];
> +		IIO_DECLARE_REPEATED_ELEMENT(s32, sampled_vals, 4);

This becomes
		IIO_DECLARE_QUATERNION(s32, sampled_vals);

>  		aligned_s64 timestamp;
>  	} scan;

In the similar way we can address drivers/iio/imu/bno055/bno055.c.

-- 
With Best Regards,
Andy Shevchenko