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

Configure Feed

Select the types of activity you want to include in your feed.

iio: imu: st_lsm6dsx: Set buffer sampling frequency for accelerometer only

The st_lsm6dsx_hwfifo_odr_store() function, which is called when userspace
writes the buffer sampling frequency sysfs attribute, calls
st_lsm6dsx_check_odr(), which accesses the odr_table array at index
`sensor->id`; since this array is only 2 entries long, an access for any
sensor type other than accelerometer or gyroscope is an out-of-bounds
access.

The motivation for being able to set a buffer frequency different from the
sensor sampling frequency is to support use cases that need accurate event
detection (which requires a high sampling frequency) while retrieving
sensor data at low frequency. Since all the supported event types are
generated from acceleration data only, do not create the buffer sampling
frequency attribute for sensor types other than the accelerometer.

Fixes: 6b648a36c200 ("iio: imu: st_lsm6dsx: Decouple sensor ODR from FIFO batch data rate")
Signed-off-by: Francesco Lavra <flavra@baylibre.com>
Cc: <Stable@vger.kernel.org>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Francesco Lavra and committed by
Jonathan Cameron
679c04c1 630748af

+10 -1
+10 -1
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c
··· 862 862 int i, ret; 863 863 864 864 for (i = 0; i < ST_LSM6DSX_ID_MAX; i++) { 865 + const struct iio_dev_attr **attrs; 866 + 865 867 if (!hw->iio_devs[i]) 866 868 continue; 867 869 870 + /* 871 + * For the accelerometer, allow setting FIFO sampling frequency 872 + * values different from the sensor sampling frequency, which 873 + * may be needed to keep FIFO data rate low while sampling 874 + * acceleration data at high rates for accurate event detection. 875 + */ 876 + attrs = i == ST_LSM6DSX_ID_ACC ? st_lsm6dsx_buffer_attrs : NULL; 868 877 ret = devm_iio_kfifo_buffer_setup_ext(hw->dev, hw->iio_devs[i], 869 878 &st_lsm6dsx_buffer_ops, 870 - st_lsm6dsx_buffer_attrs); 879 + attrs); 871 880 if (ret) 872 881 return ret; 873 882 }