* [PATCH 01/25] iio: adc: ti-ads131e08: fix the size of the scan buffer
2026-11-29 21:06 [PATCH 00/25] IIO: Various fixes mostly related to buffered capture Jonathan Cameron
@ 2026-11-29 21:06 ` Jonathan Cameron
2026-11-29 21:06 ` [PATCH 02/25] iio: potentiostat: lmp91000: fix NULL deref setting immutable trigger Jonathan Cameron
` (24 subsequent siblings)
25 siblings, 0 replies; 32+ messages in thread
From: Jonathan Cameron @ 2026-11-29 21:06 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Tomislav Denis, Matt Ranostay, Abhash Jha, Petre Rodan,
Mårten Lindahl, Dan Murphy, Sean Nyekjaer, Tomas Melin,
Michael Hennerich, Lars-Peter Clausen, Leonard Crestez,
Peter Meerwald-Stadler, Neil Armstrong, Dixit Parmar,
Matti Vaittinen, Stepan Ionichev, Srinivas Pandruvada,
Joachim Eastwood, Tiberiu Breana, Maxwell Doose, Tomasz Duszynski,
Alison Schofield, Christian Eggers, Andreas Klinger, linux-iio,
linux
Cc: Jonathan Cameron, stable
From: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
Each channel in the scan is __be32, but the scan buffer is sized for only
3 bytes per channel. If 7 or more channels + timestamp are enabled then
the buffer is too small and the check in iio_push_to_buffers_with_ts() will
reject the scan.
Declare the buffer with IIO_DECLARE_BUFFER_WITH_TS() as an array of
__be32, one for each possible channel, and drop unused
ADS131E08_NUM_STORAGE_BYTES.
Fixes: d935eddd2799 ("iio: adc: Add driver for Texas Instruments ADS131E0x ADC family")
Cc: stable@vger.kernel.org
Signed-off-by: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
---
Found by an LLM during some rework that touched this code.
---
drivers/iio/adc/ti-ads131e08.c | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/drivers/iio/adc/ti-ads131e08.c b/drivers/iio/adc/ti-ads131e08.c
index 14462a03fcdc..c120b26ae599 100644
--- a/drivers/iio/adc/ti-ads131e08.c
+++ b/drivers/iio/adc/ti-ads131e08.c
@@ -69,7 +69,7 @@
#define ADS131E08_NUM_DATA_BYTES_MAX 24
#define ADS131E08_NUM_DATA_BYTES(dr) (((dr) >= 32) ? 2 : 3)
#define ADS131E08_NUM_DATA_BITS(dr) (ADS131E08_NUM_DATA_BYTES(dr) * 8)
-#define ADS131E08_NUM_STORAGE_BYTES 4
+#define ADS131E08_MAX_CHANNELS 8
enum ads131e08_ids {
ads131e04,
@@ -100,10 +100,7 @@ struct ads131e08_state {
unsigned int reset_delay_us;
unsigned int readback_len;
struct completion completion;
- struct {
- u8 data[ADS131E08_NUM_DATA_BYTES_MAX];
- aligned_s64 ts;
- } tmp_buf;
+ IIO_DECLARE_BUFFER_WITH_TS(__be32, tmp_buf, ADS131E08_MAX_CHANNELS);
u8 tx_buf[3] __aligned(IIO_DMA_MINALIGN);
/*
@@ -637,7 +634,7 @@ static irqreturn_t ads131e08_trigger_handler(int irq, void *private)
iio_for_each_active_channel(indio_dev, chn) {
src = st->rx_buf + ADS131E08_NUM_STATUS_BYTES + chn * num_bytes;
- dest = st->tmp_buf.data + i * ADS131E08_NUM_STORAGE_BYTES;
+ dest = (u8 *)&st->tmp_buf[i];
/*
* Tweak offset is 0:
@@ -664,7 +661,7 @@ static irqreturn_t ads131e08_trigger_handler(int irq, void *private)
i++;
}
- iio_push_to_buffers_with_ts(indio_dev, &st->tmp_buf, sizeof(st->tmp_buf),
+ iio_push_to_buffers_with_ts(indio_dev, st->tmp_buf, sizeof(st->tmp_buf),
iio_get_time_ns(indio_dev));
out:
--
2.56.1
^ permalink raw reply related [flat|nested] 32+ messages in thread* [PATCH 02/25] iio: potentiostat: lmp91000: fix NULL deref setting immutable trigger
2026-11-29 21:06 [PATCH 00/25] IIO: Various fixes mostly related to buffered capture Jonathan Cameron
2026-11-29 21:06 ` [PATCH 01/25] iio: adc: ti-ads131e08: fix the size of the scan buffer Jonathan Cameron
@ 2026-11-29 21:06 ` Jonathan Cameron
2026-11-30 0:01 ` Jonathan Cameron
2026-11-29 21:06 ` [PATCH 03/25] iio: light: vl6180: notify trigger when reading data fails Jonathan Cameron
` (23 subsequent siblings)
25 siblings, 1 reply; 32+ messages in thread
From: Jonathan Cameron @ 2026-11-29 21:06 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Tomislav Denis, Matt Ranostay, Abhash Jha, Petre Rodan,
Mårten Lindahl, Dan Murphy, Sean Nyekjaer, Tomas Melin,
Michael Hennerich, Lars-Peter Clausen, Leonard Crestez,
Peter Meerwald-Stadler, Neil Armstrong, Dixit Parmar,
Matti Vaittinen, Stepan Ionichev, Srinivas Pandruvada,
Joachim Eastwood, Tiberiu Breana, Maxwell Doose, Tomasz Duszynski,
Alison Schofield, Christian Eggers, Andreas Klinger, linux-iio,
linux
Cc: Jonathan Cameron, stable
From: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
lmp91000_probe() calls iio_channel_cb_get_iio_dev(data->cb_buffer) to
find the ADC device on which to set the immutable trigger, but
data->cb_buffer is only assigned later by iio_channel_get_all_cb(). At
that point it is still NULL, so iio_channel_cb_get_iio_dev() dereferences
a NULL pointer.
The call also took place before the trigger was registered, which
triggers the WARN_ONCE() in iio_trigger_get() for an unregistered
trigger.
Move the call to after the callback buffer has been obtained, when the
trigger is also registered, and unwind the callback buffer on failure.
Fixes: 67e17300dc1d ("iio: potentiostat: add LMP91000 support")
Cc: stable@vger.kernel.org
Signed-off-by: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
---
LLM found this one whilst I was working on a broader cleanup.
Note despite this being a nasty bug I'll most likely take it for
the next merge window as I have a large series coming on top
of this.
---
drivers/iio/potentiostat/lmp91000.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/drivers/iio/potentiostat/lmp91000.c b/drivers/iio/potentiostat/lmp91000.c
index 53f181cbc0b8..676e5e962a93 100644
--- a/drivers/iio/potentiostat/lmp91000.c
+++ b/drivers/iio/potentiostat/lmp91000.c
@@ -330,13 +330,6 @@ static int lmp91000_probe(struct i2c_client *client)
if (ret)
return ret;
- ret = iio_trigger_set_immutable(iio_channel_cb_get_iio_dev(data->cb_buffer),
- data->trig);
- if (ret) {
- dev_err(dev, "cannot set immutable trigger.\n");
- return ret;
- }
-
ret = iio_trigger_register(data->trig);
if (ret) {
dev_err(dev, "cannot register iio trigger.\n");
@@ -363,6 +356,13 @@ static int lmp91000_probe(struct i2c_client *client)
data->adc_chan = iio_channel_cb_get_channels(data->cb_buffer);
+ ret = iio_trigger_set_immutable(iio_channel_cb_get_iio_dev(data->cb_buffer),
+ data->trig);
+ if (ret) {
+ dev_err(dev, "cannot set immutable trigger.\n");
+ goto error_unreg_cb_buffer;
+ }
+
ret = iio_device_register(indio_dev);
if (ret)
goto error_unreg_cb_buffer;
--
2.56.1
^ permalink raw reply related [flat|nested] 32+ messages in thread* Re: [PATCH 02/25] iio: potentiostat: lmp91000: fix NULL deref setting immutable trigger
2026-11-29 21:06 ` [PATCH 02/25] iio: potentiostat: lmp91000: fix NULL deref setting immutable trigger Jonathan Cameron
@ 2026-11-30 0:01 ` Jonathan Cameron
0 siblings, 0 replies; 32+ messages in thread
From: Jonathan Cameron @ 2026-11-30 0:01 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Tomislav Denis, Matt Ranostay, Abhash Jha, Petre Rodan,
Mårten Lindahl, Dan Murphy, Sean Nyekjaer, Tomas Melin,
Michael Hennerich, Lars-Peter Clausen, Leonard Crestez,
Peter Meerwald-Stadler, Neil Armstrong, Dixit Parmar,
Matti Vaittinen, Stepan Ionichev, Srinivas Pandruvada,
Joachim Eastwood, Tiberiu Breana, Maxwell Doose, Tomasz Duszynski,
Alison Schofield, Christian Eggers, Andreas Klinger, linux-iio,
linux
Cc: Jonathan Cameron, stable
On Sun, 29 Nov 2026 21:06:13 +0000
Jonathan Cameron <jic23@kernel.org> wrote:
> From: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
>
> lmp91000_probe() calls iio_channel_cb_get_iio_dev(data->cb_buffer) to
> find the ADC device on which to set the immutable trigger, but
> data->cb_buffer is only assigned later by iio_channel_get_all_cb(). At
> that point it is still NULL, so iio_channel_cb_get_iio_dev() dereferences
> a NULL pointer.
>
> The call also took place before the trigger was registered, which
> triggers the WARN_ONCE() in iio_trigger_get() for an unregistered
> trigger.
>
> Move the call to after the callback buffer has been obtained, when the
> trigger is also registered, and unwind the callback buffer on failure.
>
> Fixes: 67e17300dc1d ("iio: potentiostat: add LMP91000 support")
> Cc: stable@vger.kernel.org
> Signed-off-by: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
>
FWIW the sashiko comment on this one about leaking the immutable trigger
reference is entirely correct. It is addressed in the series that follows
which focuses on immutable triggers in general. For now, just leak it.
> ---
>
> LLM found this one whilst I was working on a broader cleanup.
> Note despite this being a nasty bug I'll most likely take it for
> the next merge window as I have a large series coming on top
> of this.
> ---
> drivers/iio/potentiostat/lmp91000.c | 14 +++++++-------
> 1 file changed, 7 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/iio/potentiostat/lmp91000.c b/drivers/iio/potentiostat/lmp91000.c
> index 53f181cbc0b8..676e5e962a93 100644
> --- a/drivers/iio/potentiostat/lmp91000.c
> +++ b/drivers/iio/potentiostat/lmp91000.c
> @@ -330,13 +330,6 @@ static int lmp91000_probe(struct i2c_client *client)
> if (ret)
> return ret;
>
> - ret = iio_trigger_set_immutable(iio_channel_cb_get_iio_dev(data->cb_buffer),
> - data->trig);
> - if (ret) {
> - dev_err(dev, "cannot set immutable trigger.\n");
> - return ret;
> - }
> -
> ret = iio_trigger_register(data->trig);
> if (ret) {
> dev_err(dev, "cannot register iio trigger.\n");
> @@ -363,6 +356,13 @@ static int lmp91000_probe(struct i2c_client *client)
>
> data->adc_chan = iio_channel_cb_get_channels(data->cb_buffer);
>
> + ret = iio_trigger_set_immutable(iio_channel_cb_get_iio_dev(data->cb_buffer),
> + data->trig);
> + if (ret) {
> + dev_err(dev, "cannot set immutable trigger.\n");
> + goto error_unreg_cb_buffer;
> + }
> +
> ret = iio_device_register(indio_dev);
> if (ret)
> goto error_unreg_cb_buffer;
>
^ permalink raw reply [flat|nested] 32+ messages in thread
* [PATCH 03/25] iio: light: vl6180: notify trigger when reading data fails
2026-11-29 21:06 [PATCH 00/25] IIO: Various fixes mostly related to buffered capture Jonathan Cameron
2026-11-29 21:06 ` [PATCH 01/25] iio: adc: ti-ads131e08: fix the size of the scan buffer Jonathan Cameron
2026-11-29 21:06 ` [PATCH 02/25] iio: potentiostat: lmp91000: fix NULL deref setting immutable trigger Jonathan Cameron
@ 2026-11-29 21:06 ` Jonathan Cameron
2026-11-29 21:06 ` [PATCH 04/25] iio: accel: bma220: return error if triggered buffer setup fails Jonathan Cameron
` (22 subsequent siblings)
25 siblings, 0 replies; 32+ messages in thread
From: Jonathan Cameron @ 2026-11-29 21:06 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Tomislav Denis, Matt Ranostay, Abhash Jha, Petre Rodan,
Mårten Lindahl, Dan Murphy, Sean Nyekjaer, Tomas Melin,
Michael Hennerich, Lars-Peter Clausen, Leonard Crestez,
Peter Meerwald-Stadler, Neil Armstrong, Dixit Parmar,
Matti Vaittinen, Stepan Ionichev, Srinivas Pandruvada,
Joachim Eastwood, Tiberiu Breana, Maxwell Doose, Tomasz Duszynski,
Alison Schofield, Christian Eggers, Andreas Klinger, linux-iio,
linux
Cc: Jonathan Cameron
From: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
If reading a channel value fails, vl6180_trigger_handler() returns
IRQ_HANDLED without calling iio_trigger_notify_done(). The trigger's
use count is then never decremented, so the trigger does not fire again
and buffered capture stops.
Jump to the end of the handler instead, so the trigger is notified and,
as on a successful read, the interrupt flag is cleared.
Fixes: eeebe3937cfc ("iio: light: vl6180: Add support for Continuous Mode")
Signed-off-by: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
---
Found by an LLM whilst doing a larger rework. Part of that was looking
at consistency of return values. If we claim to have handled the interrupt
the state should be maintained to match that even if no data was pushed.
---
drivers/iio/light/vl6180.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/iio/light/vl6180.c b/drivers/iio/light/vl6180.c
index 249d383b5292..9aebc970f007 100644
--- a/drivers/iio/light/vl6180.c
+++ b/drivers/iio/light/vl6180.c
@@ -556,13 +556,14 @@ static irqreturn_t vl6180_trigger_handler(int irq, void *priv)
if (ret < 0) {
dev_err(&data->client->dev,
"failed to read from value regs: %d\n", ret);
- return IRQ_HANDLED;
+ goto done;
}
scan.chan[i++] = ret;
}
iio_push_to_buffers_with_ts(indio_dev, &scan, sizeof(scan), time_ns);
+done:
iio_trigger_notify_done(indio_dev->trig);
/* Clear the interrupt flag after data read */
--
2.56.1
^ permalink raw reply related [flat|nested] 32+ messages in thread* [PATCH 04/25] iio: accel: bma220: return error if triggered buffer setup fails
2026-11-29 21:06 [PATCH 00/25] IIO: Various fixes mostly related to buffered capture Jonathan Cameron
` (2 preceding siblings ...)
2026-11-29 21:06 ` [PATCH 03/25] iio: light: vl6180: notify trigger when reading data fails Jonathan Cameron
@ 2026-11-29 21:06 ` Jonathan Cameron
2026-11-29 21:06 ` [PATCH 05/25] iio: adc: ti-adc084s021: don't push stale data if the conversion fails Jonathan Cameron
` (21 subsequent siblings)
25 siblings, 0 replies; 32+ messages in thread
From: Jonathan Cameron @ 2026-11-29 21:06 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Tomislav Denis, Matt Ranostay, Abhash Jha, Petre Rodan,
Mårten Lindahl, Dan Murphy, Sean Nyekjaer, Tomas Melin,
Michael Hennerich, Lars-Peter Clausen, Leonard Crestez,
Peter Meerwald-Stadler, Neil Armstrong, Dixit Parmar,
Matti Vaittinen, Stepan Ionichev, Srinivas Pandruvada,
Joachim Eastwood, Tiberiu Breana, Maxwell Doose, Tomasz Duszynski,
Alison Schofield, Christian Eggers, Andreas Klinger, linux-iio,
linux
Cc: Jonathan Cameron, stable
From: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
The conversion to dev_err_probe() dropped the return of the error code
when devm_iio_triggered_buffer_setup() fails. Probe then carries on and
registers the IIO device without a buffer.
Return the error as was done prior to that change.
Fixes: 5c27f1332282 ("iio: accel: bma220: migrate to regmap API")
Cc: stable@vger.kernel.org
Signed-off-by: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
---
drivers/iio/accel/bma220_core.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/iio/accel/bma220_core.c b/drivers/iio/accel/bma220_core.c
index 23eff578158c..4771352dee68 100644
--- a/drivers/iio/accel/bma220_core.c
+++ b/drivers/iio/accel/bma220_core.c
@@ -554,7 +554,7 @@ int bma220_common_probe(struct device *dev, struct regmap *regmap, int irq)
ret = devm_iio_triggered_buffer_setup(dev, indio_dev, NULL,
bma220_trigger_handler, NULL);
if (ret < 0)
- dev_err_probe(dev, ret, "iio triggered buffer setup failed\n");
+ return dev_err_probe(dev, ret, "iio triggered buffer setup failed\n");
return devm_iio_device_register(dev, indio_dev);
}
--
2.56.1
^ permalink raw reply related [flat|nested] 32+ messages in thread* [PATCH 05/25] iio: adc: ti-adc084s021: don't push stale data if the conversion fails
2026-11-29 21:06 [PATCH 00/25] IIO: Various fixes mostly related to buffered capture Jonathan Cameron
` (3 preceding siblings ...)
2026-11-29 21:06 ` [PATCH 04/25] iio: accel: bma220: return error if triggered buffer setup fails Jonathan Cameron
@ 2026-11-29 21:06 ` Jonathan Cameron
2026-11-29 21:06 ` [PATCH 06/25] iio: adc: ti-ads124s08: don't push data if reading a channel fails Jonathan Cameron
` (20 subsequent siblings)
25 siblings, 0 replies; 32+ messages in thread
From: Jonathan Cameron @ 2026-11-29 21:06 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Tomislav Denis, Matt Ranostay, Abhash Jha, Petre Rodan,
Mårten Lindahl, Dan Murphy, Sean Nyekjaer, Tomas Melin,
Michael Hennerich, Lars-Peter Clausen, Leonard Crestez,
Peter Meerwald-Stadler, Neil Armstrong, Dixit Parmar,
Matti Vaittinen, Stepan Ionichev, Srinivas Pandruvada,
Joachim Eastwood, Tiberiu Breana, Maxwell Doose, Tomasz Duszynski,
Alison Schofield, Christian Eggers, Andreas Klinger, linux-iio,
linux
Cc: Jonathan Cameron
From: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
If the SPI transfer fails, the trigger handler logs an error but still
pushes the scan buffer, which then holds the data from the previous
scan. Return without pushing anything instead.
Whilst repeated data may not be a signfiicant problem, avoiding this
also avoids potential edge cases around reconfiguration of the scan.
Fixes: 3691e5a69449 ("iio: adc: add driver for the ti-adc084s021 chip")
Signed-off-by: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
---
Found by LLM during a larger rework.
---
drivers/iio/adc/ti-adc084s021.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/iio/adc/ti-adc084s021.c b/drivers/iio/adc/ti-adc084s021.c
index cf2f6ee59411..b34b115af956 100644
--- a/drivers/iio/adc/ti-adc084s021.c
+++ b/drivers/iio/adc/ti-adc084s021.c
@@ -147,11 +147,14 @@ static irqreturn_t adc084s021_buffer_trigger_handler(int irq, void *pollfunc)
mutex_lock(&adc->lock);
- if (adc084s021_adc_conversion(adc, adc->scan.channels) < 0)
+ if (adc084s021_adc_conversion(adc, adc->scan.channels) < 0) {
dev_err(&adc->spi->dev, "Failed to read data\n");
+ goto out_unlock;
+ }
iio_push_to_buffers_with_ts(indio_dev, &adc->scan, sizeof(adc->scan),
iio_get_time_ns(indio_dev));
+out_unlock:
mutex_unlock(&adc->lock);
iio_trigger_notify_done(indio_dev->trig);
--
2.56.1
^ permalink raw reply related [flat|nested] 32+ messages in thread* [PATCH 06/25] iio: adc: ti-ads124s08: don't push data if reading a channel fails
2026-11-29 21:06 [PATCH 00/25] IIO: Various fixes mostly related to buffered capture Jonathan Cameron
` (4 preceding siblings ...)
2026-11-29 21:06 ` [PATCH 05/25] iio: adc: ti-adc084s021: don't push stale data if the conversion fails Jonathan Cameron
@ 2026-11-29 21:06 ` Jonathan Cameron
2026-11-29 21:06 ` [PATCH 07/25] iio: adc: ti-ads8688: don't push an error code as a sample Jonathan Cameron
` (19 subsequent siblings)
25 siblings, 0 replies; 32+ messages in thread
From: Jonathan Cameron @ 2026-11-29 21:06 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Tomislav Denis, Matt Ranostay, Abhash Jha, Petre Rodan,
Mårten Lindahl, Dan Murphy, Sean Nyekjaer, Tomas Melin,
Michael Hennerich, Lars-Peter Clausen, Leonard Crestez,
Peter Meerwald-Stadler, Neil Armstrong, Dixit Parmar,
Matti Vaittinen, Stepan Ionichev, Srinivas Pandruvada,
Joachim Eastwood, Tiberiu Breana, Maxwell Doose, Tomasz Duszynski,
Alison Schofield, Christian Eggers, Andreas Klinger, linux-iio,
linux
Cc: Jonathan Cameron
From: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
The trigger handler only logs an error if setting the input mux,
starting or stopping a conversion fails, and goes on to push the
buffer anyway. Worse, if the SPI transfer in ads124s_read() fails, the
negative error code is stored in the buffer as if it were a sample.
Skip pushing the buffer on each of these errors, and add an
error message for the read failure to match the others.
Fixes: e717f8c6dfec ("iio: adc: Add the TI ads124s08 ADC code")
Signed-off-by: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
---
Found during preparation of a rework (LLM assisted). This code
will get cleaned up a lot as part of that, so for now the minimal
rather ugly approach is used.
---
drivers/iio/adc/ti-ads124s08.c | 21 +++++++++++++++++----
1 file changed, 17 insertions(+), 4 deletions(-)
diff --git a/drivers/iio/adc/ti-ads124s08.c b/drivers/iio/adc/ti-ads124s08.c
index 49fbc63508ac..4731513483b3 100644
--- a/drivers/iio/adc/ti-ads124s08.c
+++ b/drivers/iio/adc/ti-ads124s08.c
@@ -281,17 +281,29 @@ static irqreturn_t ads124s_trigger_handler(int irq, void *p)
iio_for_each_active_channel(indio_dev, scan_index) {
ret = ads124s_write_reg(indio_dev, ADS124S08_INPUT_MUX,
scan_index);
- if (ret)
+ if (ret) {
dev_err(&priv->spi->dev, "Set ADC CH failed\n");
+ goto out_notify;
+ }
ret = ads124s_write_cmd(indio_dev, ADS124S08_START_CONV);
- if (ret)
+ if (ret) {
dev_err(&priv->spi->dev, "Start ADC conversions failed\n");
+ goto out_notify;
+ }
+
+ ret = ads124s_read(indio_dev);
+ if (ret < 0) {
+ dev_err(&priv->spi->dev, "Read ADC data failed\n");
+ goto out_notify;
+ }
+ priv->buffer[j] = ret;
- priv->buffer[j] = ads124s_read(indio_dev);
ret = ads124s_write_cmd(indio_dev, ADS124S08_STOP_CONV);
- if (ret)
+ if (ret) {
dev_err(&priv->spi->dev, "Stop ADC conversions failed\n");
+ goto out_notify;
+ }
j++;
}
@@ -299,6 +311,7 @@ static irqreturn_t ads124s_trigger_handler(int irq, void *p)
iio_push_to_buffers_with_ts(indio_dev, priv->buffer, sizeof(priv->buffer),
pf->timestamp);
+out_notify:
iio_trigger_notify_done(indio_dev->trig);
return IRQ_HANDLED;
--
2.56.1
^ permalink raw reply related [flat|nested] 32+ messages in thread* [PATCH 07/25] iio: adc: ti-ads8688: don't push an error code as a sample
2026-11-29 21:06 [PATCH 00/25] IIO: Various fixes mostly related to buffered capture Jonathan Cameron
` (5 preceding siblings ...)
2026-11-29 21:06 ` [PATCH 06/25] iio: adc: ti-ads124s08: don't push data if reading a channel fails Jonathan Cameron
@ 2026-11-29 21:06 ` Jonathan Cameron
2026-11-29 21:06 ` [PATCH 08/25] iio: adc: ti-ads8688: take the lock in the trigger handler Jonathan Cameron
` (18 subsequent siblings)
25 siblings, 0 replies; 32+ messages in thread
From: Jonathan Cameron @ 2026-11-29 21:06 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Tomislav Denis, Matt Ranostay, Abhash Jha, Petre Rodan,
Mårten Lindahl, Dan Murphy, Sean Nyekjaer, Tomas Melin,
Michael Hennerich, Lars-Peter Clausen, Leonard Crestez,
Peter Meerwald-Stadler, Neil Armstrong, Dixit Parmar,
Matti Vaittinen, Stepan Ionichev, Srinivas Pandruvada,
Joachim Eastwood, Tiberiu Breana, Maxwell Doose, Tomasz Duszynski,
Alison Schofield, Christian Eggers, Andreas Klinger, linux-iio,
linux
Cc: Jonathan Cameron, stable
From: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
If the SPI transfer in ads8688_read() fails, the trigger handler stores
the negative error code in the buffer as if it were a sample and pushes
it to userspace. Skip pushing the scan if any of the reads fail.
Fixes: 2a86487786b5 ("iio: adc: ti-ads8688: add trigger and buffer support")
Cc: stable@vger.kernel.org
Signed-off-by: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
---
LLM assisted and found during a rework that will change this code a lot
so minimal fix for now.
---
drivers/iio/adc/ti-ads8688.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/drivers/iio/adc/ti-ads8688.c b/drivers/iio/adc/ti-ads8688.c
index 8ad070b5ec4c..5702b814b940 100644
--- a/drivers/iio/adc/ti-ads8688.c
+++ b/drivers/iio/adc/ti-ads8688.c
@@ -379,15 +379,21 @@ static irqreturn_t ads8688_trigger_handler(int irq, void *p)
/* Ensure naturally aligned timestamp */
u16 buffer[ADS8688_MAX_CHANNELS + sizeof(s64)/sizeof(u16)] __aligned(8) = { };
int i, j = 0;
+ int ret;
iio_for_each_active_channel(indio_dev, i) {
- buffer[j] = ads8688_read(indio_dev, i);
+ ret = ads8688_read(indio_dev, i);
+ if (ret < 0)
+ goto out;
+
+ buffer[j] = ret;
j++;
}
iio_push_to_buffers_with_ts(indio_dev, buffer, sizeof(buffer),
iio_get_time_ns(indio_dev));
+out:
iio_trigger_notify_done(indio_dev->trig);
return IRQ_HANDLED;
--
2.56.1
^ permalink raw reply related [flat|nested] 32+ messages in thread* [PATCH 08/25] iio: adc: ti-ads8688: take the lock in the trigger handler
2026-11-29 21:06 [PATCH 00/25] IIO: Various fixes mostly related to buffered capture Jonathan Cameron
` (6 preceding siblings ...)
2026-11-29 21:06 ` [PATCH 07/25] iio: adc: ti-ads8688: don't push an error code as a sample Jonathan Cameron
@ 2026-11-29 21:06 ` Jonathan Cameron
2026-11-29 21:06 ` [PATCH 09/25] iio: adc: ti-ads8688: fix the endianness in the channel description Jonathan Cameron
` (17 subsequent siblings)
25 siblings, 0 replies; 32+ messages in thread
From: Jonathan Cameron @ 2026-11-29 21:06 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Tomislav Denis, Matt Ranostay, Abhash Jha, Petre Rodan,
Mårten Lindahl, Dan Murphy, Sean Nyekjaer, Tomas Melin,
Michael Hennerich, Lars-Peter Clausen, Leonard Crestez,
Peter Meerwald-Stadler, Neil Armstrong, Dixit Parmar,
Matti Vaittinen, Stepan Ionichev, Srinivas Pandruvada,
Joachim Eastwood, Tiberiu Breana, Maxwell Doose, Tomasz Duszynski,
Alison Schofield, Christian Eggers, Andreas Klinger, linux-iio,
linux
Cc: Jonathan Cameron, stable
From: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
The SPI transfer buffers in struct ads8688_state are shared between all
accesses to the device. The lock must be held to protect that shared
data.
Fixes: 2a86487786b5 ("iio: adc: ti-ads8688: add trigger and buffer support")
Cc: stable@vger.kernel.org
Signed-off-by: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
---
drivers/iio/adc/ti-ads8688.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/iio/adc/ti-ads8688.c b/drivers/iio/adc/ti-ads8688.c
index 5702b814b940..1e51cc7853b7 100644
--- a/drivers/iio/adc/ti-ads8688.c
+++ b/drivers/iio/adc/ti-ads8688.c
@@ -376,11 +376,13 @@ static irqreturn_t ads8688_trigger_handler(int irq, void *p)
{
struct iio_poll_func *pf = p;
struct iio_dev *indio_dev = pf->indio_dev;
+ struct ads8688_state *st = iio_priv(indio_dev);
/* Ensure naturally aligned timestamp */
u16 buffer[ADS8688_MAX_CHANNELS + sizeof(s64)/sizeof(u16)] __aligned(8) = { };
int i, j = 0;
int ret;
+ mutex_lock(&st->lock);
iio_for_each_active_channel(indio_dev, i) {
ret = ads8688_read(indio_dev, i);
if (ret < 0)
@@ -394,6 +396,7 @@ static irqreturn_t ads8688_trigger_handler(int irq, void *p)
iio_get_time_ns(indio_dev));
out:
+ mutex_unlock(&st->lock);
iio_trigger_notify_done(indio_dev->trig);
return IRQ_HANDLED;
--
2.56.1
^ permalink raw reply related [flat|nested] 32+ messages in thread* [PATCH 09/25] iio: adc: ti-ads8688: fix the endianness in the channel description
2026-11-29 21:06 [PATCH 00/25] IIO: Various fixes mostly related to buffered capture Jonathan Cameron
` (7 preceding siblings ...)
2026-11-29 21:06 ` [PATCH 08/25] iio: adc: ti-ads8688: take the lock in the trigger handler Jonathan Cameron
@ 2026-11-29 21:06 ` Jonathan Cameron
2026-11-29 21:06 ` [PATCH 10/25] iio: accel: sca3300: hold the lock across error handling in register access Jonathan Cameron
` (16 subsequent siblings)
25 siblings, 0 replies; 32+ messages in thread
From: Jonathan Cameron @ 2026-11-29 21:06 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Tomislav Denis, Matt Ranostay, Abhash Jha, Petre Rodan,
Mårten Lindahl, Dan Murphy, Sean Nyekjaer, Tomas Melin,
Michael Hennerich, Lars-Peter Clausen, Leonard Crestez,
Peter Meerwald-Stadler, Neil Armstrong, Dixit Parmar,
Matti Vaittinen, Stepan Ionichev, Srinivas Pandruvada,
Joachim Eastwood, Tiberiu Breana, Maxwell Doose, Tomasz Duszynski,
Alison Schofield, Christian Eggers, Andreas Klinger, linux-iio,
linux
Cc: Jonathan Cameron, stable
From: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
The buffer is filled using ads8688_read() which converts the sample to CPU
endianness. Hence the scan_type is incorrect and userspace will flip the
ordering on little endian systems.
Fixes: 2a86487786b5 ("iio: adc: ti-ads8688: add trigger and buffer support")
Cc: stable@vger.kernel.org
Signed-off-by: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
---
drivers/iio/adc/ti-ads8688.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/iio/adc/ti-ads8688.c b/drivers/iio/adc/ti-ads8688.c
index 1e51cc7853b7..a85a6bec17d4 100644
--- a/drivers/iio/adc/ti-ads8688.c
+++ b/drivers/iio/adc/ti-ads8688.c
@@ -133,7 +133,7 @@ static const int ads8688_offset_avail[] = {
.sign = 'u', \
.realbits = 16, \
.storagebits = 16, \
- .endianness = IIO_BE, \
+ .endianness = IIO_CPU, \
}, \
}
--
2.56.1
^ permalink raw reply related [flat|nested] 32+ messages in thread* [PATCH 10/25] iio: accel: sca3300: hold the lock across error handling in register access
2026-11-29 21:06 [PATCH 00/25] IIO: Various fixes mostly related to buffered capture Jonathan Cameron
` (8 preceding siblings ...)
2026-11-29 21:06 ` [PATCH 09/25] iio: adc: ti-ads8688: fix the endianness in the channel description Jonathan Cameron
@ 2026-11-29 21:06 ` Jonathan Cameron
2026-11-29 21:06 ` [PATCH 11/25] iio: imu: adis16400: don't push stale data if the SPI transfer fails Jonathan Cameron
` (15 subsequent siblings)
25 siblings, 0 replies; 32+ messages in thread
From: Jonathan Cameron @ 2026-11-29 21:06 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Tomislav Denis, Matt Ranostay, Abhash Jha, Petre Rodan,
Mårten Lindahl, Dan Murphy, Sean Nyekjaer, Tomas Melin,
Michael Hennerich, Lars-Peter Clausen, Leonard Crestez,
Peter Meerwald-Stadler, Neil Armstrong, Dixit Parmar,
Matti Vaittinen, Stepan Ionichev, Srinivas Pandruvada,
Joachim Eastwood, Tiberiu Breana, Maxwell Doose, Tomasz Duszynski,
Alison Schofield, Christian Eggers, Andreas Klinger, linux-iio,
linux
Cc: Jonathan Cameron, stable
From: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
sca3300_read_reg() and sca3300_write_reg() drop the lock after the
transfer and sca3300_error_handler() then takes it again to read the
status register. This leaves a window in which another access can use
the shared transfer buffers, or read and so clear the status, between
the failed transfer and reading its status.
Hold the lock over the entire sequence.
Fixes: 9cc9806e2217 ("iio: accel: Add driver for Murata SCA3300 accelerometer")
Cc: stable@vger.kernel.org
Signed-off-by: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
---
LLM found during larger rework. I'll be back to refactor the driver
to make more use of cleanup.h in that series. Hence keeping this focused
on the fixes.
---
drivers/iio/accel/sca3300.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/drivers/iio/accel/sca3300.c b/drivers/iio/accel/sca3300.c
index 67582cc34149..010930d02871 100644
--- a/drivers/iio/accel/sca3300.c
+++ b/drivers/iio/accel/sca3300.c
@@ -6,6 +6,7 @@
*/
#include <linux/bitops.h>
+#include <linux/cleanup.h>
#include <linux/crc8.h>
#include <linux/delay.h>
#include <linux/kernel.h>
@@ -282,14 +283,13 @@ static int sca3300_transfer(struct sca3300_data *sca_data, int *val)
}
static int sca3300_error_handler(struct sca3300_data *sca_data)
+ __must_hold(&sca_data->lock)
{
int ret;
int val;
- mutex_lock(&sca_data->lock);
sca_data->txbuf[0] = SCA3300_REG_STATUS << 2;
ret = sca3300_transfer(sca_data, &val);
- mutex_unlock(&sca_data->lock);
/*
* Return status error is cleared after reading status register once,
* expect EINVAL here.
@@ -310,10 +310,10 @@ static int sca3300_read_reg(struct sca3300_data *sca_data, u8 reg, int *val)
{
int ret;
- mutex_lock(&sca_data->lock);
+ guard(mutex)(&sca_data->lock);
+
sca_data->txbuf[0] = reg << 2;
ret = sca3300_transfer(sca_data, val);
- mutex_unlock(&sca_data->lock);
if (ret != -EINVAL)
return ret;
@@ -325,12 +325,12 @@ static int sca3300_write_reg(struct sca3300_data *sca_data, u8 reg, int val)
int reg_val = 0;
int ret;
- mutex_lock(&sca_data->lock);
+ guard(mutex)(&sca_data->lock);
+
/* BIT(7) for write operation */
sca_data->txbuf[0] = BIT(7) | (reg << 2);
put_unaligned_be16(val, &sca_data->txbuf[1]);
ret = sca3300_transfer(sca_data, ®_val);
- mutex_unlock(&sca_data->lock);
if (ret != -EINVAL)
return ret;
--
2.56.1
^ permalink raw reply related [flat|nested] 32+ messages in thread* [PATCH 11/25] iio: imu: adis16400: don't push stale data if the SPI transfer fails
2026-11-29 21:06 [PATCH 00/25] IIO: Various fixes mostly related to buffered capture Jonathan Cameron
` (9 preceding siblings ...)
2026-11-29 21:06 ` [PATCH 10/25] iio: accel: sca3300: hold the lock across error handling in register access Jonathan Cameron
@ 2026-11-29 21:06 ` Jonathan Cameron
2026-11-29 21:06 ` [PATCH 12/25] iio: light: si1145: return IRQ_NONE if no interrupt is flagged Jonathan Cameron
` (14 subsequent siblings)
25 siblings, 0 replies; 32+ messages in thread
From: Jonathan Cameron @ 2026-11-29 21:06 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Tomislav Denis, Matt Ranostay, Abhash Jha, Petre Rodan,
Mårten Lindahl, Dan Murphy, Sean Nyekjaer, Tomas Melin,
Michael Hennerich, Lars-Peter Clausen, Leonard Crestez,
Peter Meerwald-Stadler, Neil Armstrong, Dixit Parmar,
Matti Vaittinen, Stepan Ionichev, Srinivas Pandruvada,
Joachim Eastwood, Tiberiu Breana, Maxwell Doose, Tomasz Duszynski,
Alison Schofield, Christian Eggers, Andreas Klinger, linux-iio,
linux
Cc: Jonathan Cameron, stable
From: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
If the SPI transfer fails, the trigger handler logs an error but still
pushes the buffer, which then holds the data from the previous scan.
Skip pushing the buffer instead.
Fixes: 5eda3550a3cc ("staging:iio:adis16400: Preallocate transfer message")
Cc: stable@vger.kernel.org
Signed-off-by: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
---
LLM found during prep of a large rework. Will be back to do more
thorough cleanup of this driver in that series.
---
drivers/iio/imu/adis16400.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/iio/imu/adis16400.c b/drivers/iio/imu/adis16400.c
index 79f2974d3777..af6042ecdd76 100644
--- a/drivers/iio/imu/adis16400.c
+++ b/drivers/iio/imu/adis16400.c
@@ -616,8 +616,10 @@ static irqreturn_t adis16400_trigger_handler(int irq, void *p)
int ret;
ret = spi_sync(adis->spi, &adis->msg);
- if (ret)
+ if (ret) {
dev_err(&adis->spi->dev, "Failed to read data: %d\n", ret);
+ goto out_notify;
+ }
if (st->variant->flags & ADIS16400_BURST_DIAG_STAT) {
buffer = adis->buffer + sizeof(u16);
@@ -636,7 +638,7 @@ static irqreturn_t adis16400_trigger_handler(int irq, void *p)
pf->timestamp);
}
-
+out_notify:
iio_trigger_notify_done(indio_dev->trig);
return IRQ_HANDLED;
--
2.56.1
^ permalink raw reply related [flat|nested] 32+ messages in thread* [PATCH 12/25] iio: light: si1145: return IRQ_NONE if no interrupt is flagged
2026-11-29 21:06 [PATCH 00/25] IIO: Various fixes mostly related to buffered capture Jonathan Cameron
` (10 preceding siblings ...)
2026-11-29 21:06 ` [PATCH 11/25] iio: imu: adis16400: don't push stale data if the SPI transfer fails Jonathan Cameron
@ 2026-11-29 21:06 ` Jonathan Cameron
2026-11-29 21:06 ` [PATCH 13/25] iio: magnetometer: als31300: print the regmap error code on read failure Jonathan Cameron
` (13 subsequent siblings)
25 siblings, 0 replies; 32+ messages in thread
From: Jonathan Cameron @ 2026-11-29 21:06 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Tomislav Denis, Matt Ranostay, Abhash Jha, Petre Rodan,
Mårten Lindahl, Dan Murphy, Sean Nyekjaer, Tomas Melin,
Michael Hennerich, Lars-Peter Clausen, Leonard Crestez,
Peter Meerwald-Stadler, Neil Armstrong, Dixit Parmar,
Matti Vaittinen, Stepan Ionichev, Srinivas Pandruvada,
Joachim Eastwood, Tiberiu Breana, Maxwell Doose, Tomasz Duszynski,
Alison Schofield, Christian Eggers, Andreas Klinger, linux-iio,
linux
Cc: Jonathan Cameron
From: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
In autonomous mode the trigger handler reads the interrupt status
register and, if none of the interrupts the driver enables are flagged,
does nothing further. The interrupt did not come from this device, so
return IRQ_NONE rather than reporting it as handled, and don't tell the
trigger that the driver is done with it, as is appropriate for an
interrupt that was not handled.
This case can occur due to the use of iio_trigger_generic_data_poll rather
than the devices own trigger checking the interrupt status flag.
Fixes: ac45e57f1590 ("iio: light: Add driver for Silabs si1132, si1141/2/3 and si1145/6/7 ambient light, uv index and proximity sensors")
Signed-off-by: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
---
LLM found during large cleanup.
This one is a little odd so I would like people to look closely at it.
Possibly the better fix is the much more complex change to a
trigger with a threaded handler that checks the register before
call iio_trigger_poll_nested(). I'm nervous to do that without hardware
but will if people thing it is the right approach.
More generally one of the reworks that follows relies on the return
value to decide whether we are done with the trigger or not - so for
that I need a higher level of consistency than we have today.
---
drivers/iio/light/si1145.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/iio/light/si1145.c b/drivers/iio/light/si1145.c
index b160dd5dba86..6c909243f255 100644
--- a/drivers/iio/light/si1145.c
+++ b/drivers/iio/light/si1145.c
@@ -460,7 +460,7 @@ static irqreturn_t si1145_trigger_handler(int irq, void *private)
if (ret < 0)
goto done;
if (!(irq_status & SI1145_MASK_ALL_IE))
- goto done;
+ return IRQ_NONE;
}
iio_for_each_active_channel(indio_dev, i) {
--
2.56.1
^ permalink raw reply related [flat|nested] 32+ messages in thread* [PATCH 13/25] iio: magnetometer: als31300: print the regmap error code on read failure
2026-11-29 21:06 [PATCH 00/25] IIO: Various fixes mostly related to buffered capture Jonathan Cameron
` (11 preceding siblings ...)
2026-11-29 21:06 ` [PATCH 12/25] iio: light: si1145: return IRQ_NONE if no interrupt is flagged Jonathan Cameron
@ 2026-11-29 21:06 ` Jonathan Cameron
2026-11-30 8:38 ` Neil Armstrong
2026-11-29 21:06 ` [PATCH 14/25] iio: magnetometer: tlv493d: fix polling for valid data Jonathan Cameron
` (12 subsequent siblings)
25 siblings, 1 reply; 32+ messages in thread
From: Jonathan Cameron @ 2026-11-29 21:06 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Tomislav Denis, Matt Ranostay, Abhash Jha, Petre Rodan,
Mårten Lindahl, Dan Murphy, Sean Nyekjaer, Tomas Melin,
Michael Hennerich, Lars-Peter Clausen, Leonard Crestez,
Peter Meerwald-Stadler, Neil Armstrong, Dixit Parmar,
Matti Vaittinen, Stepan Ionichev, Srinivas Pandruvada,
Joachim Eastwood, Tiberiu Breana, Maxwell Doose, Tomasz Duszynski,
Alison Schofield, Christian Eggers, Andreas Klinger, linux-iio,
linux
Cc: Jonathan Cameron
From: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
The error is stored in err not ret so currently missleading value is
included in the error message.
Fixes: 3c9b6fd74188 ("iio: magnetometer: add Allegro MicroSystems ALS31300 3-D Linear Hall Effect driver")
Signed-off-by: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
---
Not marked for stable given trivial nature of result.
LLM found during prep of a larger series.
---
drivers/iio/magnetometer/als31300.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/iio/magnetometer/als31300.c b/drivers/iio/magnetometer/als31300.c
index 2a2677428ed5..038d4d3ab827 100644
--- a/drivers/iio/magnetometer/als31300.c
+++ b/drivers/iio/magnetometer/als31300.c
@@ -129,7 +129,7 @@ static int als31300_get_measure(struct als31300_data *data,
/* Bail out on regmap_bulk_read() error */
if (err) {
- dev_err(data->dev, "read data failed, error %d\n", ret);
+ dev_err(data->dev, "read data failed, error %d\n", err);
ret = err;
goto out;
}
--
2.56.1
^ permalink raw reply related [flat|nested] 32+ messages in thread* Re: [PATCH 13/25] iio: magnetometer: als31300: print the regmap error code on read failure
2026-11-29 21:06 ` [PATCH 13/25] iio: magnetometer: als31300: print the regmap error code on read failure Jonathan Cameron
@ 2026-11-30 8:38 ` Neil Armstrong
0 siblings, 0 replies; 32+ messages in thread
From: Neil Armstrong @ 2026-11-30 8:38 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Tomislav Denis, Matt Ranostay, Abhash Jha, Petre Rodan,
Mårten Lindahl, Dan Murphy, Sean Nyekjaer, Tomas Melin,
Michael Hennerich, Lars-Peter Clausen, Leonard Crestez,
Peter Meerwald-Stadler, Dixit Parmar, Matti Vaittinen,
Stepan Ionichev, Srinivas Pandruvada, Joachim Eastwood,
Tiberiu Breana, Maxwell Doose, Tomasz Duszynski, Alison Schofield,
Christian Eggers, Andreas Klinger, linux-iio, linux
Cc: Jonathan Cameron
On 11/29/26 22:06, Jonathan Cameron wrote:
> From: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
>
> The error is stored in err not ret so currently missleading value is
> included in the error message.
>
> Fixes: 3c9b6fd74188 ("iio: magnetometer: add Allegro MicroSystems ALS31300 3-D Linear Hall Effect driver")
> Signed-off-by: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
>
> ---
> Not marked for stable given trivial nature of result.
> LLM found during prep of a larger series.
> ---
> drivers/iio/magnetometer/als31300.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/iio/magnetometer/als31300.c b/drivers/iio/magnetometer/als31300.c
> index 2a2677428ed5..038d4d3ab827 100644
> --- a/drivers/iio/magnetometer/als31300.c
> +++ b/drivers/iio/magnetometer/als31300.c
> @@ -129,7 +129,7 @@ static int als31300_get_measure(struct als31300_data *data,
>
> /* Bail out on regmap_bulk_read() error */
> if (err) {
> - dev_err(data->dev, "read data failed, error %d\n", ret);
> + dev_err(data->dev, "read data failed, error %d\n", err);
> ret = err;
> goto out;
> }
>
Reviewed-by: Neil Armstrong <neil.armstrong@linaro.org>
Thanks,
Neil
^ permalink raw reply [flat|nested] 32+ messages in thread
* [PATCH 14/25] iio: magnetometer: tlv493d: fix polling for valid data
2026-11-29 21:06 [PATCH 00/25] IIO: Various fixes mostly related to buffered capture Jonathan Cameron
` (12 preceding siblings ...)
2026-11-29 21:06 ` [PATCH 13/25] iio: magnetometer: als31300: print the regmap error code on read failure Jonathan Cameron
@ 2026-11-29 21:06 ` Jonathan Cameron
2026-11-29 21:06 ` [PATCH 15/25] iio: proximity: isl29501: don't push uninitialized data on read failure Jonathan Cameron
` (11 subsequent siblings)
25 siblings, 0 replies; 32+ messages in thread
From: Jonathan Cameron @ 2026-11-29 21:06 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Tomislav Denis, Matt Ranostay, Abhash Jha, Petre Rodan,
Mårten Lindahl, Dan Murphy, Sean Nyekjaer, Tomas Melin,
Michael Hennerich, Lars-Peter Clausen, Leonard Crestez,
Peter Meerwald-Stadler, Neil Armstrong, Dixit Parmar,
Matti Vaittinen, Stepan Ionichev, Srinivas Pandruvada,
Joachim Eastwood, Tiberiu Breana, Maxwell Doose, Tomasz Duszynski,
Alison Schofield, Christian Eggers, Andreas Klinger, linux-iio,
linux
Cc: Jonathan Cameron, stable
From: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
i2c_master_recv() returns the number of bytes read on success, not 0.
The read_poll_timeout() exit condition tests err for any non zero
value, so polling stops after the first successful read whether or not
the TLV493D_TEMP_CHANNEL bit indicates that the data is valid.
Only stop early on an error from i2c_master_recv().
Fixes: 106511d280c7 ("iio: magnetometer: add support for Infineon TLV493D 3D Magentic sensor")
Cc: stable@vger.kernel.org
Signed-off-by: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
---
drivers/iio/magnetometer/tlv493d.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/iio/magnetometer/tlv493d.c b/drivers/iio/magnetometer/tlv493d.c
index 234e3ce63ff7..126b68f6d3f6 100644
--- a/drivers/iio/magnetometer/tlv493d.c
+++ b/drivers/iio/magnetometer/tlv493d.c
@@ -210,7 +210,7 @@ static int tlv493d_get_measurements(struct tlv493d_data *data, s16 *x, s16 *y,
* Poll 3x the time of the sampling time.
*/
ret = read_poll_timeout(i2c_master_recv, err,
- err || !FIELD_GET(TLV493D_TEMP_CHANNEL, buff[TLV493D_RD_REG_TEMP]),
+ err < 0 || !FIELD_GET(TLV493D_TEMP_CHANNEL, buff[TLV493D_RD_REG_TEMP]),
sleep_us, 3 * sleep_us, false, data->client, buff,
ARRAY_SIZE(buff));
if (ret) {
--
2.56.1
^ permalink raw reply related [flat|nested] 32+ messages in thread* [PATCH 15/25] iio: proximity: isl29501: don't push uninitialized data on read failure
2026-11-29 21:06 [PATCH 00/25] IIO: Various fixes mostly related to buffered capture Jonathan Cameron
` (13 preceding siblings ...)
2026-11-29 21:06 ` [PATCH 14/25] iio: magnetometer: tlv493d: fix polling for valid data Jonathan Cameron
@ 2026-11-29 21:06 ` Jonathan Cameron
2026-11-29 21:06 ` [PATCH 16/25] iio: pressure: rohm-bm1390: only return IRQ_NONE if data ready is not set Jonathan Cameron
` (10 subsequent siblings)
25 siblings, 0 replies; 32+ messages in thread
From: Jonathan Cameron @ 2026-11-29 21:06 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Tomislav Denis, Matt Ranostay, Abhash Jha, Petre Rodan,
Mårten Lindahl, Dan Murphy, Sean Nyekjaer, Tomas Melin,
Michael Hennerich, Lars-Peter Clausen, Leonard Crestez,
Peter Meerwald-Stadler, Neil Armstrong, Dixit Parmar,
Matti Vaittinen, Stepan Ionichev, Srinivas Pandruvada,
Joachim Eastwood, Tiberiu Breana, Maxwell Doose, Tomasz Duszynski,
Alison Schofield, Christian Eggers, Andreas Klinger, linux-iio,
linux
Cc: Jonathan Cameron, stable
From: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
The trigger handler ignores the return value of isl29501_register_read().
If the read fails, value is left uninitialized and part of it is then
pushed to the buffer, leaking kernel stack contents to userspace.
Check the return value and don't push a sample if the read fails.
Fixes: de18e978d0cd ("iio: proximity: isl29501: fix buffered read on big-endian systems")
Cc: stable@vger.kernel.org
Signed-off-by: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
---
drivers/iio/proximity/isl29501.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/drivers/iio/proximity/isl29501.c b/drivers/iio/proximity/isl29501.c
index b337ee530972..69ee3456c60c 100644
--- a/drivers/iio/proximity/isl29501.c
+++ b/drivers/iio/proximity/isl29501.c
@@ -942,13 +942,18 @@ static irqreturn_t isl29501_trigger_handler(int irq, void *p)
u16 data;
aligned_s64 ts;
} scan = { };
+ int ret;
if (test_bit(ISL29501_DISTANCE_SCAN_INDEX, active_mask)) {
- isl29501_register_read(isl29501, REG_DISTANCE, &value);
+ ret = isl29501_register_read(isl29501, REG_DISTANCE, &value);
+ if (ret)
+ goto out_notify;
+
scan.data = value;
}
iio_push_to_buffers_with_ts(indio_dev, &scan, sizeof(scan), pf->timestamp);
+out_notify:
iio_trigger_notify_done(indio_dev->trig);
return IRQ_HANDLED;
--
2.56.1
^ permalink raw reply related [flat|nested] 32+ messages in thread* [PATCH 16/25] iio: pressure: rohm-bm1390: only return IRQ_NONE if data ready is not set
2026-11-29 21:06 [PATCH 00/25] IIO: Various fixes mostly related to buffered capture Jonathan Cameron
` (14 preceding siblings ...)
2026-11-29 21:06 ` [PATCH 15/25] iio: proximity: isl29501: don't push uninitialized data on read failure Jonathan Cameron
@ 2026-11-29 21:06 ` Jonathan Cameron
2026-11-30 11:03 ` Matti Vaittinen
2026-11-29 21:06 ` [PATCH 17/25] iio: accel: kxcjk-1013: claim direct mode for raw reads Jonathan Cameron
` (9 subsequent siblings)
25 siblings, 1 reply; 32+ messages in thread
From: Jonathan Cameron @ 2026-11-29 21:06 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Tomislav Denis, Matt Ranostay, Abhash Jha, Petre Rodan,
Mårten Lindahl, Dan Murphy, Sean Nyekjaer, Tomas Melin,
Michael Hennerich, Lars-Peter Clausen, Leonard Crestez,
Peter Meerwald-Stadler, Neil Armstrong, Dixit Parmar,
Matti Vaittinen, Stepan Ionichev, Srinivas Pandruvada,
Joachim Eastwood, Tiberiu Breana, Maxwell Doose, Tomasz Duszynski,
Alison Schofield, Christian Eggers, Andreas Klinger, linux-iio,
linux
Cc: Jonathan Cameron
From: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
bm1390_handle_trigger() returns false both when the status register
shows that data ready is not set and when reading the status or the
pressure fails. bm1390_trigger_handler() then always calls
iio_trigger_notify_done() but returns IRQ_RETVAL() of that result, so a
read error is reported as IRQ_NONE even though the trigger was handled
and notified.
Only return false from bm1390_handle_trigger() when data ready is not
set, treating read errors as handled, as was already the case for a
failed temperature read. In bm1390_trigger_handler() return IRQ_NONE
without notifying the trigger in that case, and otherwise notify it and
return IRQ_HANDLED.
This is a case where the simple 'fix' may not be the ideal one.
The alternative would be to move the status check to the trigger
itself. Thus not trigger if the flag is not set. That may have knock
on effects if that read must occur when other triggers are in use.
Cc: Matti Vaittinen <mazziesaccount@gmail.com>
Fixes: d07bf43d175a ("iio: pressure: rohm-bm1390: harden trigger handler against transient errors")
Signed-off-by: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
---
LLM found during rework for a more significant series.
For that I need consistency of return value and whether
iio_trigger_notify_done() is called. This corner case fell out of that
requirement.
---
drivers/iio/pressure/rohm-bm1390.c | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/drivers/iio/pressure/rohm-bm1390.c b/drivers/iio/pressure/rohm-bm1390.c
index 7a6a16cffb66..6d4764b0b5f2 100644
--- a/drivers/iio/pressure/rohm-bm1390.c
+++ b/drivers/iio/pressure/rohm-bm1390.c
@@ -630,7 +630,10 @@ static bool bm1390_handle_trigger(struct iio_dev *idev)
/* DRDY is acked by reading status reg */
ret = regmap_read(data->regmap, BM1390_REG_STATUS, &status);
- if (ret || !status)
+ if (ret)
+ return true;
+
+ if (!status)
return false;
dev_dbg(data->dev, "DRDY trig status 0x%x\n", status);
@@ -639,7 +642,7 @@ static bool bm1390_handle_trigger(struct iio_dev *idev)
ret = bm1390_pressure_read(data, &data->buf.pressure);
if (ret) {
dev_warn(data->dev, "sample read failed %d\n", ret);
- return false;
+ return true;
}
}
@@ -662,12 +665,13 @@ static irqreturn_t bm1390_trigger_handler(int irq, void *p)
{
struct iio_poll_func *pf = p;
struct iio_dev *idev = pf->indio_dev;
- bool result;
- result = bm1390_handle_trigger(idev);
+ if (!bm1390_handle_trigger(idev))
+ return IRQ_NONE;
+
iio_trigger_notify_done(idev->trig);
- return IRQ_RETVAL(result);
+ return IRQ_HANDLED;
}
/* Get timestamps and wake the thread if we need to read data */
--
2.56.1
^ permalink raw reply related [flat|nested] 32+ messages in thread* Re: [PATCH 16/25] iio: pressure: rohm-bm1390: only return IRQ_NONE if data ready is not set
2026-11-29 21:06 ` [PATCH 16/25] iio: pressure: rohm-bm1390: only return IRQ_NONE if data ready is not set Jonathan Cameron
@ 2026-11-30 11:03 ` Matti Vaittinen
2026-11-30 23:45 ` Jonathan Cameron
0 siblings, 1 reply; 32+ messages in thread
From: Matti Vaittinen @ 2026-11-30 11:03 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Tomislav Denis, Matt Ranostay, Abhash Jha, Petre Rodan,
Mårten Lindahl, Dan Murphy, Sean Nyekjaer, Tomas Melin,
Michael Hennerich, Lars-Peter Clausen, Leonard Crestez,
Peter Meerwald-Stadler, Neil Armstrong, Dixit Parmar,
Stepan Ionichev, Srinivas Pandruvada, Joachim Eastwood,
Tiberiu Breana, Maxwell Doose, Tomasz Duszynski, Alison Schofield,
Christian Eggers, Andreas Klinger, linux-iio, linux
Cc: Jonathan Cameron
On 29/11/2026 23:06, Jonathan Cameron wrote:
> From: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
>
> bm1390_handle_trigger() returns false both when the status register
> shows that data ready is not set and when reading the status or the
> pressure fails. bm1390_trigger_handler() then always calls
> iio_trigger_notify_done() but returns IRQ_RETVAL() of that result, so a
> read error is reported as IRQ_NONE even though the trigger was handled
> and notified.
>
> Only return false from bm1390_handle_trigger() when data ready is not
> set, treating read errors as handled,
I don't like this because, if we have a permanent error on
bus/controller preventing the read, then the IRQ is not acked from the
sensor. This is specifically why the code returned IRQ_NONE if read failed.
With the IRQ_NONE, the "IRQ storm" resulting from un-acked IRQs will
trigger the 'safety mechanism' disabling the IRQ from the host side. On
single processor systems (which are admittably getting rare), this can
be the difference between completely unresponsive, not debuggable
device, and a device which hangs for a while, and then spits the
"disabling IRQx nobody cared" print which is a strong hint regarding
what's going on.
> as was already the case for a
> failed temperature read.
I believe that reading the temperature does not have similar "acking"
functionality.
> In bm1390_trigger_handler() return IRQ_NONE
> without notifying the trigger in that case, and otherwise notify it and
> return IRQ_HANDLED.
I have a feeling that notifying was needed, so that the IIO handler
propagates the next IRQ to the driver's handler - which can then (in
case of a failing to ACK again due to a read error), return another
IRQ_NONE. This is paramount for the above mentioned "safety IRQ
disabling" to take a place.
It is entirely possible I don't see something, the trigger stuff is not
simple (to me). :) If so, please bear with me and explain.
> This is a case where the simple 'fix' may not be the ideal one.
> The alternative would be to move the status check to the trigger
> itself. Thus not trigger if the flag is not set. That may have knock
> on effects if that read must occur when other triggers are in use.
>
> Cc: Matti Vaittinen <mazziesaccount@gmail.com>
> Fixes: d07bf43d175a ("iio: pressure: rohm-bm1390: harden trigger handler against transient errors")
> Signed-off-by: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
> ---
> LLM found during rework for a more significant series.
> For that I need consistency of return value and whether
> iio_trigger_notify_done() is called. This corner case fell out of that
> requirement.
> ---
> drivers/iio/pressure/rohm-bm1390.c | 14 +++++++++-----
> 1 file changed, 9 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/iio/pressure/rohm-bm1390.c b/drivers/iio/pressure/rohm-bm1390.c
> index 7a6a16cffb66..6d4764b0b5f2 100644
> --- a/drivers/iio/pressure/rohm-bm1390.c
> +++ b/drivers/iio/pressure/rohm-bm1390.c
> @@ -630,7 +630,10 @@ static bool bm1390_handle_trigger(struct iio_dev *idev)
>
> /* DRDY is acked by reading status reg */
> ret = regmap_read(data->regmap, BM1390_REG_STATUS, &status);
> - if (ret || !status)
> + if (ret)
> + return true;
> +
> + if (!status)
> return false;
>
> dev_dbg(data->dev, "DRDY trig status 0x%x\n", status);
> @@ -639,7 +642,7 @@ static bool bm1390_handle_trigger(struct iio_dev *idev)
> ret = bm1390_pressure_read(data, &data->buf.pressure);
> if (ret) {
> dev_warn(data->dev, "sample read failed %d\n", ret);
> - return false;
> + return true;
> }
> }
>
> @@ -662,12 +665,13 @@ static irqreturn_t bm1390_trigger_handler(int irq, void *p)
> {
> struct iio_poll_func *pf = p;
> struct iio_dev *idev = pf->indio_dev;
> - bool result;
>
> - result = bm1390_handle_trigger(idev);
> + if (!bm1390_handle_trigger(idev))
> + return IRQ_NONE;
I really like this better than hiding the IRQ_NONE case in IRQ_RETVAL().
Anyhow, I think we should still call the iio_trigger_notify_done() or
the bm1390_handle_trigger() will not see another IRQ? If this is the
case, then we only get this one IRQ_NONE returned, which is not enough
for the kernel to disable offending IRQ. So, badly behaving sensor/bus
shall hang the system. (Now, I didn't check this from the code, I just
think this was exactly the issue that got fixed by the d07bf43d175a).
> iio_trigger_notify_done(idev->trig);
>
> - return IRQ_RETVAL(result);
> + return IRQ_HANDLED;
> }
>
> /* Get timestamps and wake the thread if we need to read data */
>
Yours,
-- Matti
--
Matti Vaittinen
Linux kernel developer at ROHM Semiconductor
Oulu Finland
~~ When things go utterly wrong vim users can always type :help! ~~
^ permalink raw reply [flat|nested] 32+ messages in thread* Re: [PATCH 16/25] iio: pressure: rohm-bm1390: only return IRQ_NONE if data ready is not set
2026-11-30 11:03 ` Matti Vaittinen
@ 2026-11-30 23:45 ` Jonathan Cameron
2026-12-02 16:01 ` Matti Vaittinen
0 siblings, 1 reply; 32+ messages in thread
From: Jonathan Cameron @ 2026-11-30 23:45 UTC (permalink / raw)
To: Matti Vaittinen
Cc: David Lechner, Nuno Sá, Andy Shevchenko, Tomislav Denis,
Matt Ranostay, Abhash Jha, Petre Rodan, Mårten Lindahl,
Dan Murphy, Sean Nyekjaer, Tomas Melin, Michael Hennerich,
Lars-Peter Clausen, Leonard Crestez, Peter Meerwald-Stadler,
Neil Armstrong, Dixit Parmar, Stepan Ionichev,
Srinivas Pandruvada, Joachim Eastwood, Tiberiu Breana,
Maxwell Doose, Tomasz Duszynski, Alison Schofield,
Christian Eggers, Andreas Klinger, linux-iio, linux,
Jonathan Cameron
On Mon, 30 Nov 2026 13:03:23 +0200
Matti Vaittinen <mazziesaccount@gmail.com> wrote:
> On 29/11/2026 23:06, Jonathan Cameron wrote:
> > From: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
> >
> > bm1390_handle_trigger() returns false both when the status register
> > shows that data ready is not set and when reading the status or the
> > pressure fails. bm1390_trigger_handler() then always calls
> > iio_trigger_notify_done() but returns IRQ_RETVAL() of that result, so a
> > read error is reported as IRQ_NONE even though the trigger was handled
> > and notified.
> >
> > Only return false from bm1390_handle_trigger() when data ready is not
> > set, treating read errors as handled,
>
> I don't like this because, if we have a permanent error on
> bus/controller preventing the read, then the IRQ is not acked from the
> sensor. This is specifically why the code returned IRQ_NONE if read failed.
>
> With the IRQ_NONE, the "IRQ storm" resulting from un-acked IRQs will
> trigger the 'safety mechanism' disabling the IRQ from the host side. On
> single processor systems (which are admittably getting rare), this can
> be the difference between completely unresponsive, not debuggable
> device, and a device which hangs for a while, and then spits the
> "disabling IRQx nobody cared" print which is a strong hint regarding
> what's going on.
I fully agree with the argument for a general interrupt, but these
aren't real interrupts - those are on the trigger side of the
trigger /pollfunc divide. This part should not be deciding if we have
an interrupt but should be acting on that interrupt. The trigger
side should figure out if there is one to handle. Blocking that
real interrupt is the ideal outcome of the spurious IRQ detection
code.
I understand that divide gets tricky in some devices where the act
of reading the status register is required prior to a read because
otherwise we don't get fresh data.
I'm not sure if that change is possible here or not.
The self triggered case looks simple as it's either side of a function
call. For the case where we are using a different trigger I'm not sure
why we have the status check. Is it required to get valid data, or
is it to try and ensure fresh data (which we don't guarantee at all
if using a random trigger).
>
> > as was already the case for a
> > failed temperature read.
>
> I believe that reading the temperature does not have similar "acking"
> functionality.
>
> > In bm1390_trigger_handler() return IRQ_NONE
> > without notifying the trigger in that case, and otherwise notify it and
> > return IRQ_HANDLED.
>
> I have a feeling that notifying was needed, so that the IIO handler
> propagates the next IRQ to the driver's handler - which can then (in
> case of a failing to ACK again due to a read error), return another
> IRQ_NONE. This is paramount for the above mentioned "safety IRQ
> disabling" to take a place.
This is the tricky corner that I mention in reply to the cover letter.
I'm not sure if we should just always call iio_trigger_notify_done()
for this style of driver (one where it is expected to be called in
the interrupt handler). We can't do that in general because
there are a few drivers where that action be delayed to an entirely
different place in the code. A few series in my tree after this one
comes a patch that flags those less common cases and that allows us
to drop the need for explicit iio_trigger_notify_done() in vast majority
of drivers (with big knock on effects on code simplicity).
To me it does feel wrong to say we are done with a trigger when we haven't
done anything, but we do potentially end up wedged otherwise. Maybe
we can figure out a recovery path from that wedging but it is going
to be nasty code to handle an unlikely event.
>
> It is entirely possible I don't see something, the trigger stuff is not
> simple (to me). :) If so, please bear with me and explain.
>
Entirely valid questions! This was the bit of this series I least
liked. Ultimately we can separate IRQ_NONE from whether we call
iio_trigger_notify_done() but we do need consistency to enable
wider cleanup.
>
> > This is a case where the simple 'fix' may not be the ideal one.
> > The alternative would be to move the status check to the trigger
> > itself. Thus not trigger if the flag is not set. That may have knock
> > on effects if that read must occur when other triggers are in use.
> >
> > Cc: Matti Vaittinen <mazziesaccount@gmail.com>
> > Fixes: d07bf43d175a ("iio: pressure: rohm-bm1390: harden trigger handler against transient errors")
> > Signed-off-by: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
> > ---
> > LLM found during rework for a more significant series.
> > For that I need consistency of return value and whether
> > iio_trigger_notify_done() is called. This corner case fell out of that
> > requirement.
> > ---
> > drivers/iio/pressure/rohm-bm1390.c | 14 +++++++++-----
> > 1 file changed, 9 insertions(+), 5 deletions(-)
> >
> > diff --git a/drivers/iio/pressure/rohm-bm1390.c b/drivers/iio/pressure/rohm-bm1390.c
> > index 7a6a16cffb66..6d4764b0b5f2 100644
> > --- a/drivers/iio/pressure/rohm-bm1390.c
> > +++ b/drivers/iio/pressure/rohm-bm1390.c
> > @@ -630,7 +630,10 @@ static bool bm1390_handle_trigger(struct iio_dev *idev)
> >
> > /* DRDY is acked by reading status reg */
> > ret = regmap_read(data->regmap, BM1390_REG_STATUS, &status);
> > - if (ret || !status)
> > + if (ret)
> > + return true;
> > +
> > + if (!status)
> > return false;
> >
> > dev_dbg(data->dev, "DRDY trig status 0x%x\n", status);
> > @@ -639,7 +642,7 @@ static bool bm1390_handle_trigger(struct iio_dev *idev)
> > ret = bm1390_pressure_read(data, &data->buf.pressure);
> > if (ret) {
> > dev_warn(data->dev, "sample read failed %d\n", ret);
> > - return false;
> > + return true;
> > }
> > }
> >
> > @@ -662,12 +665,13 @@ static irqreturn_t bm1390_trigger_handler(int irq, void *p)
> > {
> > struct iio_poll_func *pf = p;
> > struct iio_dev *idev = pf->indio_dev;
> > - bool result;
> >
> > - result = bm1390_handle_trigger(idev);
> > + if (!bm1390_handle_trigger(idev))
> > + return IRQ_NONE;
>
> I really like this better than hiding the IRQ_NONE case in IRQ_RETVAL().
>
> Anyhow, I think we should still call the iio_trigger_notify_done() or
> the bm1390_handle_trigger() will not see another IRQ? If this is the
> case, then we only get this one IRQ_NONE returned, which is not enough
> for the kernel to disable offending IRQ. So, badly behaving sensor/bus
> shall hang the system. (Now, I didn't check this from the code, I just
> think this was exactly the issue that got fixed by the d07bf43d175a).
Yes. We do end up wedged if a trigger occurs as we then say 'no not
ours'.
>
> > iio_trigger_notify_done(idev->trig);
> >
> > - return IRQ_RETVAL(result);
> > + return IRQ_HANDLED;
> > }
> >
> > /* Get timestamps and wake the thread if we need to read data */
> >
>
> Yours,
> -- Matti
>
>
^ permalink raw reply [flat|nested] 32+ messages in thread* Re: [PATCH 16/25] iio: pressure: rohm-bm1390: only return IRQ_NONE if data ready is not set
2026-11-30 23:45 ` Jonathan Cameron
@ 2026-12-02 16:01 ` Matti Vaittinen
0 siblings, 0 replies; 32+ messages in thread
From: Matti Vaittinen @ 2026-12-02 16:01 UTC (permalink / raw)
To: Jonathan Cameron
Cc: David Lechner, Nuno Sá, Andy Shevchenko, Tomislav Denis,
Matt Ranostay, Abhash Jha, Petre Rodan, Mårten Lindahl,
Dan Murphy, Sean Nyekjaer, Tomas Melin, Michael Hennerich,
Lars-Peter Clausen, Leonard Crestez, Peter Meerwald-Stadler,
Neil Armstrong, Dixit Parmar, Stepan Ionichev,
Srinivas Pandruvada, Joachim Eastwood, Tiberiu Breana,
Maxwell Doose, Tomasz Duszynski, Alison Schofield,
Christian Eggers, Andreas Klinger, linux-iio, linux,
Jonathan Cameron
On 01/12/2026 01:45, Jonathan Cameron wrote:
> On Mon, 30 Nov 2026 13:03:23 +0200
> Matti Vaittinen <mazziesaccount@gmail.com> wrote:
>
>> On 29/11/2026 23:06, Jonathan Cameron wrote:
>>> From: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
>>>
>>> bm1390_handle_trigger() returns false both when the status register
>>> shows that data ready is not set and when reading the status or the
>>> pressure fails. bm1390_trigger_handler() then always calls
>>> iio_trigger_notify_done() but returns IRQ_RETVAL() of that result, so a
>>> read error is reported as IRQ_NONE even though the trigger was handled
>>> and notified.
>>>
>>> Only return false from bm1390_handle_trigger() when data ready is not
>>> set, treating read errors as handled,
>>
>> I don't like this because, if we have a permanent error on
>> bus/controller preventing the read, then the IRQ is not acked from the
>> sensor. This is specifically why the code returned IRQ_NONE if read failed.
>>
>> With the IRQ_NONE, the "IRQ storm" resulting from un-acked IRQs will
>> trigger the 'safety mechanism' disabling the IRQ from the host side. On
>> single processor systems (which are admittably getting rare), this can
>> be the difference between completely unresponsive, not debuggable
>> device, and a device which hangs for a while, and then spits the
>> "disabling IRQx nobody cared" print which is a strong hint regarding
>> what's going on.
>
> I fully agree with the argument for a general interrupt, but these
> aren't real interrupts - those are on the trigger side of the
> trigger /pollfunc divide.
Ah, right! I only now see this! (Dangnabbit, after I already wrote all
the other replies in this post - need to go edit them)
Maybe we can move the status-reading in bm1390_irq_thread_handler(),
inside the if (data->trigger_enabled)? Perhaps we should also store the
status in the driver data before calling the iio_trigger_poll_nested().
So, the trigger handler could then read the status if it was not read by
the trigger.
This part should not be deciding if we have
> an interrupt but should be acting on that interrupt. The trigger
> side should figure out if there is one to handle. Blocking that
> real interrupt is the ideal outcome of the spurious IRQ detection
> code.
>
> I understand that divide gets tricky in some devices where the act
> of reading the status register is required prior to a read because
> otherwise we don't get fresh data.
>
> I'm not sure if that change is possible here or not.
Not sure either :)
I did dig out my old questions I sent to the HQ, and answers I received.
Judging these, the status register reading will ACK the data-ready
interrupt (which is a level IRQ, so acking is required). It was not
explicitly said if new sample(s) are accepted while data-ready IRQ stays
active. The data-sheet however says that the data-ready should be used
as an indication, that there is new temperature and pressure data available.
Furthermore, reading the status register does NOT clear the FIFO_FULL or
WATERMARK IRQs. Those are cleared when samples are read and actual fifo
state changes.
> The self triggered case looks simple as it's either side of a function
> call.
This is probably the only case I thought of when writing the driver. I
have no idea if/how people are using this driver though. Anyways, I need
to admit I am not familiar with how things look when one is using some
other trigger. Never worked with such setup, so it's a bit hard for me
to picture. As a hindsight, I should probably have restricted this to
own trigger as it was the only trigger I ever really tested.
> For the case where we are using a different trigger I'm not sure
> why we have the status check. Is it required to get valid data, or
My understanding is that the data, after it has been sampled, can be
read without reading the status-register first. The data-sheet is not
explicit on this though. Anyways, if we don't read the status, we don't
actually know if the sampling had been done and if we had valid data in
registers. So yes, it is kind of required.
> is it to try and ensure fresh data (which we don't guarantee at all
> if using a random trigger).
I don't know if new data is sampled if data-ready is not acked. There is
no explicit information in data-sheet. It says that the data should be
read using burst-read to ensure it does not get partially overwritten -
but I don't know if this assumes the status has been read before data.
>>> as was already the case for a
>>> failed temperature read.
>>
>> I believe that reading the temperature does not have similar "acking"
>> functionality.
>>
>>> In bm1390_trigger_handler() return IRQ_NONE
>>> without notifying the trigger in that case, and otherwise notify it and
>>> return IRQ_HANDLED.
>>
>> I have a feeling that notifying was needed, so that the IIO handler
>> propagates the next IRQ to the driver's handler - which can then (in
>> case of a failing to ACK again due to a read error), return another
>> IRQ_NONE. This is paramount for the above mentioned "safety IRQ
>> disabling" to take a place.
>
> This is the tricky corner that I mention in reply to the cover letter.
> I'm not sure if we should just always call iio_trigger_notify_done()
> for this style of driver (one where it is expected to be called in
> the interrupt handler). We can't do that in general because
> there are a few drivers where that action be delayed to an entirely
> different place in the code. A few series in my tree after this one
> comes a patch that flags those less common cases and that allows us
> to drop the need for explicit iio_trigger_notify_done() in vast majority
> of drivers (with big knock on effects on code simplicity).
>
> To me it does feel wrong to say we are done with a trigger when we haven't
> done anything, but we do potentially end up wedged otherwise. Maybe
> we can figure out a recovery path from that wedging but it is going
> to be nasty code to handle an unlikely event.
If the bus to device is failing, then the only workaround I can think of
is disabling the host-side IRQ. This would be duplicating the IRQ_NONE
'safety logic' in IRQ core. Furthermore, if someone used shared IRQs,
then individual driver doing the disabling would really be stepping on
someone elses toes :) I'd rather kept this kind of decisions in the IRQ
core level. But yes - you're right that in this driver, the IRQ_NONE
should be returned from the bm1390_irq_thread_handler() !
>>
>> It is entirely possible I don't see something, the trigger stuff is not
>> simple (to me). :) If so, please bear with me and explain.
>>
>
> Entirely valid questions! This was the bit of this series I least
> liked. Ultimately we can separate IRQ_NONE from whether we call
> iio_trigger_notify_done()
To me this sounds like it could be the right thing to do. Not sure how
that should be done though. :)
> but we do need consistency to enable
> wider cleanup.
This is something you have far better understanding :)
I have some (very simple and limited) automated test set which is
testing the driver on a bm1390 attached to beaglebone, when new Linux
release (or tag from next) is done. Right now I can't offer much time
for bm1390 development - but I can at least run some basic test set on
patched kernel if needed. Not sure how beneficial it ends up being
though. The test set does not have anything to catch error scenarios
like an IRQ storm, but is mostly limited to measuring
pressure/temperature (in very constant environment) and checking the
values look somehow sane...
I will, however, add this to my (endless) TODO-list. Just please, don't
hold your breath waiting - we need you as the IIO maintainer (amongst
other things), so some level of oxygen should be guaranteed XD
Yours,
-- Matti
--
Matti Vaittinen
Linux kernel developer at ROHM Semiconductor
Oulu Finland
~~ When things go utterly wrong vim users can always type :help! ~~
^ permalink raw reply [flat|nested] 32+ messages in thread
* [PATCH 17/25] iio: accel: kxcjk-1013: claim direct mode for raw reads
2026-11-29 21:06 [PATCH 00/25] IIO: Various fixes mostly related to buffered capture Jonathan Cameron
` (15 preceding siblings ...)
2026-11-29 21:06 ` [PATCH 16/25] iio: pressure: rohm-bm1390: only return IRQ_NONE if data ready is not set Jonathan Cameron
@ 2026-11-29 21:06 ` Jonathan Cameron
2026-11-29 21:06 ` [PATCH 18/25] iio: accel: mma7455: " Jonathan Cameron
` (8 subsequent siblings)
25 siblings, 0 replies; 32+ messages in thread
From: Jonathan Cameron @ 2026-11-29 21:06 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Tomislav Denis, Matt Ranostay, Abhash Jha, Petre Rodan,
Mårten Lindahl, Dan Murphy, Sean Nyekjaer, Tomas Melin,
Michael Hennerich, Lars-Peter Clausen, Leonard Crestez,
Peter Meerwald-Stadler, Neil Armstrong, Dixit Parmar,
Matti Vaittinen, Stepan Ionichev, Srinivas Pandruvada,
Joachim Eastwood, Tiberiu Breana, Maxwell Doose, Tomasz Duszynski,
Alison Schofield, Christian Eggers, Andreas Klinger, linux-iio,
linux
Cc: Jonathan Cameron, stable
From: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
read_raw() checks iio_buffer_enabled() to refuse raw reads whilst the
buffer is in use, but nothing stops the buffer being enabled straight
after that check, whilst the read is still in progress.
Claim direct mode instead, which holds the device in direct mode until
the read is complete. Note that to avoid potential deadlocks that
claim must occur before taking the driver local lock.
Fixes: 1a4fbf6a9286 ("iio: accel: kxcjk1013 3-axis accelerometer driver")
Cc: stable@vger.kernel.org
Signed-off-by: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
---
The drivers doing this probably predate the option to claim the
mode.
---
drivers/iio/accel/kxcjk-1013.c | 36 +++++++++++++++++++-----------------
1 file changed, 19 insertions(+), 17 deletions(-)
diff --git a/drivers/iio/accel/kxcjk-1013.c b/drivers/iio/accel/kxcjk-1013.c
index bcf6b019b137..40b6d273e766 100644
--- a/drivers/iio/accel/kxcjk-1013.c
+++ b/drivers/iio/accel/kxcjk-1013.c
@@ -891,26 +891,28 @@ static int kxcjk1013_read_raw(struct iio_dev *indio_dev,
switch (mask) {
case IIO_CHAN_INFO_RAW:
+ if (!iio_device_claim_direct(indio_dev))
+ return -EBUSY;
+
mutex_lock(&data->mutex);
- if (iio_buffer_enabled(indio_dev))
- ret = -EBUSY;
- else {
- ret = kxcjk1013_set_power_state(data, true);
- if (ret < 0) {
- mutex_unlock(&data->mutex);
- return ret;
- }
- ret = kxcjk1013_get_acc_reg(data, chan->scan_index);
- if (ret < 0) {
- kxcjk1013_set_power_state(data, false);
- mutex_unlock(&data->mutex);
- return ret;
- }
- *val = sign_extend32(ret >> chan->scan_type.shift,
- chan->scan_type.realbits - 1);
- ret = kxcjk1013_set_power_state(data, false);
+ ret = kxcjk1013_set_power_state(data, true);
+ if (ret < 0) {
+ mutex_unlock(&data->mutex);
+ iio_device_release_direct(indio_dev);
+ return ret;
}
+ ret = kxcjk1013_get_acc_reg(data, chan->scan_index);
+ if (ret < 0) {
+ kxcjk1013_set_power_state(data, false);
+ mutex_unlock(&data->mutex);
+ iio_device_release_direct(indio_dev);
+ return ret;
+ }
+ *val = sign_extend32(ret >> chan->scan_type.shift,
+ chan->scan_type.realbits - 1);
+ ret = kxcjk1013_set_power_state(data, false);
mutex_unlock(&data->mutex);
+ iio_device_release_direct(indio_dev);
if (ret < 0)
return ret;
--
2.56.1
^ permalink raw reply related [flat|nested] 32+ messages in thread* [PATCH 18/25] iio: accel: mma7455: claim direct mode for raw reads
2026-11-29 21:06 [PATCH 00/25] IIO: Various fixes mostly related to buffered capture Jonathan Cameron
` (16 preceding siblings ...)
2026-11-29 21:06 ` [PATCH 17/25] iio: accel: kxcjk-1013: claim direct mode for raw reads Jonathan Cameron
@ 2026-11-29 21:06 ` Jonathan Cameron
2026-11-29 21:06 ` [PATCH 19/25] iio: accel: mxc4005: " Jonathan Cameron
` (7 subsequent siblings)
25 siblings, 0 replies; 32+ messages in thread
From: Jonathan Cameron @ 2026-11-29 21:06 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Tomislav Denis, Matt Ranostay, Abhash Jha, Petre Rodan,
Mårten Lindahl, Dan Murphy, Sean Nyekjaer, Tomas Melin,
Michael Hennerich, Lars-Peter Clausen, Leonard Crestez,
Peter Meerwald-Stadler, Neil Armstrong, Dixit Parmar,
Matti Vaittinen, Stepan Ionichev, Srinivas Pandruvada,
Joachim Eastwood, Tiberiu Breana, Maxwell Doose, Tomasz Duszynski,
Alison Schofield, Christian Eggers, Andreas Klinger, linux-iio,
linux
Cc: Jonathan Cameron, stable
From: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
read_raw() checks iio_buffer_enabled() to refuse raw reads whilst the
buffer is in use, but nothing stops the buffer being enabled straight
after that check, whilst the read is still in progress. Given the
use of the status register, this may end up stealing samples from
the buffered path.
Use IIO_DEV_ACQUIRE_DIRECT_MODE() instead, which holds the device in
direct mode until the read is complete.
Fixes: a84ef0d181d9 ("iio: accel: add Freescale MMA7455L/MMA7456L 3-axis accelerometer driver")
Cc: stable@vger.kernel.org
Signed-off-by: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
---
Note that this was found during preparation of a more substantial rework.
For this series I have kept to just the fix but expect cleanup to follow
shortly.
---
drivers/iio/accel/mma7455_core.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/drivers/iio/accel/mma7455_core.c b/drivers/iio/accel/mma7455_core.c
index a2b5bdf14dde..83e8d93fd5ab 100644
--- a/drivers/iio/accel/mma7455_core.c
+++ b/drivers/iio/accel/mma7455_core.c
@@ -10,6 +10,7 @@
* - Events
*/
+#include <linux/cleanup.h>
#include <linux/delay.h>
#include <linux/iio/iio.h>
#include <linux/iio/sysfs.h>
@@ -123,8 +124,9 @@ static int mma7455_read_raw(struct iio_dev *indio_dev,
int ret;
switch (mask) {
- case IIO_CHAN_INFO_RAW:
- if (iio_buffer_enabled(indio_dev))
+ case IIO_CHAN_INFO_RAW: {
+ IIO_DEV_ACQUIRE_DIRECT_MODE(indio_dev, claim);
+ if (IIO_DEV_ACQUIRE_FAILED(claim))
return -EBUSY;
ret = mma7455_drdy(mma7455);
@@ -140,6 +142,7 @@ static int mma7455_read_raw(struct iio_dev *indio_dev,
chan->scan_type.realbits - 1);
return IIO_VAL_INT;
+ }
case IIO_CHAN_INFO_SCALE:
*val = 0;
--
2.56.1
^ permalink raw reply related [flat|nested] 32+ messages in thread* [PATCH 19/25] iio: accel: mxc4005: claim direct mode for raw reads
2026-11-29 21:06 [PATCH 00/25] IIO: Various fixes mostly related to buffered capture Jonathan Cameron
` (17 preceding siblings ...)
2026-11-29 21:06 ` [PATCH 18/25] iio: accel: mma7455: " Jonathan Cameron
@ 2026-11-29 21:06 ` Jonathan Cameron
2026-11-29 21:06 ` [PATCH 20/25] iio: accel: stk8ba50: " Jonathan Cameron
` (6 subsequent siblings)
25 siblings, 0 replies; 32+ messages in thread
From: Jonathan Cameron @ 2026-11-29 21:06 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Tomislav Denis, Matt Ranostay, Abhash Jha, Petre Rodan,
Mårten Lindahl, Dan Murphy, Sean Nyekjaer, Tomas Melin,
Michael Hennerich, Lars-Peter Clausen, Leonard Crestez,
Peter Meerwald-Stadler, Neil Armstrong, Dixit Parmar,
Matti Vaittinen, Stepan Ionichev, Srinivas Pandruvada,
Joachim Eastwood, Tiberiu Breana, Maxwell Doose, Tomasz Duszynski,
Alison Schofield, Christian Eggers, Andreas Klinger, linux-iio,
linux
Cc: Jonathan Cameron
From: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
read_raw() checks iio_buffer_enabled() to refuse raw reads whilst the
buffer is in use, but nothing stops the buffer being enabled straight
after that check, whilst the read is still in progress.
Use IIO_DEV_ACQUIRE_DIRECT_MODE() instead, which holds the device in
direct mode until the read is complete.
Not marked as a fix whilst clearly not behaving as intended it is
not immediately obvious why direct mode must be held. The two
read paths both do bulk register reads but there seems to be no
stateful activity involved.
Signed-off-by: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
---
drivers/iio/accel/mxc4005.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/drivers/iio/accel/mxc4005.c b/drivers/iio/accel/mxc4005.c
index 2d4d09377397..995aa62eb397 100644
--- a/drivers/iio/accel/mxc4005.c
+++ b/drivers/iio/accel/mxc4005.c
@@ -5,6 +5,7 @@
* Copyright (c) 2014, Intel Corporation.
*/
+#include <linux/cleanup.h>
#include <linux/delay.h>
#include <linux/module.h>
#include <linux/i2c.h>
@@ -228,8 +229,9 @@ static int mxc4005_read_raw(struct iio_dev *indio_dev,
switch (mask) {
case IIO_CHAN_INFO_RAW:
switch (chan->type) {
- case IIO_ACCEL:
- if (iio_buffer_enabled(indio_dev))
+ case IIO_ACCEL: {
+ IIO_DEV_ACQUIRE_DIRECT_MODE(indio_dev, claim);
+ if (IIO_DEV_ACQUIRE_FAILED(claim))
return -EBUSY;
ret = mxc4005_read_axis(data, chan->address);
@@ -238,6 +240,7 @@ static int mxc4005_read_raw(struct iio_dev *indio_dev,
*val = sign_extend32(ret >> chan->scan_type.shift,
chan->scan_type.realbits - 1);
return IIO_VAL_INT;
+ }
default:
return -EINVAL;
}
--
2.56.1
^ permalink raw reply related [flat|nested] 32+ messages in thread* [PATCH 20/25] iio: accel: stk8ba50: claim direct mode for raw reads
2026-11-29 21:06 [PATCH 00/25] IIO: Various fixes mostly related to buffered capture Jonathan Cameron
` (18 preceding siblings ...)
2026-11-29 21:06 ` [PATCH 19/25] iio: accel: mxc4005: " Jonathan Cameron
@ 2026-11-29 21:06 ` Jonathan Cameron
2026-11-29 21:06 ` [PATCH 21/25] iio: chemical: scd30: claim direct mode before taking the lock in read_raw() Jonathan Cameron
` (5 subsequent siblings)
25 siblings, 0 replies; 32+ messages in thread
From: Jonathan Cameron @ 2026-11-29 21:06 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Tomislav Denis, Matt Ranostay, Abhash Jha, Petre Rodan,
Mårten Lindahl, Dan Murphy, Sean Nyekjaer, Tomas Melin,
Michael Hennerich, Lars-Peter Clausen, Leonard Crestez,
Peter Meerwald-Stadler, Neil Armstrong, Dixit Parmar,
Matti Vaittinen, Stepan Ionichev, Srinivas Pandruvada,
Joachim Eastwood, Tiberiu Breana, Maxwell Doose, Tomasz Duszynski,
Alison Schofield, Christian Eggers, Andreas Klinger, linux-iio,
linux
Cc: Jonathan Cameron, stable
From: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
read_raw() checks iio_buffer_enabled() to refuse raw reads whilst the
buffer is in use, but nothing stops the buffer being enabled straight
after that check, whilst the read is still in progress.
Use IIO_DEV_ACQUIRE_DIRECT_MODE() instead, which holds the device in
direct mode until the read is complete. Use guard() for the mutex at the
same time, as that avoids having to add explicit releases of direct mode
alongside the explicit unlocks on each of the exit paths.
Fixes: db6a19b8251f ("iio: accel: Add trigger support for STK8BA50")
Cc: stable@vger.kernel.org
Signed-off-by: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
---
Found during preparation of a large LLM assisted rework. Expect to
see much more general cleanup in that series.
---
drivers/iio/accel/stk8ba50.c | 18 ++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)
diff --git a/drivers/iio/accel/stk8ba50.c b/drivers/iio/accel/stk8ba50.c
index 2ae9a97524cc..064b7767729a 100644
--- a/drivers/iio/accel/stk8ba50.c
+++ b/drivers/iio/accel/stk8ba50.c
@@ -9,6 +9,7 @@
#include <linux/array_size.h>
#include <linux/bitops.h>
+#include <linux/cleanup.h>
#include <linux/dev_printk.h>
#include <linux/errno.h>
#include <linux/i2c.h>
@@ -218,26 +219,27 @@ static int stk8ba50_read_raw(struct iio_dev *indio_dev,
int ret;
switch (mask) {
- case IIO_CHAN_INFO_RAW:
- if (iio_buffer_enabled(indio_dev))
+ case IIO_CHAN_INFO_RAW: {
+ IIO_DEV_ACQUIRE_DIRECT_MODE(indio_dev, claim);
+ if (IIO_DEV_ACQUIRE_FAILED(claim))
return -EBUSY;
- mutex_lock(&data->lock);
+
+ guard(mutex)(&data->lock);
+
ret = stk8ba50_set_power(data, STK8BA50_MODE_NORMAL);
- if (ret < 0) {
- mutex_unlock(&data->lock);
+ if (ret < 0)
return -EINVAL;
- }
+
ret = stk8ba50_read_accel(data, chan->address);
if (ret < 0) {
stk8ba50_set_power(data, STK8BA50_MODE_SUSPEND);
- mutex_unlock(&data->lock);
return -EINVAL;
}
*val = sign_extend32(ret >> chan->scan_type.shift,
chan->scan_type.realbits - 1);
stk8ba50_set_power(data, STK8BA50_MODE_SUSPEND);
- mutex_unlock(&data->lock);
return IIO_VAL_INT;
+ }
case IIO_CHAN_INFO_SCALE:
*val = 0;
*val2 = stk8ba50_scale_table[data->range].scale_val;
--
2.56.1
^ permalink raw reply related [flat|nested] 32+ messages in thread* [PATCH 21/25] iio: chemical: scd30: claim direct mode before taking the lock in read_raw()
2026-11-29 21:06 [PATCH 00/25] IIO: Various fixes mostly related to buffered capture Jonathan Cameron
` (19 preceding siblings ...)
2026-11-29 21:06 ` [PATCH 20/25] iio: accel: stk8ba50: " Jonathan Cameron
@ 2026-11-29 21:06 ` Jonathan Cameron
2026-11-29 21:06 ` [PATCH 22/25] iio: humidity: hdc100x: " Jonathan Cameron
` (4 subsequent siblings)
25 siblings, 0 replies; 32+ messages in thread
From: Jonathan Cameron @ 2026-11-29 21:06 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Tomislav Denis, Matt Ranostay, Abhash Jha, Petre Rodan,
Mårten Lindahl, Dan Murphy, Sean Nyekjaer, Tomas Melin,
Michael Hennerich, Lars-Peter Clausen, Leonard Crestez,
Peter Meerwald-Stadler, Neil Armstrong, Dixit Parmar,
Matti Vaittinen, Stepan Ionichev, Srinivas Pandruvada,
Joachim Eastwood, Tiberiu Breana, Maxwell Doose, Tomasz Duszynski,
Alison Schofield, Christian Eggers, Andreas Klinger, linux-iio,
linux
Cc: Jonathan Cameron, stable
From: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
Prevents a fairly hard to hit deadlock.
read_raw() takes the driver's lock and then claims direct mode, which
can block on the IIO core's mode lock. The trigger handler takes the
same driver lock, and disabling the buffer holds the mode lock whilst
waiting for any running trigger handler to finish. A raw read racing
with disabling the buffer can therefore deadlock.
Claim direct mode, using IIO_DEV_ACQUIRE_DIRECT_MODE(), before taking
the lock. To allow this, take the lock only in the cases that need it,
using guard() with scope added to those cases. The scale case returns
constants so no longer takes the lock.
Fixes: 64b3d8b1b0f5 ("iio: chemical: scd30: add core driver")
Cc: stable@vger.kernel.org
Signed-off-by: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
---
Found during preparation of a larger rework. Expect more general
driver cleanup as part of that. Here we are focused on just fixes.
---
drivers/iio/chemical/scd30_core.c | 26 +++++++++++++++++---------
1 file changed, 17 insertions(+), 9 deletions(-)
diff --git a/drivers/iio/chemical/scd30_core.c b/drivers/iio/chemical/scd30_core.c
index 2710a3cf97a6..7437ecd86290 100644
--- a/drivers/iio/chemical/scd30_core.c
+++ b/drivers/iio/chemical/scd30_core.c
@@ -213,32 +213,36 @@ static int scd30_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const
int ret;
u16 tmp;
- guard(mutex)(&state->lock);
switch (mask) {
case IIO_CHAN_INFO_RAW:
- case IIO_CHAN_INFO_PROCESSED:
+ case IIO_CHAN_INFO_PROCESSED: {
if (chan->output) {
+ guard(mutex)(&state->lock);
+
*val = state->pressure_comp;
return IIO_VAL_INT;
}
- if (!iio_device_claim_direct(indio_dev))
+ IIO_DEV_ACQUIRE_DIRECT_MODE(indio_dev, claim);
+ if (IIO_DEV_ACQUIRE_FAILED(claim))
return -EBUSY;
+ guard(mutex)(&state->lock);
+
ret = scd30_read(state);
- if (ret) {
- iio_device_release_direct(indio_dev);
+ if (ret)
return ret;
- }
*val = state->meas[chan->address];
- iio_device_release_direct(indio_dev);
return IIO_VAL_INT;
+ }
case IIO_CHAN_INFO_SCALE:
*val = 0;
*val2 = 1;
return IIO_VAL_INT_PLUS_MICRO;
- case IIO_CHAN_INFO_SAMP_FREQ:
+ case IIO_CHAN_INFO_SAMP_FREQ: {
+ guard(mutex)(&state->lock);
+
ret = scd30_command_read(state, CMD_MEAS_INTERVAL, &tmp);
if (ret)
return ret;
@@ -246,13 +250,17 @@ static int scd30_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const
*val = 0;
*val2 = 1000000000 / tmp;
return IIO_VAL_INT_PLUS_NANO;
- case IIO_CHAN_INFO_CALIBBIAS:
+ }
+ case IIO_CHAN_INFO_CALIBBIAS: {
+ guard(mutex)(&state->lock);
+
ret = scd30_command_read(state, CMD_TEMP_OFFSET, &tmp);
if (ret)
return ret;
*val = tmp;
return IIO_VAL_INT;
+ }
default:
return -EINVAL;
}
--
2.56.1
^ permalink raw reply related [flat|nested] 32+ messages in thread* [PATCH 22/25] iio: humidity: hdc100x: claim direct mode before taking the lock in read_raw()
2026-11-29 21:06 [PATCH 00/25] IIO: Various fixes mostly related to buffered capture Jonathan Cameron
` (20 preceding siblings ...)
2026-11-29 21:06 ` [PATCH 21/25] iio: chemical: scd30: claim direct mode before taking the lock in read_raw() Jonathan Cameron
@ 2026-11-29 21:06 ` Jonathan Cameron
2026-11-29 21:06 ` [PATCH 23/25] iio: light: as73211: claim direct mode before taking the lock in write_raw() Jonathan Cameron
` (3 subsequent siblings)
25 siblings, 0 replies; 32+ messages in thread
From: Jonathan Cameron @ 2026-11-29 21:06 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Tomislav Denis, Matt Ranostay, Abhash Jha, Petre Rodan,
Mårten Lindahl, Dan Murphy, Sean Nyekjaer, Tomas Melin,
Michael Hennerich, Lars-Peter Clausen, Leonard Crestez,
Peter Meerwald-Stadler, Neil Armstrong, Dixit Parmar,
Matti Vaittinen, Stepan Ionichev, Srinivas Pandruvada,
Joachim Eastwood, Tiberiu Breana, Maxwell Doose, Tomasz Duszynski,
Alison Schofield, Christian Eggers, Andreas Klinger, linux-iio,
linux
Cc: Jonathan Cameron, stable
From: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
Prevents a fairly hard to hit deadlock.
read_raw() takes the driver's lock and then claims direct mode, which
can block on the IIO core's mode lock. The trigger handler takes the
same driver lock, and disabling the buffer holds the mode lock whilst
waiting for any running trigger handler to finish. A raw read racing
with disabling the buffer can therefore deadlock.
Claim direct mode, using IIO_DEV_ACQUIRE_DIRECT_MODE(), before taking
the lock, and take the lock separately for the heater status read,
which does not need direct mode.
Fixes: 16bf793f86b2 ("iio: humidity: hdc100x: add triggered buffer support for HDC100X")
Cc: stable@vger.kernel.org
Signed-off-by: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
---
Found during LLM assisted preparation of a larger rework.
Note like this entire series, build tested only. I didn't actually
trigger the deadlock.
---
drivers/iio/humidity/hdc100x.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/drivers/iio/humidity/hdc100x.c b/drivers/iio/humidity/hdc100x.c
index a01c66c6e2e5..3123d2ae0ec0 100644
--- a/drivers/iio/humidity/hdc100x.c
+++ b/drivers/iio/humidity/hdc100x.c
@@ -197,16 +197,20 @@ static int hdc100x_read_raw(struct iio_dev *indio_dev,
case IIO_CHAN_INFO_RAW: {
int ret;
- guard(mutex)(&data->lock);
if (chan->type == IIO_CURRENT) {
+ guard(mutex)(&data->lock);
+
*val = hdc100x_get_heater_status(data);
return IIO_VAL_INT;
}
- if (!iio_device_claim_direct(indio_dev))
+
+ IIO_DEV_ACQUIRE_DIRECT_MODE(indio_dev, claim);
+ if (IIO_DEV_ACQUIRE_FAILED(claim))
return -EBUSY;
+ guard(mutex)(&data->lock);
+
ret = hdc100x_get_measurement(data, chan);
- iio_device_release_direct(indio_dev);
if (ret < 0)
return ret;
*val = ret;
--
2.56.1
^ permalink raw reply related [flat|nested] 32+ messages in thread* [PATCH 23/25] iio: light: as73211: claim direct mode before taking the lock in write_raw()
2026-11-29 21:06 [PATCH 00/25] IIO: Various fixes mostly related to buffered capture Jonathan Cameron
` (21 preceding siblings ...)
2026-11-29 21:06 ` [PATCH 22/25] iio: humidity: hdc100x: " Jonathan Cameron
@ 2026-11-29 21:06 ` Jonathan Cameron
2026-11-29 21:06 ` [PATCH 24/25] iio: light: veml6046x00: claim direct mode before starting a single read Jonathan Cameron
` (2 subsequent siblings)
25 siblings, 0 replies; 32+ messages in thread
From: Jonathan Cameron @ 2026-11-29 21:06 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Tomislav Denis, Matt Ranostay, Abhash Jha, Petre Rodan,
Mårten Lindahl, Dan Murphy, Sean Nyekjaer, Tomas Melin,
Michael Hennerich, Lars-Peter Clausen, Leonard Crestez,
Peter Meerwald-Stadler, Neil Armstrong, Dixit Parmar,
Matti Vaittinen, Stepan Ionichev, Srinivas Pandruvada,
Joachim Eastwood, Tiberiu Breana, Maxwell Doose, Tomasz Duszynski,
Alison Schofield, Christian Eggers, Andreas Klinger, linux-iio,
linux
Cc: Jonathan Cameron, stable
From: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
Resolves a fairly hard to hit deadlock.
write_raw() takes the driver's lock and then claims direct mode, which
can block on the IIO core's mode lock. The trigger handler takes the
same driver lock, and disabling the buffer holds the mode lock whilst
waiting for any running trigger handler to finish. A write racing with
disabling the buffer can therefore deadlock.
Claim direct mode, using IIO_DEV_ACQUIRE_DIRECT_MODE(), before taking
the lock.
Fixes: 403e5586b52e ("iio: light: as73211: New driver")
Cc: stable@vger.kernel.org
Signed-off-by: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
---
Found during preparation of a larger LLM assisted rework.
Expect wider driver improvements in that.
Build tested only.
---
drivers/iio/light/as73211.c | 13 +++++--------
1 file changed, 5 insertions(+), 8 deletions(-)
diff --git a/drivers/iio/light/as73211.c b/drivers/iio/light/as73211.c
index 675866029cd7..f947f3eee1dc 100644
--- a/drivers/iio/light/as73211.c
+++ b/drivers/iio/light/as73211.c
@@ -609,17 +609,14 @@ static int as73211_write_raw(struct iio_dev *indio_dev, struct iio_chan_spec con
int val, int val2, long mask)
{
struct as73211_data *data = iio_priv(indio_dev);
- int ret;
+
+ IIO_DEV_ACQUIRE_DIRECT_MODE(indio_dev, claim);
+ if (IIO_DEV_ACQUIRE_FAILED(claim))
+ return -EBUSY;
guard(mutex)(&data->mutex);
- if (!iio_device_claim_direct(indio_dev))
- return -EBUSY;
-
- ret = _as73211_write_raw(indio_dev, chan, val, val2, mask);
- iio_device_release_direct(indio_dev);
-
- return ret;
+ return _as73211_write_raw(indio_dev, chan, val, val2, mask);
}
static irqreturn_t as73211_ready_handler(int irq __always_unused, void *priv)
--
2.56.1
^ permalink raw reply related [flat|nested] 32+ messages in thread* [PATCH 24/25] iio: light: veml6046x00: claim direct mode before starting a single read
2026-11-29 21:06 [PATCH 00/25] IIO: Various fixes mostly related to buffered capture Jonathan Cameron
` (22 preceding siblings ...)
2026-11-29 21:06 ` [PATCH 23/25] iio: light: as73211: claim direct mode before taking the lock in write_raw() Jonathan Cameron
@ 2026-11-29 21:06 ` Jonathan Cameron
2026-11-29 21:06 ` [PATCH 25/25] iio: magnetometer: bmc150_magn: claim direct mode for raw reads Jonathan Cameron
2026-11-30 0:20 ` [PATCH 00/25] IIO: Various fixes mostly related to buffered capture Jonathan Cameron
25 siblings, 0 replies; 32+ messages in thread
From: Jonathan Cameron @ 2026-11-29 21:06 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Tomislav Denis, Matt Ranostay, Abhash Jha, Petre Rodan,
Mårten Lindahl, Dan Murphy, Sean Nyekjaer, Tomas Melin,
Michael Hennerich, Lars-Peter Clausen, Leonard Crestez,
Peter Meerwald-Stadler, Neil Armstrong, Dixit Parmar,
Matti Vaittinen, Stepan Ionichev, Srinivas Pandruvada,
Joachim Eastwood, Tiberiu Breana, Maxwell Doose, Tomasz Duszynski,
Alison Schofield, Christian Eggers, Andreas Klinger, linux-iio,
linux
Cc: Jonathan Cameron
From: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
veml6046x00_single_read() only claims direct mode just before reading
the result, after it has already switched the device into single
measurement mode and triggered a conversion. A raw read whilst the
buffer is enabled therefore takes the device out of the continuous mode
set up by the buffer preenable callback before failing with -EBUSY,
disrupting the buffered capture.
Claim direct mode before touching the device.
Not entirely clear what impacts of this will be as a lot of state is
changed in this function.
Fixes: 4bfb29e8be73 ("iio: light: add support for veml6046x00 RGBIR color sensor")
Cc: stable@vger.kernel.org>
Signed-off-by: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
---
Build tested only.
Found during LLM assisted preparation of a much larger rework.
I have no idea what impact of this one is, but it definitely looks wrong!
---
drivers/iio/light/veml6046x00.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/drivers/iio/light/veml6046x00.c b/drivers/iio/light/veml6046x00.c
index b40b70679640..d28b404c1b49 100644
--- a/drivers/iio/light/veml6046x00.c
+++ b/drivers/iio/light/veml6046x00.c
@@ -661,9 +661,13 @@ static int veml6046x00_single_read(struct iio_dev *iio,
default:
return -EINVAL;
}
+
+ if (!iio_device_claim_direct(iio))
+ return -EBUSY;
+
ret = pm_runtime_resume_and_get(dev);
if (ret)
- return ret;
+ goto out_release;
ret = veml6046x00_get_it_usec(data, &it_usec);
if (ret < 0) {
@@ -694,13 +698,7 @@ static int veml6046x00_single_read(struct iio_dev *iio,
goto out;
}
- if (!iio_device_claim_direct(iio)) {
- ret = -EBUSY;
- goto out;
- }
-
ret = regmap_bulk_read(data->regmap, addr, ®, sizeof(reg));
- iio_device_release_direct(iio);
if (ret)
goto out;
@@ -710,6 +708,8 @@ static int veml6046x00_single_read(struct iio_dev *iio,
out:
pm_runtime_put_autosuspend(dev);
+out_release:
+ iio_device_release_direct(iio);
return ret;
}
--
2.56.1
^ permalink raw reply related [flat|nested] 32+ messages in thread* [PATCH 25/25] iio: magnetometer: bmc150_magn: claim direct mode for raw reads
2026-11-29 21:06 [PATCH 00/25] IIO: Various fixes mostly related to buffered capture Jonathan Cameron
` (23 preceding siblings ...)
2026-11-29 21:06 ` [PATCH 24/25] iio: light: veml6046x00: claim direct mode before starting a single read Jonathan Cameron
@ 2026-11-29 21:06 ` Jonathan Cameron
2026-11-30 0:20 ` [PATCH 00/25] IIO: Various fixes mostly related to buffered capture Jonathan Cameron
25 siblings, 0 replies; 32+ messages in thread
From: Jonathan Cameron @ 2026-11-29 21:06 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Tomislav Denis, Matt Ranostay, Abhash Jha, Petre Rodan,
Mårten Lindahl, Dan Murphy, Sean Nyekjaer, Tomas Melin,
Michael Hennerich, Lars-Peter Clausen, Leonard Crestez,
Peter Meerwald-Stadler, Neil Armstrong, Dixit Parmar,
Matti Vaittinen, Stepan Ionichev, Srinivas Pandruvada,
Joachim Eastwood, Tiberiu Breana, Maxwell Doose, Tomasz Duszynski,
Alison Schofield, Christian Eggers, Andreas Klinger, linux-iio,
linux
Cc: Jonathan Cameron
From: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
read_raw() checks iio_buffer_enabled() to refuse raw reads whilst the
buffer is in use, but nothing stops the buffer being enabled between
that check and the read. A raw read can then power down the device via
runtime PM and race with the trigger handler. Claim direct mode instead,
so that the buffer cannot be enabled until the read has finished.
No fixes tag here as whilst the code is intended to prevent this
race, it is not clear if it is necessary rather than simply desirable
to reduce interference with buffered capture.
Signed-off-by: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
---
Found during an LLM assisted significant rework. Much more cleanup
will follow as part of that series.
---
drivers/iio/magnetometer/bmc150_magn.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/iio/magnetometer/bmc150_magn.c b/drivers/iio/magnetometer/bmc150_magn.c
index 16b5c2451728..aec4b0a6f9ea 100644
--- a/drivers/iio/magnetometer/bmc150_magn.c
+++ b/drivers/iio/magnetometer/bmc150_magn.c
@@ -462,7 +462,8 @@ static int bmc150_magn_read_raw(struct iio_dev *indio_dev,
switch (mask) {
case IIO_CHAN_INFO_RAW: {
- if (iio_buffer_enabled(indio_dev))
+ IIO_DEV_ACQUIRE_DIRECT_MODE(indio_dev, claim);
+ if (IIO_DEV_ACQUIRE_FAILED(claim))
return -EBUSY;
guard(mutex)(&data->mutex);
--
2.56.1
^ permalink raw reply related [flat|nested] 32+ messages in thread* Re: [PATCH 00/25] IIO: Various fixes mostly related to buffered capture.
2026-11-29 21:06 [PATCH 00/25] IIO: Various fixes mostly related to buffered capture Jonathan Cameron
` (24 preceding siblings ...)
2026-11-29 21:06 ` [PATCH 25/25] iio: magnetometer: bmc150_magn: claim direct mode for raw reads Jonathan Cameron
@ 2026-11-30 0:20 ` Jonathan Cameron
25 siblings, 0 replies; 32+ messages in thread
From: Jonathan Cameron @ 2026-11-30 0:20 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Tomislav Denis, Matt Ranostay, Abhash Jha, Petre Rodan,
Mårten Lindahl, Dan Murphy, Sean Nyekjaer, Tomas Melin,
Michael Hennerich, Lars-Peter Clausen, Leonard Crestez,
Peter Meerwald-Stadler, Neil Armstrong, Dixit Parmar,
Matti Vaittinen, Stepan Ionichev, Srinivas Pandruvada,
Joachim Eastwood, Tiberiu Breana, Maxwell Doose, Tomasz Duszynski,
Alison Schofield, Christian Eggers, Andreas Klinger, linux-iio,
linux
Cc: Jonathan Cameron, stable
On Sun, 29 Nov 2026 21:06:11 +0000
Jonathan Cameron <jic23@kernel.org> wrote:
> I havee pulled this lot out as precursors of a major rework I plan to
> post shortly. That finally proposes a path to get rid of the need to
> call iio_trigger_notify_done() in most cases and allows a lot of
> related code improvements.
>
> There are a couple of patches in here that are 'probably not' fixes.
> That is I couldn't establish that bad things happen as opposed to ones
> outside of the intent of the driver author.
>
> Anyhow, please take a look. All LLM assisted (though I rewrote some
> commit messages for brevity and to add more commentary).
> Build tested only.
>
> I may hold off on sending the actual rework for a while given I'm dumping
> this set of fixes on the already overburdened reviewers!
Sashiko is correct about the potential wedging that occurs if we have
a trigger handler return IRQ_NONE and not call iio_trigger_notify_done().
I guess for those two drivers I'll have to look at the more substantial
rework mentioned in their commit messages or just not worry about
how we report "I got triggered but I shouldn't have done."
Note that if things go the way I want them to, we'll end up handling
the iio_trigger_notify_done() in the core by default, with the few drivers
where that can't be done setting a special flag to say they'll deal with
it asynchronously. I'm not posting the full series yet because there
are 245 more patches that I need to go through carefully first (after
the other series I just posted).
Jonathan
^ permalink raw reply [flat|nested] 32+ messages in thread