From: Lorenzo Bianconi <lorenzo@kernel.org>
To: Jonathan Cameron <jic23@kernel.org>
Cc: "Francesco Lavra" <flavra@baylibre.com>,
"David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v7 1/6] iio: imu: st_lsm6dsx: Fix check for invalid samples from FIFO
Date: Sat, 7 Mar 2026 16:23:33 +0100 [thread overview]
Message-ID: <aaxC9T75dtLR-AD8@lore-desk> (raw)
In-Reply-To: <20260307124629.7b4c3953@jic23-huawei>
[-- Attachment #1: Type: text/plain, Size: 4609 bytes --]
> On Wed, 4 Mar 2026 09:06:00 +0100
> Francesco Lavra <flavra@baylibre.com> wrote:
>
> > The DRDY_MASK feature implemented in sensor chips marks gyroscope and
> > accelerometer invalid samples (i.e. samples that have been acquired during
> > the settling time of sensor filters) with the special values 0x7FFFh,
> > 0x7FFE, and 0x7FFD.
> > The driver checks FIFO samples against these special values in order to
> > discard invalid samples; however, it does the check regardless of the type
> > of samples being processed, whereas this feature is specific to gyroscope
> > and accelerometer data. This could cause valid samples to be discarded.
> >
> > Fix the above check so that it takes into account the type of samples being
> > processed. To avoid casting to __le16 * when checking sample values, clean
> > up the type representation for data read from the FIFO.
> >
> > Fixes: 960506ed2c69 ("iio: imu: st_lsm6dsx: enable drdy-mask if available")
> > Signed-off-by: Francesco Lavra <flavra@baylibre.com>
> Looks fine to me, but looking for a Lorenzo tag ideally given it's not
> a particularly trivial fix!
>
> Jonathan
Hi Francesco,
thx for fixing this, I think the patch is fine, just a couple of nits inline if
you need to repost.
Regards,
Lorenzo
Acked-by: Lorenzo Bianconi <lorenzo@kernel.org>
> > ---
> > .../iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c | 23 +++++++++++--------
> > 1 file changed, 14 insertions(+), 9 deletions(-)
> >
> > diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c
> > index 5b28a3ffcc3d..a6ee2da5a06c 100644
> > --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c
> > +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c
> > @@ -365,8 +365,6 @@ static inline int st_lsm6dsx_read_block(struct st_lsm6dsx_hw *hw, u8 addr,
> > return 0;
> > }
> >
> > -#define ST_LSM6DSX_IIO_BUFF_SIZE (ALIGN(ST_LSM6DSX_SAMPLE_SIZE, \
> > - sizeof(s64)) + sizeof(s64))
> > /**
> > * st_lsm6dsx_read_fifo() - hw FIFO read routine
> > * @hw: Pointer to instance of struct st_lsm6dsx_hw.
> > @@ -539,14 +537,14 @@ int st_lsm6dsx_read_fifo(struct st_lsm6dsx_hw *hw)
> > #define ST_LSM6DSX_INVALID_SAMPLE 0x7ffd
> > static int
> > st_lsm6dsx_push_tagged_data(struct st_lsm6dsx_hw *hw, u8 tag,
> > - u8 *data, s64 ts)
> > + __le16 *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(data) >= ST_LSM6DSX_INVALID_SAMPLE)
> > return -EINVAL;
what about moving this check to a dedicated routine? Like
st_lsm6dsx_check_data() or similar?
> >
> > /*
> > @@ -609,7 +607,13 @@ int st_lsm6dsx_read_tagged_fifo(struct st_lsm6dsx_hw *hw)
> > * must be passed a buffer that is aligned to 8 bytes so
> > * as to allow insertion of a naturally aligned timestamp.
> > */
> > - u8 iio_buff[ST_LSM6DSX_IIO_BUFF_SIZE] __aligned(8);
> > + struct {
> > + union {
> > + __le16 data[3];
> > + __le32 fifo_ts;
> > + };
> > + aligned_s64 timestamp;
> > + } iio_buff = { };
you can get rid of space between brackets.
> > u8 tag;
> > bool reset_ts = false;
> > int i, err, read_len;
> > @@ -648,7 +652,7 @@ int st_lsm6dsx_read_tagged_fifo(struct st_lsm6dsx_hw *hw)
> >
> > for (i = 0; i < pattern_len;
> > i += ST_LSM6DSX_TAGGED_SAMPLE_SIZE) {
> > - memcpy(iio_buff, &hw->buff[i + ST_LSM6DSX_TAG_SIZE],
> > + memcpy(&iio_buff, &hw->buff[i + ST_LSM6DSX_TAG_SIZE],
> > ST_LSM6DSX_SAMPLE_SIZE);
> >
> > tag = hw->buff[i] >> 3;
> > @@ -659,7 +663,7 @@ int st_lsm6dsx_read_tagged_fifo(struct st_lsm6dsx_hw *hw)
> > * B0 = ts[7:0], B1 = ts[15:8], B2 = ts[23:16],
> > * B3 = ts[31:24]
> > */
> > - ts = le32_to_cpu(*((__le32 *)iio_buff));
> > + ts = le32_to_cpu(iio_buff.fifo_ts);
> > /*
> > * check if hw timestamp engine is going to
> > * reset (the sensor generates an interrupt
> > @@ -670,7 +674,8 @@ int st_lsm6dsx_read_tagged_fifo(struct st_lsm6dsx_hw *hw)
> > reset_ts = true;
> > ts *= hw->ts_gain;
> > } else {
> > - st_lsm6dsx_push_tagged_data(hw, tag, iio_buff,
> > + st_lsm6dsx_push_tagged_data(hw, tag,
> > + iio_buff.data,
> > ts);
> > }
> > }
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
next prev parent reply other threads:[~2026-03-07 15:23 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-04 8:05 [PATCH v7 0/6] imu: st_lsm6dsx: Add support for rotation sensor Francesco Lavra
2026-03-04 8:06 ` [PATCH v7 1/6] iio: imu: st_lsm6dsx: Fix check for invalid samples from FIFO Francesco Lavra
2026-03-07 12:46 ` Jonathan Cameron
2026-03-07 15:23 ` Lorenzo Bianconi [this message]
2026-03-07 17:04 ` Jonathan Cameron
2026-03-07 17:20 ` Lorenzo Bianconi
2026-03-04 8:06 ` [PATCH v7 2/6] iio: Replace 'sign' field with union in struct iio_scan_type Francesco Lavra
2026-03-04 22:55 ` David Lechner
2026-03-07 12:47 ` Jonathan Cameron
2026-03-07 13:10 ` Jonathan Cameron
2026-03-04 8:06 ` [PATCH v7 3/6] iio: tools: Add support for floating-point numbers in buffer scan elements Francesco Lavra
2026-03-04 22:53 ` David Lechner
2026-03-04 8:06 ` [PATCH v7 4/6] iio: ABI: " Francesco Lavra
2026-03-04 22:45 ` David Lechner
2026-03-05 9:09 ` Francesco Lavra
2026-03-05 9:23 ` Andy Shevchenko
2026-03-05 14:37 ` David Lechner
2026-03-06 12:09 ` Andy Shevchenko
2026-03-07 12:51 ` Jonathan Cameron
2026-03-17 10:40 ` Francesco Lavra
2026-03-04 8:07 ` [PATCH v7 5/6] iio: ABI: Add partial quaternion modifier Francesco Lavra
2026-03-04 11:51 ` Andy Shevchenko
2026-03-04 14:21 ` Francesco Lavra
2026-03-04 22:42 ` David Lechner
2026-03-05 8:50 ` Francesco Lavra
2026-03-05 14:40 ` David Lechner
2026-03-06 12:10 ` Andy Shevchenko
2026-03-04 19:25 ` kernel test robot
2026-03-04 22:35 ` David Lechner
2026-03-05 7:04 ` Andy Shevchenko
2026-03-07 13:00 ` Jonathan Cameron
2026-03-07 13:03 ` Jonathan Cameron
2026-03-08 20:27 ` Andy Shevchenko
2026-03-14 11:14 ` Jonathan Cameron
2026-03-07 13:05 ` Jonathan Cameron
2026-03-04 8:07 ` [PATCH v7 6/6] iio: imu: st_lsm6dsx: Add support for rotation sensor Francesco Lavra
2026-03-04 13:39 ` Andy Shevchenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aaxC9T75dtLR-AD8@lore-desk \
--to=lorenzo@kernel.org \
--cc=andy@kernel.org \
--cc=dlechner@baylibre.com \
--cc=flavra@baylibre.com \
--cc=jic23@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nuno.sa@analog.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox