mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] iio: imu: bno055: add explicit scan buf layout
@ 2026-02-14 22:10 David Lechner
  2026-02-16  7:49 ` Andy Shevchenko
  0 siblings, 1 reply; 2+ messages in thread
From: David Lechner @ 2026-02-14 22:10 UTC (permalink / raw)
  To: Jonathan Cameron, Nuno Sá, Andy Shevchenko
  Cc: linux-iio, linux-kernel, David Lechner

Move the scan buf.chans array into a union along with a struct that
gives the layout of the buffer with all channels enabled.

Although not technically required in this case, if there had been a
different number of items before the quaternion, there could have been
a subtle bug with the special alignment needed for the quaternion
channel data and the array would have been too small.

Signed-off-by: David Lechner <dlechner@baylibre.com>
---
This depends on [1] that introduces the IIO_DECLARE_REPEATED_ELEMENT()
macro. I didn't include it in the same series because the other series
contains a fix and should be backported while this one ins't a fix.

[1]: https://lore.kernel.org/linux-iio/20260214-iio-fix-repeat-alignment-v1-1-47f01288c803@baylibre.com/
---
 drivers/iio/imu/bno055/bno055.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/drivers/iio/imu/bno055/bno055.c b/drivers/iio/imu/bno055/bno055.c
index 303bc308f80a..47afda01229f 100644
--- a/drivers/iio/imu/bno055/bno055.c
+++ b/drivers/iio/imu/bno055/bno055.c
@@ -211,7 +211,25 @@ struct bno055_priv {
 	struct gpio_desc *reset_gpio;
 	bool sw_reset;
 	struct {
-		__le16 chans[BNO055_SCAN_CH_COUNT];
+		union {
+			__le16 chans[BNO055_SCAN_CH_COUNT];
+			/*
+			 * Struct is to ensure proper size in case any padding
+			 * is needed. Technically not needed in this case, but
+			 * better to be explicit about the requirements.
+			 */
+			struct {
+				__le16 acc[3];
+				__le16 magn[3];
+				__le16 gyr[3];
+				__le16 yaw;
+				__le16 pitch;
+				__le16 roll;
+				IIO_DECLARE_REPEATED_ELEMENT(__le16, quaternion, 4);
+				__le16 lia[3];
+				__le16 gravity[3];
+			};
+		};
 		aligned_s64 timestamp;
 	} buf;
 	struct dentry *debugfs;

---
base-commit: 0713b26190addfa3a774b386c8658952ef9f7faf
change-id: 20260214-iio-imu-bno055-repeated-element-1c1552ea74be
prerequisite-change-id: 20260214-iio-fix-repeat-alignment-575b2c009e25:v1
prerequisite-patch-id: f7d2b3c87791f50de610900f5680d1b9b503702a
prerequisite-patch-id: 28aed7da5bbcd16f83256bbe2d4c209fc26888bc

Best regards,
-- 
David Lechner <dlechner@baylibre.com>


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-02-16  7:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-02-14 22:10 [PATCH] iio: imu: bno055: add explicit scan buf layout David Lechner
2026-02-16  7:49 ` Andy Shevchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®