Re: [PATCH v6 2/7] iio: imu: st_lsm6dsx: Set buffer sampling frequency for accelerometer only
From: Jonathan Cameron
Date: Sat Feb 28 2026 - 16:25:16 EST
On Wed, 25 Feb 2026 11:16:32 +0100
Francesco Lavra <flavra@xxxxxxxxxxxx> wrote:
> 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@xxxxxxxxxxxx>
It feels like we may need a little longer to converge on the rest of
the series, and I don't want to risk delaying the fixes further.
A such I've picked up patches 1 and 2 on the fixes-togreg branch of iio.git
Please just assume they are available for v7 and drop them from what you post.
This may mean we have to wait for these to be available in a suitable upstream
tree before I can pick up the rest. We have plenty of cycle left and
the fixes are really piling up in my tree, so that shouldn't be a problem.
Jonathan
> ---
> drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c | 11 ++++++++++-
> 1 file changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c
> index 1ee2fc5f5f1f..5b28a3ffcc3d 100644
> --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c
> +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c
> @@ -862,12 +862,21 @@ int st_lsm6dsx_fifo_setup(struct st_lsm6dsx_hw *hw)
> int i, ret;
>
> for (i = 0; i < ST_LSM6DSX_ID_MAX; i++) {
> + const struct iio_dev_attr **attrs;
> +
> if (!hw->iio_devs[i])
> continue;
>
> + /*
> + * For the accelerometer, allow setting FIFO sampling frequency
> + * values different from the sensor sampling frequency, which
> + * may be needed to keep FIFO data rate low while sampling
> + * acceleration data at high rates for accurate event detection.
> + */
> + attrs = i == ST_LSM6DSX_ID_ACC ? st_lsm6dsx_buffer_attrs : NULL;
> ret = devm_iio_kfifo_buffer_setup_ext(hw->dev, hw->iio_devs[i],
> &st_lsm6dsx_buffer_ops,
> - st_lsm6dsx_buffer_attrs);
> + attrs);
> if (ret)
> return ret;
> }