Linux IIO development
 help / color / mirror / Atom feed
* [PATCH v3] iio: imu: bno055: add explicit scan buf layout
@ 2026-03-14 21:38 David Lechner
  2026-03-16 14:54 ` Andy Shevchenko
  0 siblings, 1 reply; 3+ messages in thread
From: David Lechner @ 2026-03-14 21:38 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_QUATERNION() macro
(which is currently in fixes-togreg).

[1]: https://lore.kernel.org/linux-iio/20260214-iio-fix-repeat-alignment-v1-1-47f01288c803@baylibre.com/
---
Changes in v3:
- Use IIO_DECLARE_BUFFER_WITH_TS()
- Move timestamp into new struct.
- Make comment more verbose.
- Link to v2: https://lore.kernel.org/r/20260228-iio-imu-bno055-repeated-element-v2-1-888676158804@baylibre.com

Changes in v2:
- Rename IIO_DECLARE_REPEATED_ELEMENT() to IIO_DECLARE_QUATERNION().
- Link to v1: https://lore.kernel.org/r/20260214-iio-imu-bno055-repeated-element-v1-1-b57b08efd566@baylibre.com
---
 drivers/iio/imu/bno055/bno055.c | 27 ++++++++++++++++++++++++---
 1 file changed, 24 insertions(+), 3 deletions(-)

diff --git a/drivers/iio/imu/bno055/bno055.c b/drivers/iio/imu/bno055/bno055.c
index c96fec2ebb3e..d0101607a9b3 100644
--- a/drivers/iio/imu/bno055/bno055.c
+++ b/drivers/iio/imu/bno055/bno055.c
@@ -210,9 +210,30 @@ struct bno055_priv {
 	u8 uid[BNO055_UID_LEN];
 	struct gpio_desc *reset_gpio;
 	bool sw_reset;
-	struct {
-		__le16 chans[BNO055_SCAN_CH_COUNT];
-		aligned_s64 timestamp;
+	union {
+		IIO_DECLARE_BUFFER_WITH_TS(__le16, chans, BNO055_SCAN_CH_COUNT);
+		/*
+		 * This struct is not used, but it is here to ensure proper size
+		 * and alignment of the scan buffer above (because of the extra
+		 * requirements of the quaternion field). Technically it is not
+		 * needed in this case, because other fields just happen to make
+		 * things correctly aligned already. But it is better to be
+		 * explicit about the requirements anyway. The actual contents
+		 * of the scan buffer will vary depending on which channels are
+		 * enabled.
+		 */
+		struct {
+			__le16 acc[3];
+			__le16 magn[3];
+			__le16 gyr[3];
+			__le16 yaw;
+			__le16 pitch;
+			__le16 roll;
+			IIO_DECLARE_QUATERNION(__le16, quaternion);
+			__le16 lia[3];
+			__le16 gravity[3];
+			aligned_s64 timestamp;
+		};
 	} buf;
 	struct dentry *debugfs;
 };

---
base-commit: 79a86a6cc3669416a21fef32d0767d39ba84b3aa
change-id: 20260214-iio-imu-bno055-repeated-element-1c1552ea74be

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


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

* Re: [PATCH v3] iio: imu: bno055: add explicit scan buf layout
  2026-03-14 21:38 [PATCH v3] iio: imu: bno055: add explicit scan buf layout David Lechner
@ 2026-03-16 14:54 ` Andy Shevchenko
  2026-04-12 14:24   ` Jonathan Cameron
  0 siblings, 1 reply; 3+ messages in thread
From: Andy Shevchenko @ 2026-03-16 14:54 UTC (permalink / raw)
  To: David Lechner
  Cc: Jonathan Cameron, Nuno Sá, Andy Shevchenko, linux-iio,
	linux-kernel

On Sat, Mar 14, 2026 at 04:38:25PM -0500, David Lechner wrote:
> 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.

This looks good to me,
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH v3] iio: imu: bno055: add explicit scan buf layout
  2026-03-16 14:54 ` Andy Shevchenko
@ 2026-04-12 14:24   ` Jonathan Cameron
  0 siblings, 0 replies; 3+ messages in thread
From: Jonathan Cameron @ 2026-04-12 14:24 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: David Lechner, Nuno Sá, Andy Shevchenko, linux-iio,
	linux-kernel, Andrea Merello

On Mon, 16 Mar 2026 16:54:22 +0200
Andy Shevchenko <andriy.shevchenko@intel.com> wrote:

> On Sat, Mar 14, 2026 at 04:38:25PM -0500, David Lechner wrote:
> > 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.  
> 
> This looks good to me,
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
> 
Applied to the testing branch of iio.git.

Also +CC Andrea as original author - not sure if email address still
valid however!

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

end of thread, other threads:[~2026-04-12 14:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-14 21:38 [PATCH v3] iio: imu: bno055: add explicit scan buf layout David Lechner
2026-03-16 14:54 ` Andy Shevchenko
2026-04-12 14:24   ` Jonathan Cameron

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