Skip to contentSkip to conversation

iio: imu: st_lsm6dsx: fix possible lockup during FIFO read

PATCH Lorenzo Bianconi 1 participant 1 message Mar 10, 2025 IIO

lore
Share & tools
lore
#0 lore raw

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

Reply-To:
In-Reply-To: <[email protected]>

Quoted 15 lines

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.

---
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c +0 -0
index 0a7cd8c1aa33..39a7e15ae9ae 100644
@@ -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))

drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c int st_lsm6dsx_read_fifo(struct st_lsm6dsx_hw *hw) · line 402

Quoted 10 lines
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c +5 -0
 		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

Quoted 16 lines
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c +3 -0
 	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,
Signature · 1 line
2.48.1