Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

iio: imu: st_lsm6dsx: fix iio_chan_spec for sensors without event detection

The st_lsm6dsx_acc_channels array of struct iio_chan_spec has a non-NULL
event_spec field, indicating support for IIO events. However, event
detection is not supported for all sensors, and if userspace tries to
configure accelerometer wakeup events on a sensor device that does not
support them (e.g. LSM6DS0), st_lsm6dsx_write_event() dereferences a NULL
pointer when trying to write to the wakeup register.
Define an additional struct iio_chan_spec array whose members have a NULL
event_spec field, and use this array instead of st_lsm6dsx_acc_channels for
sensors without event detection capability.

Fixes: b5969abfa8b8 ("iio: imu: st_lsm6dsx: add motion events")
Signed-off-by: Francesco Lavra <flavra@baylibre.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Acked-by: Lorenzo Bianconi <lorenzo@kernel.org>
Cc: stable@vger.kernel.org
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Francesco Lavra and committed by
Jonathan Cameron
c34e2e2d da934ef0

+11 -4
+11 -4
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
··· 101 101 IIO_CHAN_SOFT_TIMESTAMP(3), 102 102 }; 103 103 104 + static const struct iio_chan_spec st_lsm6ds0_acc_channels[] = { 105 + ST_LSM6DSX_CHANNEL(IIO_ACCEL, 0x28, IIO_MOD_X, 0), 106 + ST_LSM6DSX_CHANNEL(IIO_ACCEL, 0x2a, IIO_MOD_Y, 1), 107 + ST_LSM6DSX_CHANNEL(IIO_ACCEL, 0x2c, IIO_MOD_Z, 2), 108 + IIO_CHAN_SOFT_TIMESTAMP(3), 109 + }; 110 + 104 111 static const struct iio_chan_spec st_lsm6dsx_gyro_channels[] = { 105 112 ST_LSM6DSX_CHANNEL(IIO_ANGL_VEL, 0x22, IIO_MOD_X, 0), 106 113 ST_LSM6DSX_CHANNEL(IIO_ANGL_VEL, 0x24, IIO_MOD_Y, 1), ··· 149 142 }, 150 143 .channels = { 151 144 [ST_LSM6DSX_ID_ACC] = { 152 - .chan = st_lsm6dsx_acc_channels, 153 - .len = ARRAY_SIZE(st_lsm6dsx_acc_channels), 145 + .chan = st_lsm6ds0_acc_channels, 146 + .len = ARRAY_SIZE(st_lsm6ds0_acc_channels), 154 147 }, 155 148 [ST_LSM6DSX_ID_GYRO] = { 156 149 .chan = st_lsm6ds0_gyro_channels, ··· 1456 1449 }, 1457 1450 .channels = { 1458 1451 [ST_LSM6DSX_ID_ACC] = { 1459 - .chan = st_lsm6dsx_acc_channels, 1460 - .len = ARRAY_SIZE(st_lsm6dsx_acc_channels), 1452 + .chan = st_lsm6ds0_acc_channels, 1453 + .len = ARRAY_SIZE(st_lsm6ds0_acc_channels), 1461 1454 }, 1462 1455 [ST_LSM6DSX_ID_GYRO] = { 1463 1456 .chan = st_lsm6dsx_gyro_channels,