Re: [PATCH] iio: pressure: rohm-bm1390: notify trigger on all error paths

From: Andy Shevchenko

Date: Mon May 18 2026 - 03:00:54 EST


On Mon, May 18, 2026 at 08:21:17AM +0300, Matti Vaittinen wrote:
> On 17/05/2026 20:12, David Lechner wrote:
> > On 5/17/26 11:08 AM, Stepan Ionichev wrote:

...

> 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.

> 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 :)


--
With Best Regards,
Andy Shevchenko