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

From: Matti Vaittinen

Date: Mon May 18 2026 - 03:42:57 EST


On 18/05/2026 09:59, Andy Shevchenko wrote:
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.

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

--
Matti Vaittinen
Linux kernel developer at ROHM Semiconductors
Oulu Finland

~~ When things go utterly wrong vim users can always type :help! ~~