[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <Z8nDzyVO596rW0Mf@lore-desk>
Date: Thu, 6 Mar 2025 16:48:31 +0100
From: Lorenzo Bianconi <lorenzo@...nel.org>
To: Silvano Seva <s.seva@...gma.it>
Cc: a.greco@...gma.it, Jonathan Cameron <jic23@...nel.org>,
Lars-Peter Clausen <lars@...afoo.de>,
"open list:ST LSM6DSx IMU IIO DRIVER" <linux-iio@...r.kernel.org>,
open list <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] iio: imu: st_lsm6dsx: fix possible lockup during FIFO
read
> Prevent st_lsm6dsx_read_fifo and st_lsm6dsx_read_tagged_fifo functions
> from falling in an infinite loop in case pattern_len is equal to zero and
> the device FIFO is not empty.
>
> Signed-off-by: Silvano Seva <s.seva@...gma.it>
> ---
> drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c | 8 ++++++++
> 1 file changed, 8 insertions(+)
>
> diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c
> index 0a7cd8c1aa33..7f343614f8a5 100644
> --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c
> +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c
> @@ -395,12 +395,17 @@ int st_lsm6dsx_read_fifo(struct st_lsm6dsx_hw *hw)
> fifo_len = (le16_to_cpu(fifo_status) & fifo_diff_mask) *
> ST_LSM6DSX_CHAN_SIZE;
> fifo_len = (fifo_len / pattern_len) * pattern_len;
> + if (!fifo_len)
> + return 0;
I do not think this check is necessary since if fifo_len is 0 we will not run
the for loop, right?
>
> acc_sensor = iio_priv(hw->iio_devs[ST_LSM6DSX_ID_ACC]);
> gyro_sensor = iio_priv(hw->iio_devs[ST_LSM6DSX_ID_GYRO]);
> if (hw->iio_devs[ST_LSM6DSX_ID_EXT0])
> ext_sensor = iio_priv(hw->iio_devs[ST_LSM6DSX_ID_EXT0]);
>
> + if (!pattern_len)
> + pattern_len = ST_LSM6DSX_SAMPLE_SIZE;
same here, I do not think pattern_len can be 0 since hw->sip must be greater
than 0 in order to enable the FIFO. Moreover, this check should be some lines
above since we have already divided fifo_len by pattern_len here.
> +
> for (read_len = 0; read_len < fifo_len; read_len += pattern_len) {
> err = st_lsm6dsx_read_block(hw, ST_LSM6DSX_REG_FIFO_OUTL_ADDR,
> hw->buff, pattern_len,
> @@ -623,6 +628,9 @@ int st_lsm6dsx_read_tagged_fifo(struct st_lsm6dsx_hw *hw)
> if (!fifo_len)
> return 0;
>
> + if (!pattern_len)
> + pattern_len = ST_LSM6DSX_TAGGED_SAMPLE_SIZE;
for the reason above, this is not necessary.
Regards,
Lorenzo
> +
> for (read_len = 0; read_len < fifo_len; read_len += pattern_len) {
> err = st_lsm6dsx_read_block(hw,
> ST_LSM6DSX_REG_FIFO_OUT_TAG_ADDR,
> --
> 2.48.1
>
Download attachment "signature.asc" of type "application/pgp-signature" (229 bytes)
Powered by blists - more mailing lists