]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
iio: imu: bno055: fix BNO055_SCAN_CH_COUNT off by one
authorDavid Lechner <dlechner@baylibre.com>
Sat, 14 Feb 2026 22:33:54 +0000 (16:33 -0600)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Sun, 1 Mar 2026 12:25:43 +0000 (12:25 +0000)
Fix an off-by-one error in the BNO055_SCAN_CH_COUNT macro. The count
is derived by taking the difference of the last and first register
addresses, dividing by the size of each channel (2 bytes). It needs to
also add 1 to account for the fact that the count is inclusive of both
the first and last channels.

Thanks to the aligned_s64 timestamp field, there was already extra
padding in the buffer, so there were no runtime issues caused by this
bug.

Fixes: 4aefe1c2bd0c ("iio: imu: add Bosch Sensortec BNO055 core driver")
Signed-off-by: David Lechner <dlechner@baylibre.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/imu/bno055/bno055.c

index 303bc308f80a84b3281b8ec871435bb0ab5b8d58..c96fec2ebb3e7852ba0dc01809e1f8aab9375447 100644 (file)
@@ -64,7 +64,7 @@
 #define BNO055_GRAVITY_DATA_X_LSB_REG  0x2E
 #define BNO055_GRAVITY_DATA_Y_LSB_REG  0x30
 #define BNO055_GRAVITY_DATA_Z_LSB_REG  0x32
-#define BNO055_SCAN_CH_COUNT ((BNO055_GRAVITY_DATA_Z_LSB_REG - BNO055_ACC_DATA_X_LSB_REG) / 2)
+#define BNO055_SCAN_CH_COUNT ((BNO055_GRAVITY_DATA_Z_LSB_REG - BNO055_ACC_DATA_X_LSB_REG) / 2 + 1)
 #define BNO055_TEMP_REG                        0x34
 #define BNO055_CALIB_STAT_REG          0x35
 #define BNO055_CALIB_STAT_MAGN_SHIFT 0