iio: pressure: rohm-bm1390: notify trigger on all error paths
Subsystems (3)
PATCH 1/1 iio: pressure: rohm-bm1390: notify trigger on all error paths
bm1390_trigger_handler() has three error returns:
if (ret || !status)
return IRQ_NONE; /* status read failed */
...
if (ret) {
dev_warn(...);
return IRQ_NONE; /* pressure read failed */
}
...
if (ret) {
dev_warn(...);
return IRQ_HANDLED; /* temp read failed */
}None of them call iio_trigger_notify_done(). The success path at the end does, so on a single transient regmap or pressure-read error the trigger never sees its use_count decremented, and the !atomic_read(&trig->use_count) guard in iio_trigger_poll_chained() drops every subsequent dispatch for that trigger. The buffered-data flow stays wedged until the trigger is detached.
The IRQ_HANDLED return on the temperature path additionally leaves the temp branch's last partial state in &data->buf.temp without pushing the sample, which is the existing intended behaviour; only the missing notify_done() needs fixing.
Funnel all returns through a single 'done' label that calls iio_trigger_notify_done() before returning the saved irqreturn_t.
--- drivers/iio/pressure/rohm-bm1390.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
drivers/iio/pressure/rohm-bm1390.c +10 -5
@@ -626,12 +626,15 @@ static irqreturn_t bm1390_trigger_handler(int irq, void *p)struct iio_poll_func *pf = p;struct iio_dev *idev = pf->indio_dev;struct bm1390_data *data =iio_priv (idev); +irqreturn_t result =IRQ_HANDLED ;int ret, status;/* DRDY is acked by reading status reg */ ret =regmap_read (data->regmap,BM1390_REG_STATUS , &status); -if (ret || !status) -return IRQ_NONE ; +if (ret || !status) { + result =IRQ_NONE ; + goto done; + }dev_dbg (data->dev,"DRDY trig status 0x%x\n" , status);
@@ -639,7 +642,8 @@ static irqreturn_t bm1390_trigger_handler(int irq, void *p) ret =bm1390_pressure_read (data, &data->buf.pressure);if (ret) {dev_warn (data->dev,"sample read failed %d\n" , ret); -return IRQ_NONE ; + result =IRQ_NONE ; + goto done; } }
@@ -648,15 +652,16 @@ static irqreturn_t bm1390_trigger_handler(int irq, void *p) &data->buf.temp, sizeof(data->buf.temp));if (ret) {dev_warn (data->dev,"temp read failed %d\n" , ret); -return IRQ_HANDLED ; + goto done; } }iio_push_to_buffers_with_ts (idev, &data->buf,sizeof (data->buf), data->timestamp); +done:iio_trigger_notify_done (idev->trig); -return IRQ_HANDLED ; +return result; }/* Get timestamps and wake the thread if we need to read data */
Signature · 1 line
2.43.0
David Lechner
reviewerQuoted 44 lines · Stepan Ionichev
bm1390_trigger_handler()has three error returns:if (ret || !status) return IRQ_NONE; /* status read failed */ ... if (ret) { dev_warn(...); return IRQ_NONE; /* pressure read failed */ } ... if (ret) { dev_warn(...); return IRQ_HANDLED; /* temp read failed */ }None of them call
iio_trigger_notify_done(). The success path at the end does, so on a single transient regmap or pressure-read error the trigger never sees itsuse_countdecremented, and the !atomic_read(&trig->use_count) guard iniio_trigger_poll_chained()drops every subsequent dispatch for that trigger. The buffered-data flow stays wedged until the trigger is detached.The
IRQ_HANDLEDreturn on the temperature path additionally leaves the temp branch's last partial state in&data->buf.tempwithout pushing the sample, which is the existing intended behaviour; only the missingnotify_done()needs fixing.Funnel all returns through a single 'done' label that calls
iio_trigger_notify_done()before returning the savedirqreturn_t.Fixes 81ca5979b6ed ("iio: pressure: Support ROHM BU1390")Signed-off-by Stepan Ionichev <[email protected]>--- drivers/iio/pressure/rohm-bm1390.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)drivers/iio/pressure/rohm-bm1390.c +0
-0@@ -626,12 +626,15 @@ static irqreturn_t bm1390_trigger_handler(int irq, void *p)struct iio_poll_func *pf = p;struct iio_dev *idev = pf->indio_dev;
drivers/iio/pressure/rohm-bm1390.c static irqreturn_t bm1390_trigger_handler(int irq, void *p) · line 635
Quoted 10 lines
drivers/iio/pressure/rohm-bm1390.c +3
-2struct bm1390_data *data =iio_priv (idev); +irqreturn_t result =IRQ_HANDLED ;int ret, status;/* DRDY is acked by reading status reg */ ret =regmap_read (data->regmap,BM1390_REG_STATUS , &status); -if (ret || !status) -return IRQ_NONE ; +if (ret || !status) { + result =IRQ_NONE ;
IRQ_NONE means that the interrupt wasn't handled, so it won't be cleared and the handler will likely just run again immediately. So it probably isn't the right thing to be returning in the first place.
Quoted 34 lines
drivers/iio/pressure/rohm-bm1390.c +7
-3+ goto done; + }dev_dbg (data->dev,"DRDY trig status 0x%x\n" , status);@@ -639,7 +642,8 @@ static irqreturn_t bm1390_trigger_handler(int irq, void *p) ret =bm1390_pressure_read (data, &data->buf.pressure);if (ret) {dev_warn (data->dev,"sample read failed %d\n" , ret); -return IRQ_NONE ; + result =IRQ_NONE ; + goto done; } }@@ -648,15 +652,16 @@ static irqreturn_t bm1390_trigger_handler(int irq, void *p) &data->buf.temp, sizeof(data->buf.temp));if (ret) {dev_warn (data->dev,"temp read failed %d\n" , ret); -return IRQ_HANDLED ; + goto done; } }iio_push_to_buffers_with_ts (idev, &data->buf,sizeof (data->buf), data->timestamp); +done:iio_trigger_notify_done (idev->trig); -return IRQ_HANDLED ; +return result; }/* Get timestamps and wake the thread if we need to read data */
Quoted 3 lines · David Lechner
IRQ_NONEmeans that the interrupt wasn't handled, so it won't be cleared and the handler will likely just run again immediately. So it probably isn't the right thing to be returning in the first place.
Right -- though here it is called via handle_nested_irq() from the threaded pollfunc, so the return value does not feed the IRQ controller and the immediate re-fire concern is moot in practice. But the IRQ_NONE choice is still odd.
Matti, do you want a v2 that always returns IRQ_HANDLED on the error paths instead, or keep the current shape and just fix the missing notify_done()?
Stepan
Matti Vaittinen
maintainerQuoted 16 lines · David Lechner
Quoted 15 lines · Stepan Ionichev
bm1390_trigger_handler()has three error returns:if (ret || !status) return IRQ_NONE; /* status read failed */ ... if (ret) { dev_warn(...); return IRQ_NONE; /* pressure read failed */ } ... if (ret) { dev_warn(...); return IRQ_HANDLED; /* temp read failed */ }
Quoted 6 lines
Quoted 6 lines
None of them call
iio_trigger_notify_done(). The success path at the end does, so on a single transient regmap or pressure-read error the trigger never sees itsuse_countdecremented, and the !atomic_read(&trig->use_count) guard iniio_trigger_poll_chained()drops every subsequent dispatch for that trigger. The buffered-data flow stays wedged until the trigger is detached.
I don't really know the intended logic of the use_count, so I'll leave this to those who understand it better. I'll just add some thoughts this invoked.
I think it is not really nice to require (or trust) drivers to call the "iio_trigger_notify_done()" if the handler fails. Maybe it would be better to do something like:
void iio_trigger_poll_nested(struct iio_trigger *trig)
{
int i;
if (!atomic_read(&trig->use_count)) {
atomic_set(&trig->use_count, CONFIG_IIO_CONSUMERS_PER_TRIGGER);
for (i = 0; i < CONFIG_IIO_CONSUMERS_PER_TRIGGER; i++) {
if (trig->subirqs[i].enabled)
handle_nested_irq(trig->subirq_base + i);
else
iio_trigger_notify_done(trig);
}
atomic_set(&trig->use_count, 0); /* Clear the use_count if drivers
didn't */
}
}to prevent this class of problems once and for all. But yeah, wiser minds have designed this - so let's hear some other opinions as well :)
Quoted 27 lines
Quoted 27 lines
The
IRQ_HANDLEDreturn on the temperature path additionally leaves the temp branch's last partial state in&data->buf.tempwithout pushing the sample, which is the existing intended behaviour; only the missingnotify_done()needs fixing.Funnel all returns through a single 'done' label that calls
iio_trigger_notify_done()before returning the savedirqreturn_t.Fixes 81ca5979b6ed ("iio: pressure: Support ROHM BU1390")Signed-off-by Stepan Ionichev <[email protected]>--- drivers/iio/pressure/rohm-bm1390.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)drivers/iio/pressure/rohm-bm1390.c +1
-0@@ -626,12 +626,15 @@ static irqreturn_t bm1390_trigger_handler(int irq, void *p)struct iio_poll_func *pf = p;struct iio_dev *idev = pf->indio_dev;struct bm1390_data *data =iio_priv (idev); +irqreturn_t result =IRQ_HANDLED ;int ret, status;
Quoted 10 lines
drivers/iio/pressure/rohm-bm1390.c static irqreturn_t bm1390_trigger_handler(int irq, void *p) · line 635
Quoted 6 lines
drivers/iio/pressure/rohm-bm1390.c +2
-2/* DRDY is acked by reading status reg */ ret =regmap_read (data->regmap,BM1390_REG_STATUS , &status); -if (ret || !status) -return IRQ_NONE ; +if (ret || !status) { + result =IRQ_NONE ;
IRQ_NONEmeans that the interrupt wasn't handled, so it won't be cleared and the handler will likely just run again immediately. So it probably isn't the right thing to be returning in the first place.
This is exactly why IRQ-none is returned, and what it is used for. If the problem with bus-access / device persists, the kernel will (after XXXX fails indicated by IRQ_NONE - don't remember exact numbers) disable the IRQ from the host side, and emit the, ass-saving, "nobody cared" -print.
This is (in my opinion) the only RightThing(tm). (Especially so, if the device is accessed from the fast handler, and is system is single-core). There is a tremendous difference when debugging a system which just hangs in IRQ loop forever (and you can't get no contact to it), and when debugging a system which, after a relatively short hang-up, let's you see the magic "nobody cared" -print telling a misbehaving IRQ was disabled.
Furthermore, if the status register read failure was a temporary one, then we should be getting new IRQ as soon as the handler exists. This should then successfully handle the IRQ.
Yours,
-- Matti
Signature · 6 lines
--- Matti Vaittinen Linux kernel developer at ROHM Semiconductors Oulu Finland ~~ When things go utterly wrong vim users can always type :help! ~~
Quoted 1 line · Stepan Ionichev
bm1390_trigger_handler()has three error returns:
...
drivers/iio/pressure/rohm-bm1390.c static irqreturn_t bm1390_trigger_handler(int irq, void *p) · line 629
Quoted 1 line
drivers/iio/pressure/rohm-bm1390.c +1
-0+irqreturn_t result =IRQ_HANDLED ;
Make result boolean and use IRQ_RETVAL() macro once.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 2 lines · Matti Vaittinen
Quoted 1 line · David Lechner
On 5/17/26 11:08 AM, Stepan Ionichev wrote:
...
Quoted 9 lines
Maybe it would be better to do something like:
void
iio_trigger_poll_nested(struct iio_trigger *trig){ int i; if (!atomic_read(&trig->use_count)) { atomic_set(&trig->use_count,
CONFIG_IIO_CONSUMERS_PER_TRIGGER);
Just in case somebody is going to do that, avoid doing atomic_read() followed by atomic_set(). This is typical TOCTOU issue. This should be something like atomic_xchg() or atomic_add_return() or something like this in a single atomic operation.
Quoted 13 lines
for (i = 0; i < CONFIG_IIO_CONSUMERS_PER_TRIGGER; i++) { if (trig->subirqs[i].enabled) handle_nested_irq(trig->subirq_base + i); else iio_trigger_notify_done(trig); } atomic_set(&trig->use_count, 0); /* Clear the use_count if drivers didn't */ } }to prevent this class of problems once and for all. But yeah, wiser minds have designed this - so let's hear some other opinions as well :)
Signature · 2 lines
With Best Regards, Andy Shevchenko
Matti Vaittinen
maintainerQuoted 12 lines · Andy Shevchenko
Quoted 2 lines · Matti Vaittinen
Quoted 1 line · David Lechner
On 5/17/26 11:08 AM, Stepan Ionichev wrote:
...
Quoted 6 lines
Maybe it would be better to do something like:
void
iio_trigger_poll_nested(struct iio_trigger *trig){ int i;
Quoted 8 lines
Quoted 3 lines
if (!atomic_read(&trig->use_count)) { atomic_set(&trig->use_count,
CONFIG_IIO_CONSUMERS_PER_TRIGGER);Just in case somebody is going to do that, avoid doing
atomic_read()followed byatomic_set(). This is typical TOCTOU issue. This should be something likeatomic_xchg()oratomic_add_return()or something like this in a single atomic operation.
Well spotted Andy. This is existing code, so perhaps this should be fixed if the logic won't be altered after this discussion.
Yours,
-- Matti
Signature · 5 lines
Matti Vaittinen Linux kernel developer at ROHM Semiconductors Oulu Finland ~~ When things go utterly wrong vim users can always type :help! ~~
PATCH v2 1/1 iio: pressure: rohm-bm1390: notify trigger on all error paths
In reply to Stepan Ionichevbm1390_trigger_handler() returns from three error paths without calling iio_trigger_notify_done(). The success path at the end does, so on a single transient regmap or read failure the trigger use_count is never decremented, and the !atomic_read(&trig->use_count) guard in iio_trigger_poll_chained() drops every subsequent dispatch. The buffered-data flow stays wedged until the trigger is detached.
Funnel all returns through a single done label that calls iio_trigger_notify_done() and reports the outcome via IRQ_RETVAL().
---
v2:
- Use a bool and IRQ_RETVAL() instead of irqreturn_t (Andy)
v1: https://lore.kernel.org/all/[email protected]/
drivers/iio/pressure/rohm-bm1390.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
drivers/iio/pressure/rohm-bm1390.c +10 -5
@@ -626,12 +626,15 @@ static irqreturn_t bm1390_trigger_handler(int irq, void *p)struct iio_poll_func *pf = p;struct iio_dev *idev = pf->indio_dev;struct bm1390_data *data =iio_priv (idev); +bool handled = true;int ret, status;/* DRDY is acked by reading status reg */ ret =regmap_read (data->regmap,BM1390_REG_STATUS , &status); -if (ret || !status) -return IRQ_NONE ; +if (ret || !status) { + handled = false; + goto done; + }dev_dbg (data->dev,"DRDY trig status 0x%x\n" , status);
@@ -639,7 +642,8 @@ static irqreturn_t bm1390_trigger_handler(int irq, void *p) ret =bm1390_pressure_read (data, &data->buf.pressure);if (ret) {dev_warn (data->dev,"sample read failed %d\n" , ret); -return IRQ_NONE ; + handled = false; + goto done; } }
@@ -648,15 +652,16 @@ static irqreturn_t bm1390_trigger_handler(int irq, void *p) &data->buf.temp, sizeof(data->buf.temp));if (ret) {dev_warn (data->dev,"temp read failed %d\n" , ret); -return IRQ_HANDLED ; + goto done; } }iio_push_to_buffers_with_ts (idev, &data->buf,sizeof (data->buf), data->timestamp); +done:iio_trigger_notify_done (idev->trig); -return IRQ_HANDLED ; +return IRQ_RETVAL (handled); }/* Get timestamps and wake the thread if we need to read data */
Signature · 1 line
2.43.0
Quoted 9 lines · Stepan Ionichev
bm1390_trigger_handler()returns from three error paths without callingiio_trigger_notify_done(). The success path at the end does, so on a single transient regmap or read failure the triggeruse_countis never decremented, and the !atomic_read(&trig->use_count) guard iniio_trigger_poll_chained()drops every subsequent dispatch. The buffered-data flow stays wedged until the trigger is detached.Funnel all returns through a single done label that calls
iio_trigger_notify_done()and reports the outcome viaIRQ_RETVAL().
...
drivers/iio/pressure/rohm-bm1390.c static irqreturn_t bm1390_trigger_handler(int irq, void *p) · line 662
Quoted 2 lines
drivers/iio/pressure/rohm-bm1390.c +1
-0+done:iio_trigger_notify_done (idev->trig);
Maybe it's better to make this as an implementation and wrap it in something like
handle_trigger_irq()
{
bool result;
// that returns boolean and doesn't have notify call
result = this_old_function(...);
iio_trigger_notify_done(idev->trig);
return IRQ_RETVAL(result);
}Signature · 2 lines
With Best Regards, Andy Shevchenko
Matti Vaittinen
maintainerQuoted 7 lines · Stepan Ionichev
bm1390_trigger_handler()returns from three error paths without callingiio_trigger_notify_done(). The success path at the end does, so on a single transient regmap or read failure the triggeruse_countis never decremented, and the !atomic_read(&trig->use_count) guard iniio_trigger_poll_chained()drops every subsequent dispatch. The buffered-data flow stays wedged until the trigger is detached.
I still believe the use-count should be decremented by the IIO, after it has called trigger handlers. (Unless there is an use-case where the use-count is not decremented.) Well, let's wait for a little while so Jonathan & others have time to comment. I have been wrong at times ;)
Quoted 20 lines
Funnel all returns through a single done label that calls
iio_trigger_notify_done()and reports the outcome viaIRQ_RETVAL().Fixes 81ca5979b6ed ("iio: pressure: Support ROHM BU1390")Signed-off-by Stepan Ionichev <[email protected]>---
v2:
- Use a bool andIRQ_RETVAL()instead ofirqreturn_t(Andy)v1: https://lore.kernel.org/all/[email protected]/
drivers/iio/pressure/rohm-bm1390.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)drivers/iio/pressure/rohm-bm1390.c +0
-0
drivers/iio/pressure/rohm-bm1390.c static irqreturn_t bm1390_trigger_handler(int irq, void *p) · line 629
Quoted 4 lines
drivers/iio/pressure/rohm-bm1390.c +1
-0@@ -626,12 +626,15 @@ static irqreturn_t bm1390_trigger_handler(int irq, void *p)struct iio_poll_func *pf = p;struct iio_dev *idev = pf->indio_dev;struct bm1390_data *data =iio_priv (idev); +bool handled = true;
I would inverse the logic. At this point, the IRQ is _not_ handled. Hence I'd default this false and only toggled it to true when the IRQ is indeed successfully acked and data is read. That should allow you to touch the 'handled' only once after the initialization.
Quoted 32 lines
drivers/iio/pressure/rohm-bm1390.c +7
-4int ret, status;/* DRDY is acked by reading status reg */ ret =regmap_read (data->regmap,BM1390_REG_STATUS , &status); -if (ret || !status) -return IRQ_NONE ; +if (ret || !status) { + handled = false; + goto done; + }dev_dbg (data->dev,"DRDY trig status 0x%x\n" , status);@@ -639,7 +642,8 @@ static irqreturn_t bm1390_trigger_handler(int irq, void *p) ret =bm1390_pressure_read (data, &data->buf.pressure);if (ret) {dev_warn (data->dev,"sample read failed %d\n" , ret); -return IRQ_NONE ; + handled = false; + goto done; } }@@ -648,15 +652,16 @@ static irqreturn_t bm1390_trigger_handler(int irq, void *p) &data->buf.temp, sizeof(data->buf.temp));if (ret) {dev_warn (data->dev,"temp read failed %d\n" , ret); -return IRQ_HANDLED ; + goto done; } }
drivers/iio/pressure/rohm-bm1390.c static irqreturn_t bm1390_trigger_handler(int irq, void *p) · line 667
Quoted 10 lines
drivers/iio/pressure/rohm-bm1390.c +2
-1iio_push_to_buffers_with_ts (idev, &data->buf,sizeof (data->buf), data->timestamp); +done:iio_trigger_notify_done (idev->trig); -return IRQ_HANDLED ; +return IRQ_RETVAL (handled); }/* Get timestamps and wake the thread if we need to read data */
Yours,
-- Matti
---
Matti Vaittinen
Linux kernel developer at ROHM Semiconductors
Oulu Finland
~~ When things go utterly wrong vim users can always type :help! ~~
Jonathan Cameron
maintainerQuoted 40 lines · On Mon, 18 May 2026 08:21:17 +0300 Matti Vaittinen <[email protected]>…
Quoted 16 lines · David Lechner
Quoted 15 lines · Stepan Ionichev
bm1390_trigger_handler()has three error returns:if (ret || !status) return IRQ_NONE; /* status read failed */ ... if (ret) { dev_warn(...); return IRQ_NONE; /* pressure read failed */ } ... if (ret) { dev_warn(...); return IRQ_HANDLED; /* temp read failed */ }Quoted 6 lines
Quoted 6 lines
None of them call
iio_trigger_notify_done(). The success path at the end does, so on a single transient regmap or pressure-read error the trigger never sees itsuse_countdecremented, and the !atomic_read(&trig->use_count) guard iniio_trigger_poll_chained()drops every subsequent dispatch for that trigger. The buffered-data flow stays wedged until the trigger is detached.I don't really know the intended logic of the
use_count, so I'll leave this to those who understand it better. I'll just add some thoughts this invoked.I think it is not really nice to require (or trust) drivers to call the "
iio_trigger_notify_done()" if the handler fails. Maybe it would be better to do something like:void
iio_trigger_poll_nested(struct iio_trigger *trig){ int i; if (!atomic_read(&trig->use_count)) { atomic_set(&trig->use_count,
CONFIG_IIO_CONSUMERS_PER_TRIGGER);
Quoted 8 lines
for (i = 0; i < CONFIG_IIO_CONSUMERS_PER_TRIGGER; i++) { if (trig->subirqs[i].enabled) handle_nested_irq(trig->subirq_base + i); else iio_trigger_notify_done(trig); } atomic_set(&trig->use_count, 0); /* Clear the use_count if driversdidn't */
If this worked we could just drop the use_count :)
Quoted 5 lines
} }to prevent this class of problems once and for all. But yeah, wiser minds have designed this - so let's hear some other opinions as well :)
I've mused about similar myself. The problem is the iio_trigger_notify_done() at least in theory doesn't have to be anywhere near the interrupt handler.
It normally is, but there is potential for some other delaying action to be fired - e.g. using an hrtimer to fire off an action that then starts sampling and waits for an interrupt to finish the sampling. The iio_trigger_notify_done() call belongs in that interrupt handler - which is no anywhere near here.
Can't find an example right now, but they existed when I wrote that complex mess in the first place.
Like many things in IIO we may have designed it for a case that went away in the meantime. The silliest one of those is that (last time I checked) there are no top half / thread combinations for pollfuncs where the top half does anything beyond grabbing a timestamp. So ultimately we could replace the top half handler parameter with a bool to say if the timestamp is useful.
Quoted 51 lines
Quoted 28 lines
Quoted 28 lines
The
IRQ_HANDLEDreturn on the temperature path additionally leaves the temp branch's last partial state in&data->buf.tempwithout pushing the sample, which is the existing intended behaviour; only the missingnotify_done()needs fixing.Funnel all returns through a single 'done' label that calls
iio_trigger_notify_done()before returning the savedirqreturn_t.Fixes 81ca5979b6ed ("iio: pressure: Support ROHM BU1390")Signed-off-by Stepan Ionichev <[email protected]>--- drivers/iio/pressure/rohm-bm1390.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)drivers/iio/pressure/rohm-bm1390.c +1
-0@@ -626,12 +626,15 @@ static irqreturn_t bm1390_trigger_handler(int irq, void *p)struct iio_poll_func *pf = p;struct iio_dev *idev = pf->indio_dev;struct bm1390_data *data =iio_priv (idev); +irqreturn_t result =IRQ_HANDLED ;int ret, status;Quoted 10 lines
drivers/iio/pressure/rohm-bm1390.c static irqreturn_t bm1390_trigger_handler(int irq, void *p) · line 635
Quoted 6 lines
drivers/iio/pressure/rohm-bm1390.c +2
-2/* DRDY is acked by reading status reg */ ret =regmap_read (data->regmap,BM1390_REG_STATUS , &status); -if (ret || !status) -return IRQ_NONE ; +if (ret || !status) { + result =IRQ_NONE ;
IRQ_NONEmeans that the interrupt wasn't handled, so it won't be cleared and the handler will likely just run again immediately. So it probably isn't the right thing to be returning in the first place.This is exactly why IRQ-none is returned, and what it is used for. If the problem with bus-access / device persists, the kernel will (after XXXX fails indicated by
IRQ_NONE- don't remember exact numbers) disable the IRQ from the host side, and emit the, ass-saving, "nobody cared" -print.This is (in my opinion) the only RightThing(tm). (Especially so, if the device is accessed from the fast handler, and is system is single-core). There is a tremendous difference when debugging a system which just hangs in IRQ loop forever (and you can't get no contact to it), and when debugging a system which, after a relatively short hang-up, let's you see the magic "nobody cared" -print telling a misbehaving IRQ was disabled.
Quoted 3 lines
Furthermore, if the status register read failure was a temporary one, then we should be getting new IRQ as soon as the handler exists. This should then successfully handle the IRQ.
I see this as a bit more nuanced. Depends on what fails. If we detect no interrupt then it makes sense. For other cases it's is tricky to figure out the right option. Some errors are fine as we know they don't affect the interrupt being cleared (if we even need to clear it).
So generally I've left that analysis and decision up to individual driver authors.
Quoted 4 lines
Yours,
-- Matti
Jonathan Cameron
maintainerQuoted 12 lines · On Mon, 18 May 2026 09:59:24 +0300 Andy Shevchenko…
Quoted 2 lines · Matti Vaittinen
Quoted 1 line · David Lechner
On 5/17/26 11:08 AM, Stepan Ionichev wrote:
...
Quoted 6 lines
Maybe it would be better to do something like:
void
iio_trigger_poll_nested(struct iio_trigger *trig){ int i;
Quoted 8 lines
Quoted 3 lines
if (!atomic_read(&trig->use_count)) { atomic_set(&trig->use_count,
CONFIG_IIO_CONSUMERS_PER_TRIGGER);Just in case somebody is going to do that, avoid doing
atomic_read()followed byatomic_set(). This is typical TOCTOU issue. This should be something likeatomic_xchg()oratomic_add_return()or something like this in a single atomic operation.
Just to clarify - the current code is fine. This got reported a few years back and I did the analysis to prove it. From what I recall the key is that the state space isn't as complex as it immediately looks.
That counter is either non 0 at the start (we don't use it here and we skip an interrupt - that's actually the desired behaviour if the trigger is running too fast - triggers must survive that - reenable() callback is there to make that all work).
Otherwise there is a single path that sets it and we know any decrement until after that happens would have undeflowed (and hence was a bug). The rest are decrement only and it can never go to less than 0.
Hence it is fine.
Agreed things get messy if we make this alg any more complex though!
J
Quoted 16 lines
Quoted 14 lines
for (i = 0; i < CONFIG_IIO_CONSUMERS_PER_TRIGGER; i++) { if (trig->subirqs[i].enabled) handle_nested_irq(trig->subirq_base + i); else iio_trigger_notify_done(trig); } atomic_set(&trig->use_count, 0); /* Clear the use_count if drivers didn't */ } }to prevent this class of problems once and for all. But yeah, wiser minds have designed this - so let's hear some other opinions as well :)
Jonathan Cameron
maintainerQuoted 7 lines · On Mon, 18 May 2026 14:42:38 +0500 Stepan Ionichev <[email protected]> wrote:
bm1390_trigger_handler()returns from three error paths without callingiio_trigger_notify_done(). The success path at the end does, so on a single transient regmap or read failure the triggeruse_countis never decremented, and the !atomic_read(&trig->use_count) guard iniio_trigger_poll_chained()drops every subsequent dispatch. The buffered-data flow stays wedged until the trigger is detached.
Quoted 6 lines
Funnel all returns through a single done label that calls
iio_trigger_notify_done()and reports the outcome viaIRQ_RETVAL().Fixes 81ca5979b6ed ("iio: pressure: Support ROHM BU1390")Signed-off-by Stepan Ionichev <[email protected]>
These error path 'fixes' are fixes for hardware failure - so if anything they are hardending against a possible error condition. I don't mind that bit it's not a bug to not do this so fixes tag an stable are not appropriate for any of these.
Note however that hardening against these conditions is not this simple. It takes careful analysis of exactly how the hardware behaves and what each error condition 'might' mean. Whilst they are probably harmless I'm also very dubious about taking them without comprehensive testing on the particular device.
Quoted 14 lines
---
v2:
- Use a bool andIRQ_RETVAL()instead ofirqreturn_t(Andy)v1: https://lore.kernel.org/all/[email protected]/
drivers/iio/pressure/rohm-bm1390.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)drivers/iio/pressure/rohm-bm1390.c +0
-0
drivers/iio/pressure/rohm-bm1390.c static irqreturn_t bm1390_trigger_handler(int irq, void *p) · line 633
Quoted 8 lines
drivers/iio/pressure/rohm-bm1390.c +1
-0@@ -626,12 +626,15 @@ static irqreturn_t bm1390_trigger_handler(int irq, void *p)struct iio_poll_func *pf = p;struct iio_dev *idev = pf->indio_dev;struct bm1390_data *data =iio_priv (idev); +bool handled = true;int ret, status;/* DRDY is acked by reading status reg */ ret =regmap_read (data->regmap,BM1390_REG_STATUS , &status);
So question 1.
- What actually is device state if this read fails? We have no idea. It might have failed on the 'to device' path in which case the device didn't see the read. Or it might have failed on the 'from device path'.
Gets more complex...
drivers/iio/pressure/rohm-bm1390.c static irqreturn_t bm1390_trigger_handler(int irq, void *p) · line 634
Quoted 2 lines
drivers/iio/pressure/rohm-bm1390.c +0
-2-if (ret || !status) -return IRQ_NONE ;
The trigger in use might well be the dataready trigger provided by this driver (though I note this device has no validate callbacks so we do allow other triggers - that may or may not be a bug!) I really dislike read to clear register designs as they make this stuff more complex.
Anyhow question 2:
- What happens if we don't clear it and do acknowledge the interrupt plus ack the trigger (which is what iio_trigger_done() is doing? Two obvious options - wedged device, it re interrupts immediately.
If we are wedged, then meh device dead. Without adding retry loops (don't) recovery path is reset the driver by unbinding and rebinding.
Fun follow up is what happens if having acked the data ready trigger by this read, we get another read before getting to iio_trigger_notify_done()?
Quite possibly we wedge. This drivers trigger may be missing a reenable() callback (which would typically reread the status register to clear any such interrupt).
Whether it does is again a device implementation specific thing.
Quoted 8 lines
drivers/iio/pressure/rohm-bm1390.c +4
-0+if (ret || !status) { + handled = false; + goto done; + }dev_dbg (data->dev,"DRDY trig status 0x%x\n" , status);
drivers/iio/pressure/rohm-bm1390.c static irqreturn_t bm1390_trigger_handler(int irq, void *p) · line 646
Quoted 6 lines
drivers/iio/pressure/rohm-bm1390.c +2
-1@@ -639,7 +642,8 @@ static irqreturn_t bm1390_trigger_handler(int irq, void *p) ret =bm1390_pressure_read (data, &data->buf.pressure);if (ret) {dev_warn (data->dev,"sample read failed %d\n" , ret); -return IRQ_NONE ; + handled = false; + goto done;
Hopefully all this stuff is unrelated to the trigger. For these it is fair to ack the trigger and the interrupt. Curiously the driver does it partly for the next one (IRQ_HANDLED).
Quoted 9 lines
drivers/iio/pressure/rohm-bm1390.c +1
-1} }@@ -648,15 +652,16 @@ static irqreturn_t bm1390_trigger_handler(int irq, void *p) &data->buf.temp, sizeof(data->buf.temp));if (ret) {dev_warn (data->dev,"temp read failed %d\n" , ret); -return IRQ_HANDLED ; + goto done;
drivers/iio/pressure/rohm-bm1390.c static irqreturn_t bm1390_trigger_handler(int irq, void *p) · line 664
Quoted 10 lines
drivers/iio/pressure/rohm-bm1390.c +2
-1} }iio_push_to_buffers_with_ts (idev, &data->buf,sizeof (data->buf), data->timestamp); +done:iio_trigger_notify_done (idev->trig); -return IRQ_HANDLED ; +return IRQ_RETVAL (handled);
If we are doing this Andy's suggestion of a helper is neater.
Anyhow, upshot is to get this stuff right requires device specific knowledge. Ideally the author tests injecting errors at each point to verify if the data capture survives. However, it's up to a driver author to decide if they care. There are normally dozens of paths in a driver that will result in needing a reset (unbind/bind for most IIO drivers) - that's expensive, complex, fragile handling code to maintain, so personally I consider it optional.
Jonathan
Quoted 3 lines
drivers/iio/pressure/rohm-bm1390.c +0
-0}/* Get timestamps and wake the thread if we need to read data */
Quoted 5 lines · Jonathan Cameron
Quoted 3 lines · On Mon, 18 May 2026 09:59:24 +0300 Andy Shevchenko…
Quoted 2 lines · Matti Vaittinen
Quoted 1 line · David Lechner
On 5/17/26 11:08 AM, Stepan Ionichev wrote:
...
Quoted 23 lines
Quoted 6 lines
Quoted 6 lines
Maybe it would be better to do something like:
void
iio_trigger_poll_nested(struct iio_trigger *trig){ int i;Quoted 8 lines
Quoted 3 lines
if (!atomic_read(&trig->use_count)) { atomic_set(&trig->use_count,
CONFIG_IIO_CONSUMERS_PER_TRIGGER);Just in case somebody is going to do that, avoid doing
atomic_read()followed byatomic_set(). This is typical TOCTOU issue. This should be something likeatomic_xchg()oratomic_add_return()or something like this in a single atomic operation.Just to clarify - the current code is fine. This got reported a few years back and I did the analysis to prove it. From what I recall the key is that the state space isn't as complex as it immediately looks.
That counter is either non 0 at the start (we don't use it here and we skip an interrupt - that's actually the desired behaviour if the trigger is running too fast - triggers must survive that -reenable()callback is there to make that all work).
Quoted 7 lines
Otherwise there is a single path that sets it and we know any decrement until after that happens would have undeflowed (and hence was a bug). The rest are decrement only and it can never go to less than 0.
Hence it is fine.
Agreed things get messy if we make this alg any more complex though!
Perhaps we need a good comment just on top of this atomic_read()/atomic_set() pair. Because it's really the code no one should take as an example how to do atomics :-) Logical question, why do we even have atomics there? Shouldn't be that READ_ONCE()/WRITE_ONCE() to have an integrity in place? (This I believe even mentioned in the documentation for atomics.)
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
for (i = 0; i < CONFIG_IIO_CONSUMERS_PER_TRIGGER; i++) { if (trig->subirqs[i].enabled) handle_nested_irq(trig->subirq_base + i); else iio_trigger_notify_done(trig); } atomic_set(&trig->use_count, 0); /* Clear the use_count if drivers didn't */ } }to prevent this class of problems once and for all. But yeah, wiser minds have designed this - so let's hear some other opinions as well :)
Signature · 2 lines
With Best Regards, Andy Shevchenko
Matti Vaittinen
maintainerThanks Jonathan,
Your post give me something to think about ;)
Quoted 57 lines · Jonathan Cameron
Quoted 7 lines · On Mon, 18 May 2026 14:42:38 +0500 Stepan Ionichev <[email protected]> wrote:
bm1390_trigger_handler()returns from three error paths without callingiio_trigger_notify_done(). The success path at the end does, so on a single transient regmap or read failure the triggeruse_countis never decremented, and the !atomic_read(&trig->use_count) guard iniio_trigger_poll_chained()drops every subsequent dispatch. The buffered-data flow stays wedged until the trigger is detached.Quoted 6 lines
Funnel all returns through a single done label that calls
iio_trigger_notify_done()and reports the outcome viaIRQ_RETVAL().Fixes 81ca5979b6ed ("iio: pressure: Support ROHM BU1390")Signed-off-by Stepan Ionichev <[email protected]>These error path 'fixes' are fixes for hardware failure - so if anything they are hardending against a possible error condition. I don't mind that bit it's not a bug to not do this so fixes tag an stable are not appropriate for any of these.
Note however that hardening against these conditions is not this simple. It takes careful analysis of exactly how the hardware behaves and what each error condition 'might' mean. Whilst they are probably harmless I'm also very dubious about taking them without comprehensive testing on the particular device.
Quoted 14 lines
---
v2:
- Use a bool andIRQ_RETVAL()instead ofirqreturn_t(Andy)v1: https://lore.kernel.org/all/[email protected]/
drivers/iio/pressure/rohm-bm1390.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)drivers/iio/pressure/rohm-bm1390.c +0
-0drivers/iio/pressure/rohm-bm1390.c static irqreturn_t bm1390_trigger_handler(int irq, void *p) · line 633
Quoted 8 lines
drivers/iio/pressure/rohm-bm1390.c +1
-0@@ -626,12 +626,15 @@ static irqreturn_t bm1390_trigger_handler(int irq, void *p)struct iio_poll_func *pf = p;struct iio_dev *idev = pf->indio_dev;struct bm1390_data *data =iio_priv (idev); +bool handled = true;int ret, status;/* DRDY is acked by reading status reg */ ret =regmap_read (data->regmap,BM1390_REG_STATUS , &status);So question 1.
- What actually is device state if this read fails? We have no idea. It might have failed on the 'to device' path in which case the device didn't see the read. Or it might have failed on the 'from device path'.Gets more complex...
Quoted 7 lines
drivers/iio/pressure/rohm-bm1390.c static irqreturn_t bm1390_trigger_handler(int irq, void *p) · line 634
Quoted 2 lines
drivers/iio/pressure/rohm-bm1390.c +0
-2-if (ret || !status) -return IRQ_NONE ;The trigger in use might well be the dataready trigger provided by this driver (though I note this device has no validate callbacks so we do allow other triggers - that may or may not be a bug!) I really dislike read to clear register designs as they make this stuff more complex.
I have a strong feeling it should be the dataready. Still, I have no idea about actual systems using this driver, so I am a bit cautious adding new restrictions.
Quoted 6 lines
Anyhow question 2:
- What happens if we don't clear it and do acknowledge the interrupt plus ack the trigger (which is whatiio_trigger_done()is doing? Two obvious options - wedged device, it re interrupts immediately.
If we are wedged, then meh device dead. Without adding retry loops (don't) recovery path is reset the driver by unbinding and rebinding.
The BM1390 keeps the IRQ pin asserted.
Quoted 4 lines
Fun follow up is what happens if having acked the data ready trigger by this read, we get another read before getting to
iio_trigger_notify_done()?Quite possibly we wedge.
I see. This isn't fun at all. Even more so if the trigger use-count now prevents us from calling the handler, and returning further IRQ_NONEs, preventing the safety-mechanism intended to disable the offending IRQ. I have a feeling there is IRQF_ONESHOT set though, so perhaps we are safe from this (when no error path is taken in the handler).
Quoted 2 lines
This drivers trigger may be missing a
reenable()callback
(which would typically reread the status register to clear any such interrupt).
Which works for case where we "get another read before getting to iio_trigger_notify_done()" - but not for a case where we might have the bus stuck, causing read errors.
Quoted 10 lines
Whether it does is again a device implementation specific thing.
Quoted 7 lines
drivers/iio/pressure/rohm-bm1390.c +4
-0+if (ret || !status) { + handled = false; + goto done; + }dev_dbg (data->dev,"DRDY trig status 0x%x\n" , status);
Quoted 11 lines
drivers/iio/pressure/rohm-bm1390.c static irqreturn_t bm1390_trigger_handler(int irq, void *p) · line 646
Quoted 7 lines
drivers/iio/pressure/rohm-bm1390.c +2
-1@@ -639,7 +642,8 @@ static irqreturn_t bm1390_trigger_handler(int irq, void *p) ret =bm1390_pressure_read (data, &data->buf.pressure);if (ret) {dev_warn (data->dev,"sample read failed %d\n" , ret); -return IRQ_NONE ; + handled = false; + goto done;Hopefully all this stuff is unrelated to the trigger. For these it is fair to ack the trigger and the interrupt. Curiously the driver does it partly for the next one (
IRQ_HANDLED).
I would keep the IRQ_NONE here because, if we keep constantly failing the reads, then the bus is likely to be unerliable - and disabling the useless IRQ is probably very sane thing to do. It should help debugging. What comes to acking the trigger - I am starting to agree with Stepan, we should probably ack the trigger in any case. If we don't ack the trigger, then the IRQ_NONE does not serve the purpose it is intended for.
Quoted 17 lines
Quoted 17 lines
drivers/iio/pressure/rohm-bm1390.c +2
-1} }@@ -648,15 +652,16 @@ static irqreturn_t bm1390_trigger_handler(int irq, void *p) &data->buf.temp, sizeof(data->buf.temp));if (ret) {dev_warn (data->dev,"temp read failed %d\n" , ret); -return IRQ_HANDLED ; + goto done; } }iio_push_to_buffers_with_ts (idev, &data->buf,sizeof (data->buf), data->timestamp); +done:iio_trigger_notify_done (idev->trig);
Quoted 5 lines
drivers/iio/pressure/rohm-bm1390.c static irqreturn_t bm1390_trigger_handler(int irq, void *p) · line 664
Quoted 2 lines
drivers/iio/pressure/rohm-bm1390.c +1
-1-return IRQ_HANDLED ; +return IRQ_RETVAL (handled);If we are doing this Andy's suggestion of a helper is neater.
Anyhow, upshot is to get this stuff right requires device specific knowledge.
And time... :)
Quoted 5 lines
Ideally the author tests injecting errors at each point to verify if the data capture survives. However, it's up to a driver author to decide if they care. There are normally dozens of paths in a driver that will result in needing a reset (unbind/bind for most IIO drivers) - that's expensive, complex, fragile handling code to maintain, so personally I consider it optional.
I am not going to try adding any such recovery code in driver. I am afraid it would be way too complex for me to maintain (with my memory, code I've seen last month is new Today) for the added benefit. If we have such a delicate system where this type of 'failure recovery w/o reset' is required, then such code should (in my opinion) be system specific and not generic. Most of the device users will never benefit from it, but will need to look at it...
What I DO care is the IRQ gets disabled (from host side) if it can't be acked (from device side). That shouldn't be so complex (although, it seems it is more complex I thought when I wrote this driver).
After all this babbling I've done - if I understood it right, omitting the call to iio_trigger_notify_done() will prevent further returns of the IRQ_NONE, even if the IRQ stays asserted. So yes, I would definitely like to see this fix getting in.
Thanks guys for giving me a lesson again!
Quoted 5 lines
drivers/iio/pressure/rohm-bm1390.c static irqreturn_t bm1390_trigger_handler(int irq, void *p) · line 667
Quoted 4 lines
drivers/iio/pressure/rohm-bm1390.c +0
-0}/* Get timestamps and wake the thread if we need to read data */
Yours,
-- Matti
---
Matti Vaittinen
Linux kernel developer at ROHM Semiconductors
Oulu Finland
~~ When things go utterly wrong vim users can always type :help! ~~
Jonathan Cameron
maintainerQuoted 38 lines · On Mon, 18 May 2026 21:31:48 +0300 Andy Shevchenko…
Quoted 5 lines · Jonathan Cameron
Quoted 3 lines · On Mon, 18 May 2026 09:59:24 +0300 Andy Shevchenko…
Quoted 2 lines · Matti Vaittinen
Quoted 1 line · David Lechner
On 5/17/26 11:08 AM, Stepan Ionichev wrote:
...
Quoted 29 lines
Quoted 6 lines
Quoted 6 lines
Maybe it would be better to do something like:
void
iio_trigger_poll_nested(struct iio_trigger *trig){ int i;Quoted 8 lines
Quoted 3 lines
if (!atomic_read(&trig->use_count)) { atomic_set(&trig->use_count,
CONFIG_IIO_CONSUMERS_PER_TRIGGER);Just in case somebody is going to do that, avoid doing
atomic_read()followed byatomic_set(). This is typical TOCTOU issue. This should be something likeatomic_xchg()oratomic_add_return()or something like this in a single atomic operation.Just to clarify - the current code is fine. This got reported a few years back and I did the analysis to prove it. From what I recall the key is that the state space isn't as complex as it immediately looks.
That counter is either non 0 at the start (we don't use it here and we skip an interrupt - that's actually the desired behaviour if the trigger is running too fast - triggers must survive that -reenable()callback is there to make that all work).Otherwise there is a single path that sets it and we know any decrement until after that happens would have undeflowed (and hence was a bug). The rest are decrement only and it can never go to less than 0.
Hence it is fine.
Quoted 7 lines
Quoted 1 line
Agreed things get messy if we make this alg any more complex though!
Perhaps we need a good comment just on top of this atomic_read()/atomic_set() pair. Because it's really the code no one should take as an example how to do atomics :-) Logical question, why do we even have atomics there? Shouldn't be that READ_ONCE()/WRITE_ONCE() to have an integrity in place? (This I believe even mentioned in the documentation for atomics.)
There are atomic decrements elsewhere that need to be (multiple drivers can decrement at the same time) and mixing and matching between atomic accessors and non atomic is a mess.
Comment wise. I'd like to say I'll get to it, but unlikely it'll be soon.
Jonathan
Quoted 15 lines
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
for (i = 0; i < CONFIG_IIO_CONSUMERS_PER_TRIGGER; i++) { if (trig->subirqs[i].enabled) handle_nested_irq(trig->subirq_base + i); else iio_trigger_notify_done(trig); } atomic_set(&trig->use_count, 0); /* Clear the use_count if drivers didn't */ } }to prevent this class of problems once and for all. But yeah, wiser minds have designed this - so let's hear some other opinions as well :)
Jonathan Cameron
maintainerQuoted 3 lines · On Tue, 19 May 2026 08:48:13 +0300 Matti Vaittinen <[email protected]>…
Thanks Jonathan,
Your post give me something to think about ;)
This is a can of worms. More below.
I'm unconcerned as long as (and ideally someone should check it) we can get of being stuck by unbind/rebind of driver. Anything else is best effort.
Quoted 67 lines · Jonathan Cameron
Quoted 57 lines
Quoted 7 lines · On Mon, 18 May 2026 14:42:38 +0500 Stepan Ionichev <[email protected]> wrote:
bm1390_trigger_handler()returns from three error paths without callingiio_trigger_notify_done(). The success path at the end does, so on a single transient regmap or read failure the triggeruse_countis never decremented, and the !atomic_read(&trig->use_count) guard iniio_trigger_poll_chained()drops every subsequent dispatch. The buffered-data flow stays wedged until the trigger is detached.Quoted 6 lines
Funnel all returns through a single done label that calls
iio_trigger_notify_done()and reports the outcome viaIRQ_RETVAL().Fixes 81ca5979b6ed ("iio: pressure: Support ROHM BU1390")Signed-off-by Stepan Ionichev <[email protected]>These error path 'fixes' are fixes for hardware failure - so if anything they are hardending against a possible error condition. I don't mind that bit it's not a bug to not do this so fixes tag an stable are not appropriate for any of these.
Note however that hardening against these conditions is not this simple. It takes careful analysis of exactly how the hardware behaves and what each error condition 'might' mean. Whilst they are probably harmless I'm also very dubious about taking them without comprehensive testing on the particular device.
Quoted 14 lines
---
v2:
- Use a bool andIRQ_RETVAL()instead ofirqreturn_t(Andy)v1: https://lore.kernel.org/all/[email protected]/
drivers/iio/pressure/rohm-bm1390.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)drivers/iio/pressure/rohm-bm1390.c +0
-0drivers/iio/pressure/rohm-bm1390.c static irqreturn_t bm1390_trigger_handler(int irq, void *p) · line 633
Quoted 8 lines
drivers/iio/pressure/rohm-bm1390.c +1
-0@@ -626,12 +626,15 @@ static irqreturn_t bm1390_trigger_handler(int irq, void *p)struct iio_poll_func *pf = p;struct iio_dev *idev = pf->indio_dev;struct bm1390_data *data =iio_priv (idev); +bool handled = true;int ret, status;/* DRDY is acked by reading status reg */ ret =regmap_read (data->regmap,BM1390_REG_STATUS , &status);So question 1.
- What actually is device state if this read fails? We have no idea. It might have failed on the 'to device' path in which case the device didn't see the read. Or it might have failed on the 'from device path'.Gets more complex...
Quoted 7 lines
drivers/iio/pressure/rohm-bm1390.c static irqreturn_t bm1390_trigger_handler(int irq, void *p) · line 634
Quoted 2 lines
drivers/iio/pressure/rohm-bm1390.c +0
-2-if (ret || !status) -return IRQ_NONE ;The trigger in use might well be the dataready trigger provided by this driver (though I note this device has no validate callbacks so we do allow other triggers - that may or may not be a bug!) I really dislike read to clear register designs as they make this stuff more complex.
Quoted 3 lines
I have a strong feeling it should be the dataready. Still, I have no idea about actual systems using this driver, so I am a bit cautious adding new restrictions.
If we can show it is broken with any of the other triggers then we can add the restriction without it being a potential regression. Not sure if that is doable - easiest way would be to just try it and see.
Quoted 13 lines
Quoted 7 lines
Anyhow question 2:
- What happens if we don't clear it and do acknowledge the interrupt plus ack the trigger (which is whatiio_trigger_done()is doing? Two obvious options - wedged device, it re interrupts immediately.
If we are wedged, then meh device dead. Without adding retry loops (don't) recovery path is reset the driver by unbinding and rebinding.The BM1390 keeps the IRQ pin asserted.
Quoted 3 lines
Fun follow up is what happens if having acked the data ready trigger by this read, we get another read before getting to
iio_trigger_notify_done()?
Quoted 7 lines
Quoted 1 line
Quite possibly we wedge.
I see. This isn't fun at all. Even more so if the trigger use-count now prevents us from calling the handler, and returning further
IRQ_NONEs, preventing the safety-mechanism intended to disable the offending IRQ. I have a feeling there isIRQF_ONESHOTset though, so perhaps we are safe from this (when no error path is taken in the handler).
Good point.
You are right (I think!) that saves us if using the trigger in this driver because the trigger is fired by iio_trigger_poll_nested()/handle_nested_irq() which runs the thread_fn()s for (pollfunc threads) in the thread belonging to the trigger interrupt.
If we had a trigger that was doing in the top half (iio_trigger_poll()) then it would get messier but I think that could only slew the data by a sample which isn't too bad (as we don't need this interrupt to happen).
If we return an error because we know it's not our interrupt then we should be fine anyway because our interrupt will turn up later (as long as that is in the trigger itself).
Quoted 7 lines
Quoted 3 lines
This drivers trigger may be missing a
reenable()callback
(which would typically reread the status register to clear any such interrupt).Which works for case where we "get another read before getting to
iio_trigger_notify_done()" - but not for a case where we might have the bus stuck, causing read errors.
If bus is stuck, I'm of the view recovery unlikely and if it really is a once in a blue moon thing, unbind and rebind the driver.
Quoted 23 lines
Quoted 11 lines
Whether it does is again a device implementation specific thing.
Quoted 7 lines
drivers/iio/pressure/rohm-bm1390.c +4
-0+if (ret || !status) { + handled = false; + goto done; + }dev_dbg (data->dev,"DRDY trig status 0x%x\n" , status);Quoted 11 lines
drivers/iio/pressure/rohm-bm1390.c static irqreturn_t bm1390_trigger_handler(int irq, void *p) · line 646
Quoted 7 lines
drivers/iio/pressure/rohm-bm1390.c +2
-1@@ -639,7 +642,8 @@ static irqreturn_t bm1390_trigger_handler(int irq, void *p) ret =bm1390_pressure_read (data, &data->buf.pressure);if (ret) {dev_warn (data->dev,"sample read failed %d\n" , ret); -return IRQ_NONE ; + handled = false; + goto done;Hopefully all this stuff is unrelated to the trigger. For these it is fair to ack the trigger and the interrupt. Curiously the driver does it partly for the next one (
IRQ_HANDLED).
Quoted 6 lines
I would keep the
IRQ_NONEhere because, if we keep constantly failing the reads, then the bus is likely to be unerliable - and disabling the useless IRQ is probably very sane thing to do. It should help debugging. What comes to acking the trigger - I am starting to agree with Stepan, we should probably ack the trigger in any case. If we don't ack the trigger, then theIRQ_NONEdoes not serve the purpose it is intended for.
The interrupt that we'd get spurious detection on here would not be the device one it would be the software emulated one deep in the iio trigger stuff.
Might still be useful for debug. Anyone fancy hacking an error in and reporting back what we actually get from the debug hardware? (with that trigger acked as you suggest?)
Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
drivers/iio/pressure/rohm-bm1390.c +2
-1} }@@ -648,15 +652,16 @@ static irqreturn_t bm1390_trigger_handler(int irq, void *p) &data->buf.temp, sizeof(data->buf.temp));if (ret) {dev_warn (data->dev,"temp read failed %d\n" , ret); -return IRQ_HANDLED ; + goto done; } }iio_push_to_buffers_with_ts (idev, &data->buf,sizeof (data->buf), data->timestamp); +done:iio_trigger_notify_done (idev->trig);
Quoted 7 lines
Quoted 5 lines
drivers/iio/pressure/rohm-bm1390.c static irqreturn_t bm1390_trigger_handler(int irq, void *p) · line 664
Quoted 2 lines
drivers/iio/pressure/rohm-bm1390.c +1
-1-return IRQ_HANDLED ; +return IRQ_RETVAL (handled);If we are doing this Andy's suggestion of a helper is neater.
Anyhow, upshot is to get this stuff right requires device specific knowledge.
And time... :)
Absolutely - I see it as value add, so its a business decision to work through all these or not.
Quoted 15 lines
Quoted 6 lines
Ideally the author tests injecting errors at each point to verify if the data capture survives. However, it's up to a driver author to decide if they care. There are normally dozens of paths in a driver that will result in needing a reset (unbind/bind for most IIO drivers) - that's expensive, complex, fragile handling code to maintain, so personally I consider it optional.
I am not going to try adding any such recovery code in driver. I am afraid it would be way too complex for me to maintain (with my memory, code I've seen last month is new Today) for the added benefit. If we have such a delicate system where this type of 'failure recovery w/o reset' is required, then such code should (in my opinion) be system specific and not generic. Most of the device users will never benefit from it, but will need to look at it...
Quoted 8 lines
What I DO care is the IRQ gets disabled (from host side) if it can't be acked (from device side). That shouldn't be so complex (although, it seems it is more complex I thought when I wrote this driver).
After all this babbling I've done - if I understood it right, omitting the call to
iio_trigger_notify_done()will prevent further returns of theIRQ_NONE, even if the IRQ stays asserted. So yes, I would definitely like to see this fix getting in.
I think you are right on this, but I'd kind of like someone to hammer some hardware to verify it. I'm not set up to do that today (even in emulation) but could get to it at some point.
The bit that makes me a bit doubtful is if this is a level interrupt and the clear is in the trigger handler I think we get an interrupt storm anyway - even with IRQ_NONE because that IRQ_NONE is for the nested interrupt. We keep return IRQ_HANDLED from the main thread irq despite not actually doing anything.
That's hard behavior to fix in the core as that skip is intended for annoying free running edge triggers - which are only ones where this race 'should' happen. Those can run faster than we can actually read data
and so we want to drop a scan. Maybe we could cap the number
that are skipped so we eventually report a problem from iio_trigger_poll_nested() or push that decision up to the caller? This would rely on not call iio_trigger_poll_done() in IRQ_NONE on the 'software' interrupts in that pollfuncs come from.
bool iio_trigger_poll_nested(struct iio_trigger *trig)
{
int i;
if (!atomic_read(&trig->use_count)) {
atomic_set(&trig->use_count, CONFIG_IIO_CONSUMERS_PER_TRIGGER);
for (i = 0; i < CONFIG_IIO_CONSUMERS_PER_TRIGGER; i++) {
if (trig->subirqs[i].enabled)
handle_nested_irq(trig->subirq_base + i);
else
iio_trigger_notify_done(trig);
}
} else {
return false;
}
return true;
}Then check that in the caller. That will tell us someone didn't finish the previous trigger. Note it's still not fun because if we let other consumers use the trigger, one of those might be running slow and do we want to throttle the capture to every other interrupt (which incidentally means the clear should be in the trigger irq handler, not the one grabbing the data). Ah - that's a good reason to add a validate_device to the trigger. It is broken anyway for other devices using this trigger.
This feels like yet another case where we need some docs on best practice and acceptable options.
Gah. I hate analysing error paths in complex flows. Lunch time!
Jonathan
Quoted 18 lines
Thanks guys for giving me a lesson again!
Quoted 5 lines
drivers/iio/pressure/rohm-bm1390.c static irqreturn_t bm1390_trigger_handler(int irq, void *p) · line 667
Quoted 4 lines
drivers/iio/pressure/rohm-bm1390.c +0
-0}/* Get timestamps and wake the thread if we need to read data */ Yours,
-- Matti---
Matti Vaittinen
Linux kernel developer at ROHM Semiconductors
Oulu Finland~~ When things go utterly wrong vim users can always type :help! ~~
Matti Vaittinen
maintainerQuoted 5 lines · Jonathan Cameron
Quoted 2 lines · On Tue, 19 May 2026 08:48:13 +0300 Matti Vaittinen <[email protected]>…
Thanks Jonathan,
Quoted 40 lines
Quoted 1 line
Your post give me something to think about ;)
This is a can of worms. More below.
I'm unconcerned as long as (and ideally someone should check it) we can get of being stuck by unbind/rebind of driver. Anything else is best effort.
Quoted 31 lines · Jonathan Cameron
Quoted 29 lines
Quoted 7 lines · On Mon, 18 May 2026 14:42:38 +0500 Stepan Ionichev <[email protected]> wrote:
bm1390_trigger_handler()returns from three error paths without callingiio_trigger_notify_done(). The success path at the end does, so on a single transient regmap or read failure the triggeruse_countis never decremented, and the !atomic_read(&trig->use_count) guard iniio_trigger_poll_chained()drops every subsequent dispatch. The buffered-data flow stays wedged until the trigger is detached.Quoted 6 lines
Funnel all returns through a single done label that calls
iio_trigger_notify_done()and reports the outcome viaIRQ_RETVAL().Fixes 81ca5979b6ed ("iio: pressure: Support ROHM BU1390")Signed-off-by Stepan Ionichev <[email protected]>These error path 'fixes' are fixes for hardware failure - so if anything they are hardending against a possible error condition. I don't mind that bit it's not a bug to not do this so fixes tag an stable are not appropriate for any of these.
Note however that hardening against these conditions is not this simple. It takes careful analysis of exactly how the hardware behaves and what each error condition 'might' mean. Whilst they are probably harmless I'm also very dubious about taking them without comprehensive testing on the particular device.
Quoted 1 line
---
//snip
Quoted 20 lines
Quoted 13 lines
Quoted 12 lines
drivers/iio/pressure/rohm-bm1390.c static irqreturn_t bm1390_trigger_handler(int irq, void *p) · line 646
Quoted 8 lines
drivers/iio/pressure/rohm-bm1390.c +2
-1@@ -639,7 +642,8 @@ static irqreturn_t bm1390_trigger_handler(int irq, void *p) ret =bm1390_pressure_read (data, &data->buf.pressure);if (ret) {dev_warn (data->dev,"sample read failed %d\n" , ret); -return IRQ_NONE ; + handled = false; + goto done;Hopefully all this stuff is unrelated to the trigger. For these it is fair to ack the trigger and the interrupt. Curiously the driver does it partly for the next one (
IRQ_HANDLED).Quoted 6 lines
I would keep the
IRQ_NONEhere because, if we keep constantly failing the reads, then the bus is likely to be unerliable - and disabling the useless IRQ is probably very sane thing to do. It should help debugging. What comes to acking the trigger - I am starting to agree with Stepan, we should probably ack the trigger in any case. If we don't ack the trigger, then theIRQ_NONEdoes not serve the purpose it is intended for.
Quoted 6 lines
The interrupt that we'd get spurious detection on here would not be the device one it would be the software emulated one deep in the iio trigger stuff.
Might still be useful for debug. Anyone fancy hacking an error in and reporting back what we actually get from the debug hardware? (with that trigger acked as you suggest?)
No promises but I'll see if I can try out something next week...
Yours,
-- Matti
Signature · 6 lines
--- Matti Vaittinen Linux kernel developer at ROHM Semiconductors Oulu Finland ~~ When things go utterly wrong vim users can always type :help! ~~
Matti Vaittinen
maintainerQuoted 67 lines · Matti Vaittinen
Quoted 5 lines · Jonathan Cameron
Quoted 2 lines · On Tue, 19 May 2026 08:48:13 +0300 Matti Vaittinen <[email protected]>…
Thanks Jonathan,
Quoted 38 lines
Quoted 1 line
Your post give me something to think about ;)
This is a can of worms. More below.
I'm unconcerned as long as (and ideally someone should check it) we can get of being stuck by unbind/rebind of driver. Anything else is best effort.
Quoted 29 lines · Jonathan Cameron
Quoted 27 lines
Quoted 7 lines · On Mon, 18 May 2026 14:42:38 +0500 Stepan Ionichev <[email protected]> wrote:
bm1390_trigger_handler()returns from three error paths without callingiio_trigger_notify_done(). The success path at the end does, so on a single transient regmap or read failure the triggeruse_countis never decremented, and the !atomic_read(&trig->use_count) guard iniio_trigger_poll_chained()drops every subsequent dispatch. The buffered-data flow stays wedged until the trigger is detached.Quoted 6 lines
Funnel all returns through a single done label that calls
iio_trigger_notify_done()and reports the outcome viaIRQ_RETVAL().Fixes 81ca5979b6ed ("iio: pressure: Support ROHM BU1390")Signed-off-by Stepan Ionichev <[email protected]>These error path 'fixes' are fixes for hardware failure - so if anything they are hardending against a possible error condition. I don't mind that bit it's not a bug to not do this so fixes tag an stable are not appropriate for any of these.
Note however that hardening against these conditions is not this simple. It takes careful analysis of exactly how the hardware behaves and what each error condition 'might' mean. Whilst they are probably harmless I'm also very dubious about taking them without comprehensive testing on the particular device.
Quoted 1 line
---
//snip
Quoted 20 lines
Quoted 19 lines
Quoted 4 lines
Quoted 4 lines
drivers/iio/pressure/rohm-bm1390.c +0
-0@@ -639,7 +642,8 @@ static irqreturn_t bm1390_trigger_handler(int irq, void *p) ret = bm1390_pressure_read(data, &data->buf.pressure); if (ret) {Quoted 8 lines
drivers/iio/pressure/rohm-bm1390.c static irqreturn_t bm1390_trigger_handler(int irq, void *p) · line 646
Quoted 4 lines
drivers/iio/pressure/rohm-bm1390.c +2
-1dev_warn(data->dev, "sample read failed %d\n", ret); - return IRQ_NONE; + handled = false; + goto done;Hopefully all this stuff is unrelated to the trigger. For these it is fair to ack the trigger and the interrupt. Curiously the driver does it partly for the next one (
IRQ_HANDLED).I would keep the
IRQ_NONEhere because, if we keep constantly failing the reads, then the bus is likely to be unerliable - and disabling the useless IRQ is probably very sane thing to do. It should help debugging. What comes to acking the trigger - I am starting to agree with Stepan, we should probably ack the trigger in any case. If we don't ack the trigger, then theIRQ_NONEdoes not serve the purpose it is intended for.
Quoted 8 lines
Quoted 6 lines
The interrupt that we'd get spurious detection on here would not be the device one it would be the software emulated one deep in the iio trigger stuff.
Might still be useful for debug. Anyone fancy hacking an error in and reporting back what we actually get from the debug hardware? (with that trigger acked as you suggest?)
No promises but I'll see if I can try out something next week...
The week has been horrible... I only had around half an hour for this (just now). Quick:
+++ b/drivers/iio/pressure/rohm-bm1390.c
@@ -621,6 +621,16 @@ static const struct iio_buffer_setup_ops bm1390_buffer_ops = {
.predisable = bm1390_buffer_predisable,
};
+/*
+ * Test case where IRQ status is nopt read (acked). Useful for evaluating the
+ * impact of returning the IRQ_NONE from the trigger handler. define also the
+ * TEST_FORCE_IRQ_NOTIFY if you wish to cause the trigger to be notified.
+ *
+ * Note, in case it is not obvious, this will cause IRQ storm.
+ */
+#define TEST_FORCE_IRQ_NONE
+#define TEST_FORCE_IRQ_NOTIFY
+
static irqreturn_t bm1390_trigger_handler(int irq, void *p)
{
struct iio_poll_func *pf = p;
@@ -628,12 +638,27 @@ static irqreturn_t bm1390_trigger_handler(int irq, void *p)
struct bm1390_data *data = iio_priv(idev);
int ret, status;+#ifdef TEST_FORCE_IRQ_NONE
+ static unsigned long int first = 1, first2 = 0;
+ ret = 0;
+
+ if (first) {
+ pr_info("Skip read\n");
+ first = 0;
+ }
+ #ifdef TEST_FORCE_IRQ_NOTIFY
+ status = BIT(BM1390_CHAN_PRESSURE);
+ #else
+ status = 0;
+ #endif
+#else
/* DRDY is acked by reading status reg */
ret = regmap_read(data->regmap, BM1390_REG_STATUS, &status);
if (ret || !status)
return IRQ_NONE;+#endif
- dev_dbg(data->dev, "DRDY trig status 0x%x\n", status);
+// dev_dbg(data->dev, "DRDY trig status 0x%x\n", status);
if (test_bit(BM1390_CHAN_PRESSURE, idev->active_scan_mask)) {
ret = bm1390_pressure_read(data, &data->buf.pressure);
@@ -656,7 +681,17 @@ static irqreturn_t bm1390_trigger_handler(int irq, void *p)
data->timestamp);
iio_trigger_notify_done(idev->trig);+#ifdef TEST_FORCE_IRQ_NONE
+ /* HACK, return IRQ_NONE and see if IRQ gets disabled */
+ if (!(first2 % 1000))
+ pr_info("Hack, return IRQ_NONE (%lu th)\n", first2);
+
+ first2++;
+
+ return IRQ_NONE;
+#else
return IRQ_HANDLED;
+#endif
}
/* Get timestamps and wake the thread if we need to read data */
resulted:
root@arm:/home/debian# /iio_generic_buffer -a -c1000000 --device-name bm1390 -T0 > /dev/null Enabling all channels [ 115.098819] Skip read [ 115.102442] Hack, return IRQ_NONE (0 th) [ 116.459049] Hack, return IRQ_NONE (1000 th) [ 117.851037] Hack, return IRQ_NONE (2000 th) [ 119.214843] Hack, return IRQ_NONE (3000 th) [ 120.598114] Hack, return IRQ_NONE (4000 th) [ 121.960255] Hack, return IRQ_NONE (5000 th) [ 123.322424] Hack, return IRQ_NONE (6000 th)
//snip
[ 237.726666] Hack, return IRQ_NONE (90000 th)
[ 239.095910] Hack, return IRQ_NONE (91000 th)
[ 240.481233] Hack, return IRQ_NONE (92000 th)
[ 241.846072] Hack, return IRQ_NONE (93000 th)
[ 243.206432] Hack, return IRQ_NONE (94000 th)
[ 244.570636] Hack, return IRQ_NONE (95000 th)
[ 245.928964] Hack, return IRQ_NONE (96000 th)
[ 247.286839] Hack, return IRQ_NONE (97000 th)
[ 248.647986] Hack, return IRQ_NONE (98000 th)
[ 250.011214] Hack, return IRQ_NONE (99000 th)
[ 251.368583] irq 64: nobody cared (try booting with the "irqpoll" option)
[ 251.375463] CPU: 0 UID: 0 PID: 835 Comm: irq/63-2-005d-b Tainted: G
O 7.1.0-rc1-00002-g3b459deb7222-dirty #249 VOLUNTARY
[ 251.375501] Tainted: [O]=OOT_MODULE
[ 251.375511] Hardware name: Generic AM33XX (Flattened Device Tree)
[ 251.375525] Call trace:
[ 251.375545] unwind_backtrace from show_stack+0x10/0x14
[ 251.375607] show_stack from dump_stack_lvl+0x50/0x64
[ 251.375646] dump_stack_lvl from __report_bad_irq+0x30/0xbc
[ 251.375680] __report_bad_irq from note_interrupt+0x2b4/0x32c
[ 251.375722] note_interrupt from handle_nested_irq+0x13c/0x14c
[ 251.375758] handle_nested_irq from iio_trigger_poll_nested+0x4c/0x68 [industrialio]
[ 251.375917] iio_trigger_poll_nested [industrialio] from bm1390_irq_thread_handler+0x54/0x7c [rohm_bm1390]
[ 251.375994] bm1390_irq_thread_handler [rohm_bm1390] from irq_thread_fn+0x1c/0x78
[ 251.376028] irq_thread_fn from irq_thread+0x18c/0x324
[ 251.376057] irq_thread from kthread+0xf8/0x130
[ 251.376091] kthread from ret_from_fork+0x14/0x20
[ 251.376114] Exception stack(0xe0355fb0 to 0xe0355ff8)
[ 251.376136] 5fa0: 00000000 00000000 00000000 00000000
[ 251.376156] 5fc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
[ 251.376175] 5fe0: 00000000 00000000 00000000 00000000 00000013 00000000
[ 251.376189] handlers:
[ 251.498714] [<2ec7a5d9>] iio_pollfunc_store_time [industrialio] threaded [<7f4268a2>] bm1390_trigger_handler [rohm_bm1390]
[ 251.509974] Disabling IRQ #64Message from syslogd@arm at Jan 1 01:17:33 ...
kernel:[ 251.509974] Disabling IRQ #64
[ 252.822500] sched: RT throttling activated
Things I very hastly picked up:
1. The throttling mechanism works even though the handling is invoked via iio_trigger_poll_nested(), Probably because this propagates the call to the handle_nested_irq() - which does bookkeeping.
2. For some reason (which I didn't have time to check yet), the beaglebone black which I used to run this, was not completely blocked by the IRQ. We can see the "Hack, return IRQ_NONE (xxx th)" -prints emerging just fine.
And now I must run. I hope to be able to dig some more details next week.
Yours,
-- Matti
Signature · 5 lines
Matti Vaittinen Linux kernel developer at ROHM Semiconductors Oulu Finland ~~ When things go utterly wrong vim users can always type :help! ~~
Quoted 4 lines · Matti Vaittinen
Quoted 3 lines · Matti Vaittinen
Quoted 2 lines · Jonathan Cameron
On Tue, 19 May 2026 08:48:13 +0300
Matti Vaittinen <[email protected]> wrote:
...
Review
Quoted 4 lines
(quoted diff) +4
-0+#ifdef TEST_FORCE_IRQ_NONE + /* HACK, return IRQ_NONE and see if IRQ gets disabled */ + if (!(first2 % 1000)) + pr_info("Hack, return IRQ_NONE (%lu th)\n", first2);
Hint: pr_info_ratelimited() seems better?
Quoted 6 lines
(quoted diff) +5
-0+ first2++; + + return IRQ_NONE; +#else return IRQ_HANDLED; +#endif
Signature · 2 lines
With Best Regards, Andy Shevchenko
Jonathan Cameron
maintainerQuoted 219 lines · On Fri, 29 May 2026 11:21:40 +0300 Matti Vaittinen <[email protected]>…
Quoted 76 lines · Matti Vaittinen
Quoted 5 lines · Jonathan Cameron
Quoted 2 lines · On Tue, 19 May 2026 08:48:13 +0300 Matti Vaittinen <[email protected]>…
Thanks Jonathan,
Quoted 40 lines
Quoted 1 line
Your post give me something to think about ;)
This is a can of worms. More below.
I'm unconcerned as long as (and ideally someone should check it) we can get of being stuck by unbind/rebind of driver. Anything else is best effort.
Quoted 31 lines · Jonathan Cameron
Quoted 29 lines
Quoted 7 lines · On Mon, 18 May 2026 14:42:38 +0500 Stepan Ionichev <[email protected]> wrote:
bm1390_trigger_handler()returns from three error paths without callingiio_trigger_notify_done(). The success path at the end does, so on a single transient regmap or read failure the triggeruse_countis never decremented, and the !atomic_read(&trig->use_count) guard iniio_trigger_poll_chained()drops every subsequent dispatch. The buffered-data flow stays wedged until the trigger is detached.Quoted 6 lines
Funnel all returns through a single done label that calls
iio_trigger_notify_done()and reports the outcome viaIRQ_RETVAL().Fixes 81ca5979b6ed ("iio: pressure: Support ROHM BU1390")Signed-off-by Stepan Ionichev <[email protected]>These error path 'fixes' are fixes for hardware failure - so if anything
they are hardending against a possible error condition. I don't mind that bit it's not a bug to not do this so fixes tag an stable are not appropriate for any of these.Note however that hardening against these conditions is not this simple.
It takes careful analysis of exactly how the hardware behaves and what each error condition 'might' mean. Whilst they are probably harmless I'm also very dubious about taking them without comprehensive testing on the particular device.Quoted 1 line
---
//snip
Quoted 27 lines
Quoted 15 lines
Quoted 6 lines
Quoted 6 lines
drivers/iio/pressure/rohm-bm1390.c +0
-1@@ -639,7 +642,8 @@ static irqreturn_t bm1390_trigger_handler(int irq, void *p) ret = bm1390_pressure_read(data, &data->buf.pressure); if (ret) { dev_warn(data->dev, "sample read failed %d\n", ret); - return IRQ_NONE;Quoted 8 lines
Review static irqreturn_t bm1390_trigger_handler(int · line 647
Quoted 2 lines
(quoted diff) +2
-0+ handled = false; + goto done;Hopefully all this stuff is unrelated to the trigger. For these it is fair to
ack the trigger and the interrupt. Curiously the driver does it partly for the
next one (IRQ_HANDLED).Quoted 7 lines
I would keep the
IRQ_NONEhere because, if we keep constantly failing the reads, then the bus is likely to be unerliable - and disabling the useless IRQ is probably very sane thing to do. It should help debugging. What comes to acking the trigger - I am starting to agree with Stepan, we should probably ack the trigger in any case. If we don't ack the trigger, then theIRQ_NONEdoes not serve the purpose it is intended for.The interrupt that we'd get spurious detection on here would not be the device
one it would be the software emulated one deep in the iio trigger stuff.Quoted 7 lines
Quoted 5 lines
Might still be useful for debug. Anyone fancy hacking an error in and reporting
back what we actually get from the debug hardware? (with that trigger acked
as you suggest?)No promises but I'll see if I can try out something next week...
The week has been horrible... I only had around half an hour for this (just now). Quick:
+++
b/drivers/iio/pressure/rohm-bm1390.c(quoted diff) +2
-0@@ -621,6 +621,16 @@ static const struct iio_buffer_setup_ops bm1390_buffer_ops = { .predisable = bm1390_buffer_predisable, }; +/* + * Test case where IRQ status is nopt read (acked). Useful forevaluating the
+ * impact of returning theIRQ_NONEfrom the trigger handler. define also the
+ *TEST_FORCE_IRQ_NOTIFYif you wish to cause the trigger to be notified.
+ *
+ * Note, in case it is not obvious, this will cause IRQ storm.
+ */(quoted diff) +19
-1+#define TEST_FORCE_IRQ_NONE +#define TEST_FORCE_IRQ_NOTIFY + static irqreturn_t bm1390_trigger_handler(int irq, void *p) { struct iio_poll_func *pf = p;@@ -628,12 +638,27 @@ static irqreturn_t bm1390_trigger_handler(int irq, void *p) struct bm1390_data *data = iio_priv(idev); int ret, status; +#ifdef TEST_FORCE_IRQ_NONE + static unsigned long int first = 1, first2 = 0; + ret = 0; + + if (first) { + pr_info("Skip read\n"); + first = 0; + } + #ifdef TEST_FORCE_IRQ_NOTIFY + status = BIT(BM1390_CHAN_PRESSURE); + #else + status = 0; + #endif +#else /* DRDY is acked by reading status reg */ ret = regmap_read(data->regmap, BM1390_REG_STATUS, &status); if (ret || !status) return IRQ_NONE; +#endif - dev_dbg(data->dev, "DRDY trig status 0x%x\n", status); +// dev_dbg(data->dev, "DRDY trig status 0x%x\n", status); if (test_bit(BM1390_CHAN_PRESSURE, idev->active_scan_mask)) {ret = bm1390_pressure_read(data, &data->buf.pressure);(quoted diff) +10
-0@@ -656,7 +681,17 @@ static irqreturn_t bm1390_trigger_handler(int irq, void *p) data->timestamp); iio_trigger_notify_done(idev->trig); +#ifdef TEST_FORCE_IRQ_NONE + /* HACK, return IRQ_NONE and see if IRQ gets disabled */ + if (!(first2 % 1000)) + pr_info("Hack, return IRQ_NONE (%lu th)\n", first2); + + first2++; + + return IRQ_NONE; +#else return IRQ_HANDLED; +#endif }/* Get timestamps and wake the thread if we need to read data */
resulted:
root@arm:/home/debian# /iio_generic_buffer -a -c1000000 --device-name bm1390 -T0 > /dev/null Enabling all channels [ 115.098819] Skip read [ 115.102442] Hack, return IRQ_NONE (0 th) [ 116.459049] Hack, return IRQ_NONE (1000 th) [ 117.851037] Hack, return IRQ_NONE (2000 th) [ 119.214843] Hack, return IRQ_NONE (3000 th) [ 120.598114] Hack, return IRQ_NONE (4000 th) [ 121.960255] Hack, return IRQ_NONE (5000 th) [ 123.322424] Hack, return IRQ_NONE (6000 th)//snip
[ 237.726666] Hack, return IRQ_NONE (90000 th) [ 239.095910] Hack, return IRQ_NONE (91000 th) [ 240.481233] Hack, return IRQ_NONE (92000 th) [ 241.846072] Hack, return IRQ_NONE (93000 th) [ 243.206432] Hack, return IRQ_NONE (94000 th) [ 244.570636] Hack, return IRQ_NONE (95000 th) [ 245.928964] Hack, return IRQ_NONE (96000 th) [ 247.286839] Hack, return IRQ_NONE (97000 th) [ 248.647986] Hack, return IRQ_NONE (98000 th) [ 250.011214] Hack, return IRQ_NONE (99000 th) [ 251.368583] irq 64: nobody cared (try booting with the "irqpoll" option) [ 251.375463] CPU: 0 UID: 0 PID: 835 Comm: irq/63-2-005d-b Tainted: G O 7.1.0-rc1-00002-g3b459deb7222-dirty #249 VOLUNTARY [ 251.375501] Tainted: [O]=OOT_MODULE [ 251.375511] Hardware name: Generic AM33XX (Flattened Device Tree) [ 251.375525] Call trace: [ 251.375545] unwind_backtrace from show_stack+0x10/0x14 [ 251.375607] show_stack from dump_stack_lvl+0x50/0x64 [ 251.375646] dump_stack_lvl from __report_bad_irq+0x30/0xbc [ 251.375680] __report_bad_irq from note_interrupt+0x2b4/0x32c [ 251.375722] note_interrupt from handle_nested_irq+0x13c/0x14c [ 251.375758] handle_nested_irq from iio_trigger_poll_nested+0x4c/0x68 [industrialio] [ 251.375917] iio_trigger_poll_nested [industrialio] from bm1390_irq_thread_handler+0x54/0x7c [rohm_bm1390] [ 251.375994] bm1390_irq_thread_handler [rohm_bm1390] from irq_thread_fn+0x1c/0x78 [ 251.376028] irq_thread_fn from irq_thread+0x18c/0x324 [ 251.376057] irq_thread from kthread+0xf8/0x130 [ 251.376091] kthread from ret_from_fork+0x14/0x20 [ 251.376114] Exception stack(0xe0355fb0 to 0xe0355ff8) [ 251.376136] 5fa0: 00000000 00000000 00000000 00000000 [ 251.376156] 5fc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [ 251.376175] 5fe0: 00000000 00000000 00000000 00000000 00000013 00000000 [ 251.376189] handlers: [ 251.498714] [<2ec7a5d9>] iio_pollfunc_store_time [industrialio] threaded [<7f4268a2>] bm1390_trigger_handler [rohm_bm1390] [ 251.509974] Disabling IRQ #64Message from syslogd@arm at Jan 1 01:17:33 ...
kernel:[ 251.509974] Disabling IRQ #64
Quoted 8 lines
[ 252.822500] sched: RT throttling activatedThings I very hastly picked up:
1. The throttling mechanism works even though the handling is invoked via
iio_trigger_poll_nested(), Probably because this propagates the call to thehandle_nested_irq()- which does bookkeeping.
Great. At least it squashes something.
Quoted 5 lines
2. For some reason (which I didn't have time to check yet), the beaglebone black which I used to run this, was not completely blocked by the IRQ. We can see the "Hack, return
IRQ_NONE(xxx th)" -prints emerging just fine.
After the Disabling IRQ #64 message?
Quoted 7 lines
And now I must run. I hope to be able to dig some more details next week.
Yours,
-- Matti
Matti Vaittinen
maintainerQuoted 7 lines · Jonathan Cameron
Quoted 4 lines · On Fri, 29 May 2026 11:21:40 +0300 Matti Vaittinen <[email protected]>…
Quoted 3 lines · Matti Vaittinen
Quoted 2 lines · Jonathan Cameron
On Tue, 19 May 2026 08:48:13 +0300
Matti Vaittinen <[email protected]> wrote:
//snip
Quoted 36 lines
Quoted 36 lines
[ 251.368583] irq 64: nobody cared (try booting with the "irqpoll" option) [ 251.375463] CPU: 0 UID: 0 PID: 835 Comm: irq/63-2-005d-b Tainted: G O 7.1.0-rc1-00002-g3b459deb7222-dirty #249 VOLUNTARY [ 251.375501] Tainted: [O]=OOT_MODULE [ 251.375511] Hardware name: Generic AM33XX (Flattened Device Tree) [ 251.375525] Call trace: [ 251.375545] unwind_backtrace from show_stack+0x10/0x14 [ 251.375607] show_stack from dump_stack_lvl+0x50/0x64 [ 251.375646] dump_stack_lvl from __report_bad_irq+0x30/0xbc [ 251.375680] __report_bad_irq from note_interrupt+0x2b4/0x32c [ 251.375722] note_interrupt from handle_nested_irq+0x13c/0x14c [ 251.375758] handle_nested_irq from iio_trigger_poll_nested+0x4c/0x68 [industrialio] [ 251.375917] iio_trigger_poll_nested [industrialio] from bm1390_irq_thread_handler+0x54/0x7c [rohm_bm1390] [ 251.375994] bm1390_irq_thread_handler [rohm_bm1390] from irq_thread_fn+0x1c/0x78 [ 251.376028] irq_thread_fn from irq_thread+0x18c/0x324 [ 251.376057] irq_thread from kthread+0xf8/0x130 [ 251.376091] kthread from ret_from_fork+0x14/0x20 [ 251.376114] Exception stack(0xe0355fb0 to 0xe0355ff8) [ 251.376136] 5fa0: 00000000 00000000 00000000 00000000 [ 251.376156] 5fc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [ 251.376175] 5fe0: 00000000 00000000 00000000 00000000 00000013 00000000 [ 251.376189] handlers: [ 251.498714] [<2ec7a5d9>] iio_pollfunc_store_time [industrialio] threaded [<7f4268a2>] bm1390_trigger_handler [rohm_bm1390] [ 251.509974] Disabling IRQ #64Message from syslogd@arm at Jan 1 01:17:33 ...
kernel:[ 251.509974] Disabling IRQ #64[ 252.822500] sched: RT throttling activated
Quoted 7 lines
Quoted 5 lines
Things I very hastly picked up:
1. The throttling mechanism works even though the handling is invoked via
iio_trigger_poll_nested(), Probably because this propagates the call to thehandle_nested_irq()- which does bookkeeping.Great. At least it squashes something.
Yes. We get the nice trace in logs, clearly pointing to the guilty one.
Quoted 7 lines
Quoted 5 lines
2. For some reason (which I didn't have time to check yet), the beaglebone black which I used to run this, was not completely blocked by the IRQ. We can see the "Hack, return
IRQ_NONE(xxx th)" -prints emerging just fine.After the Disabling IRQ #64 message?
No. The prints were spilled out regularly, even before the IRQ got disabled. So, CPU was not completely consumed by the IRQs. I am not sure if the IRQ thread gets preempted (what is the default scheduling policy for IRQ threads?), or if we have some other safety mechanism letting other stuff be executed. In any case, the system stayed somewhat responsive.
***
I did also try a hack which returned the IRQ_NONE, but did not call the iio_trigger_notify_done(). Result was as expected - the IRQ stayed asserted as the bm1390_trigger_handler() was not invoked repeatedly. Furthermore, the very helpful log entry was not spilled.
I suppose that now, because the system stayed somewhat responsive (even when the IRQ stayed active in the background), it wasn't exactly hard to check the IRQ counters and spot the culprit from there.
As a bottom line, I would love to see this fix getting merged, even though it doesn't seem as crucial I thought it was. Checking the log is still first thing one does when spotting a problem - and the entry there was to the point. Not all systems capture IRQ counters when an error occurs - while many still capture the kernel logs :)
Yours,
-- Matti
Signature · 5 lines
Matti Vaittinen Linux kernel developer at ROHM Semiconductors Oulu Finland ~~ When things go utterly wrong vim users can always type :help! ~~
Matti Vaittinen
maintainerQuoted 6 lines · Andy Shevchenko
Quoted 4 lines · Matti Vaittinen
Quoted 3 lines · Matti Vaittinen
Quoted 2 lines · Jonathan Cameron
On Tue, 19 May 2026 08:48:13 +0300
Matti Vaittinen <[email protected]> wrote:
Quoted 8 lines
...
Review
Quoted 4 lines
(quoted diff) +4
-0+#ifdef TEST_FORCE_IRQ_NONE + /* HACK, return IRQ_NONE and see if IRQ gets disabled */ + if (!(first2 % 1000)) + pr_info("Hack, return IRQ_NONE (%lu th)\n", first2);Hint:
pr_info_ratelimited()seems better?
Thanks Andy. Yes, I suppose so. It's just that I _really_ rarely need ratelimit prints. Hence I don't remember exact form of these print APIs without checking for them. And it's easier to add a static counter (as a unsafe debug hack) than search for the function signatures ;)
Quoted 7 lines
Review
Quoted 6 lines
(quoted diff) +5
-0+ first2++; + + return IRQ_NONE; +#else return IRQ_HANDLED; +#endif
Yours,
-- Matti
Signature · 5 lines
Matti Vaittinen Linux kernel developer at ROHM Semiconductors Oulu Finland ~~ When things go utterly wrong vim users can always type :help! ~~