linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH] iio: imu: st_lsm6dsx: fix possible lockup during FIFO read
@ 2025-03-10 13:36 Lorenzo Bianconi
  0 siblings, 0 replies; 7+ messages in thread
From: Lorenzo Bianconi @ 2025-03-10 13:36 UTC (permalink / raw)
  To: Silvano Seva
  Cc: a.greco, Jonathan Cameron, Lars-Peter Clausen, linux-iio,
	linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1747 bytes --]

I guess you missed v2 here. Moreover, can you please proper Fixes tag?

Reply-To: 
In-Reply-To: <20250310132508.24660-2-s.seva@4sigma.it>

> 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@4sigma.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..39a7e15ae9ae 100644
> --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c
> +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c
> @@ -392,9 +392,14 @@ int st_lsm6dsx_read_fifo(struct st_lsm6dsx_hw *hw)
>  	if (fifo_status & cpu_to_le16(ST_LSM6DSX_FIFO_EMPTY_MASK))
>  		return 0;
>  
> +	if (!pattern_len)
> +		pattern_len = ST_LSM6DSX_SAMPLE_SIZE;
> +
>  	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;

this is not needed, please drop it.

Regards,
Lorenzo

>  
>  	acc_sensor = iio_priv(hw->iio_devs[ST_LSM6DSX_ID_ACC]);
>  	gyro_sensor = iio_priv(hw->iio_devs[ST_LSM6DSX_ID_GYRO]);
> @@ -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 (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
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread
* [PATCH] iio: imu: st_lsm6dsx: fix possible lockup during FIFO read
@ 2025-03-03 13:21 Silvano Seva
  2025-03-06 15:48 ` Lorenzo Bianconi
  0 siblings, 1 reply; 7+ messages in thread
From: Silvano Seva @ 2025-03-03 13:21 UTC (permalink / raw)
  To: lorenzo
  Cc: a.greco, Silvano Seva, Jonathan Cameron, Lars-Peter Clausen,
	open list:ST LSM6DSx IMU IIO DRIVER, open list

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@4sigma.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;
 
 	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;
+
 	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 (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


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2025-03-10 13:36 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-10 13:36 [PATCH] iio: imu: st_lsm6dsx: fix possible lockup during FIFO read Lorenzo Bianconi
  -- strict thread matches above, loose matches on Subject: below --
2025-03-03 13:21 Silvano Seva
2025-03-06 15:48 ` Lorenzo Bianconi
2025-03-07  9:20   ` Silvano Seva
2025-03-07 14:40     ` Lorenzo Bianconi
2025-03-10 13:22       ` Silvano Seva
2025-03-10 13:29       ` Silvano Seva

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).