iio: imu: st_lsm6dsx: fix array size for st_lsm6dsx_settings fields
Subsystems (2)
PATCH 1/1 iio: imu: st_lsm6dsx: fix array size for st_lsm6dsx_settings fields
The decimator and batch fields of struct st_lsm6dsx_settings are arrays indexed by sensor type, not by sensor hardware identifier; moreover, the batch field is only used for the accelerometer and gyroscope.
Change the array size for decimator from ST_LSM6DSX_MAX_ID to ST_LSM6DSX_ID_MAX, and change the array size for batch from ST_LSM6DSX_MAX_ID to 2; move the enum st_lsm6dsx_sensor_id definition so that the ST_LSM6DSX_ID_MAX value is usable within the struct st_lsm6dsx_settings definition.
--- drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h +11 -11
@@ -252,6 +252,15 @@ struct st_lsm6dsx_event_settings {u8 wakeup_src_x_mask; }; +enum st_lsm6dsx_sensor_id { +ST_LSM6DSX_ID_GYRO , +ST_LSM6DSX_ID_ACC , +ST_LSM6DSX_ID_EXT0 , +ST_LSM6DSX_ID_EXT1 , +ST_LSM6DSX_ID_EXT2 , +ST_LSM6DSX_ID_MAX , +}; +enum st_lsm6dsx_ext_sensor_id {ST_LSM6DSX_ID_MAGN , };
@@ -337,23 +346,14 @@ struct st_lsm6dsx_settings {struct st_lsm6dsx_odr_table_entry odr_table[2 ];struct st_lsm6dsx_samples_to_discard samples_to_discard[2 ];struct st_lsm6dsx_fs_table_entry fs_table[2 ]; -struct st_lsm6dsx_reg decimator[ST_LSM6DSX_MAX_ID ]; -struct st_lsm6dsx_reg batch[ST_LSM6DSX_MAX_ID ]; +struct st_lsm6dsx_reg decimator[ST_LSM6DSX_ID_MAX ]; +struct st_lsm6dsx_reg batch[2 ];struct st_lsm6dsx_fifo_ops fifo_ops;struct st_lsm6dsx_hw_ts_settings ts_settings;struct st_lsm6dsx_shub_settings shub_settings;struct st_lsm6dsx_event_settings event_settings; }; -enum st_lsm6dsx_sensor_id { -ST_LSM6DSX_ID_GYRO , -ST_LSM6DSX_ID_ACC , -ST_LSM6DSX_ID_EXT0 , -ST_LSM6DSX_ID_EXT1 , -ST_LSM6DSX_ID_EXT2 , -ST_LSM6DSX_ID_MAX , -}; -enum st_lsm6dsx_fifo_mode {ST_LSM6DSX_FIFO_BYPASS =0x0 ,ST_LSM6DSX_FIFO_CONT =0x6 ,
Signature · 1 line
2.39.5
Quoted 10 lines
The
decimatorandbatchfields of structst_lsm6dsx_settingsare arrays indexed by sensor type, not by sensor hardware identifier; moreover, thebatchfield is only used for the accelerometer and gyroscope.
Change the array size fordecimatorfromST_LSM6DSX_MAX_IDtoST_LSM6DSX_ID_MAX, and change the array size forbatchfromST_LSM6DSX_MAX_IDto 2; move the enumst_lsm6dsx_sensor_iddefinition so that theST_LSM6DSX_ID_MAXvalue is usable within the structst_lsm6dsx_settingsdefinition.
Quoted 2 lines
Fixes 801a6e0af0c6c ("iio: imu: st_lsm6dsx: add support to LSM6DSO")Signed-off-by Francesco Lavra <[email protected]>
Quoted 53 lines
--- drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h +11
-11@@ -252,6 +252,15 @@ struct st_lsm6dsx_event_settings {u8 wakeup_src_x_mask; }; +enum st_lsm6dsx_sensor_id { +ST_LSM6DSX_ID_GYRO , +ST_LSM6DSX_ID_ACC , +ST_LSM6DSX_ID_EXT0 , +ST_LSM6DSX_ID_EXT1 , +ST_LSM6DSX_ID_EXT2 , +ST_LSM6DSX_ID_MAX , +}; +enum st_lsm6dsx_ext_sensor_id {ST_LSM6DSX_ID_MAGN , };@@ -337,23 +346,14 @@ struct st_lsm6dsx_settings {struct st_lsm6dsx_odr_table_entry odr_table[2 ];struct st_lsm6dsx_samples_to_discard samples_to_discard[2 ];struct st_lsm6dsx_fs_table_entry fs_table[2 ]; -struct st_lsm6dsx_reg decimator[ST_LSM6DSX_MAX_ID ]; -struct st_lsm6dsx_reg batch[ST_LSM6DSX_MAX_ID ]; +struct st_lsm6dsx_reg decimator[ST_LSM6DSX_ID_MAX ]; +struct st_lsm6dsx_reg batch[2 ];struct st_lsm6dsx_fifo_ops fifo_ops;struct st_lsm6dsx_hw_ts_settings ts_settings;struct st_lsm6dsx_shub_settings shub_settings;struct st_lsm6dsx_event_settings event_settings; }; -enum st_lsm6dsx_sensor_id { -ST_LSM6DSX_ID_GYRO , -ST_LSM6DSX_ID_ACC , -ST_LSM6DSX_ID_EXT0 , -ST_LSM6DSX_ID_EXT1 , -ST_LSM6DSX_ID_EXT2 , -ST_LSM6DSX_ID_MAX , -}; -enum st_lsm6dsx_fifo_mode {ST_LSM6DSX_FIFO_BYPASS =0x0 ,ST_LSM6DSX_FIFO_CONT =0x6 ,Signature · 1 line
2.39.5
Quoted 10 lines · On Sat, 18 Oct 2025 11:33:39 +0200 Lorenzo Bianconi <[email protected]> wrote:
Quoted 10 lines
The
decimatorandbatchfields of structst_lsm6dsx_settingsare arrays indexed by sensor type, not by sensor hardware identifier; moreover, thebatchfield is only used for the accelerometer and gyroscope.
Change the array size fordecimatorfromST_LSM6DSX_MAX_IDtoST_LSM6DSX_ID_MAX, and change the array size forbatchfromST_LSM6DSX_MAX_IDto 2; move the enumst_lsm6dsx_sensor_iddefinition so that theST_LSM6DSX_ID_MAXvalue is usable within the structst_lsm6dsx_settingsdefinition.
Quoted 5 lines
Quoted 2 lines
Fixes 801a6e0af0c6c ("iio: imu: st_lsm6dsx: add support to LSM6DSO")Signed-off-by Francesco Lavra <[email protected]>Acked-by Lorenzo Bianconi <[email protected]>
Applied to the fixes-togreg branch of iio.git and marked for stable.
thanks,
Jonathan
Quoted 9 lines · Francesco Lavra
The
decimatorandbatchfields of structst_lsm6dsx_settingsare arrays indexed by sensor type, not by sensor hardware identifier; moreover, thebatchfield is only used for the accelerometer and gyroscope.
Change the array size fordecimatorfromST_LSM6DSX_MAX_IDtoST_LSM6DSX_ID_MAX, and change the array size forbatchfromST_LSM6DSX_MAX_IDto 2; move the enumst_lsm6dsx_sensor_iddefinition so that theST_LSM6DSX_ID_MAXvalue is usable within the structst_lsm6dsx_settingsdefinition.
...
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h struct st_lsm6dsx_event_settings { · line 261
Quoted 10 lines
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h +7
-0+enum st_lsm6dsx_sensor_id { +ST_LSM6DSX_ID_GYRO , +ST_LSM6DSX_ID_ACC , +ST_LSM6DSX_ID_EXT0 , +ST_LSM6DSX_ID_EXT1 , +ST_LSM6DSX_ID_EXT2 , +ST_LSM6DSX_ID_MAX ,
Is it a termination entry? (Looks like that to me) Can we drop trailing comma while at it?
Quoted 1 line
+};
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 22 lines · Andy Shevchenko
Quoted 9 lines · Francesco Lavra
The
decimatorandbatchfields of structst_lsm6dsx_settingsare arrays indexed by sensor type, not by sensor hardware identifier; moreover, thebatchfield is only used for the accelerometer and gyroscope.
Change the array size fordecimatorfromST_LSM6DSX_MAX_IDtoST_LSM6DSX_ID_MAX, and change the array size forbatchfromST_LSM6DSX_MAX_IDto 2; move the enumst_lsm6dsx_sensor_iddefinition so that theST_LSM6DSX_ID_MAXvalue is usable within the structst_lsm6dsx_settingsdefinition....
Quoted 6 lines
+enum
st_lsm6dsx_sensor_id{
+ ST_LSM6DSX_ID_GYRO,
+ ST_LSM6DSX_ID_ACC,
+ ST_LSM6DSX_ID_EXT0,
+ ST_LSM6DSX_ID_EXT1,
+ ST_LSM6DSX_ID_EXT2,
Quoted 5 lines
Quoted 1 line
+ ST_LSM6DSX_ID_MAX,
Is it a termination entry? (Looks like that to me) Can we drop trailing comma
while at it?
Yes, it's a termination entry, I will drop the trailing comma.
Quoted 1 line
Quoted 1 line
+};
Jonathan Cameron
maintainerQuoted 23 lines · On Sat, 18 Oct 2025 20:55:40 +0200 Francesco Lavra <[email protected]> wrote:
Quoted 22 lines · Andy Shevchenko
Quoted 9 lines · Francesco Lavra
The
decimatorandbatchfields of structst_lsm6dsx_settingsare arrays indexed by sensor type, not by sensor hardware identifier; moreover, thebatchfield is only used for the accelerometer and gyroscope.
Change the array size fordecimatorfromST_LSM6DSX_MAX_IDtoST_LSM6DSX_ID_MAX, and change the array size forbatchfromST_LSM6DSX_MAX_IDto 2; move the enumst_lsm6dsx_sensor_iddefinition so that theST_LSM6DSX_ID_MAXvalue is usable within the structst_lsm6dsx_settingsdefinition....
Quoted 6 lines
+enum
st_lsm6dsx_sensor_id{
+ ST_LSM6DSX_ID_GYRO,
+ ST_LSM6DSX_ID_ACC,
+ ST_LSM6DSX_ID_EXT0,
+ ST_LSM6DSX_ID_EXT1,
+ ST_LSM6DSX_ID_EXT2,
Quoted 9 lines
Quoted 5 lines
Quoted 1 line
+ ST_LSM6DSX_ID_MAX,
Is it a termination entry? (Looks like that to me) Can we drop trailing comma
while at it?Yes, it's a termination entry, I will drop the trailing comma.
Quoted 1 line
Quoted 1 line
+};
I tweaked it. So no need for new version.