Re: [PATCH] iio: imu: st_lsm6dsx: Fix check for invalid samples from FIFO

From: Andy Shevchenko

Date: Wed Jan 21 2026 - 08:04:49 EST


On Wed, Jan 21, 2026 at 02:47:40PM +0200, Andy Shevchenko wrote:
> On Wed, Jan 21, 2026 at 12:27:57PM +0100, Francesco Lavra wrote:

...

> > st_lsm6dsx_push_tagged_data(struct st_lsm6dsx_hw *hw, u8 tag,
> > u8 *data, s64 ts)
> > {
> > - s16 val = le16_to_cpu(*(__le16 *)data);
> > struct st_lsm6dsx_sensor *sensor;
> > struct iio_dev *iio_dev;
> >
> > /* invalid sample during bootstrap phase */
> > - if (val >= ST_LSM6DSX_INVALID_SAMPLE)
> > + if ((tag == ST_LSM6DSX_GYRO_TAG || tag == ST_LSM6DSX_ACC_TAG) &&
> > + (s16)le16_to_cpup((__le16 *)data) >= ST_LSM6DSX_INVALID_SAMPLE)
>
> Since data is u8 *, it might appear on unaligned addresses and the proper
> conversion here is to use get_unaligned_le16() without any of those ugly
> castings.

Okay, (s16) seems needed or another way to allow 0x8000 and higher values.

> > return -EINVAL;

--
With Best Regards,
Andy Shevchenko