summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorDavid Lechner <dlechner@baylibre.com>2026-03-14 16:38:25 -0500
committerJonathan Cameron <jic23@kernel.org>2026-04-27 09:58:16 +0100
commit5de55ae1300b4bd70eb39b6664b6c733eee08228 (patch)
tree6b92c06f7c80957090da72c48738508657d75bc2 /drivers
parentd05e3c1460e47aa61e58cc6947cf7c9fc1371d7e (diff)
downloadlinux-5de55ae1300b4bd70eb39b6664b6c733eee08228.tar.gz
linux-5de55ae1300b4bd70eb39b6664b6c733eee08228.zip
iio: imu: bno055: add explicit scan buf layout
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> Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/iio/imu/bno055/bno055.c27
1 files 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;
};