Re: [PATCH] iio: inkern: guard fwnode_xlate with info_exist_lock

From: Arnav Kapoor

Date: Wed Nov 25 2026 - 23:59:57 EST


On Wed, Nov 25, 2026 at 11:48:27PM +0000, Ilia Snezhkov wrote:
> + scoped_guard(mutex, &iio_dev_opaque->info_exist_lock) {
> + if (!indio_dev->info)
> + index = -ENODEV;

Taking info_exist_lock here matches the rest of inkern.c, but -ENODEV
already means "no channel on this node, keep looking" in the callers.
Without a name, __fwnode_iio_channel_get_by_name() passes it back up,
fwnode_iio_channel_get_by_name() then walks the parents and
iio_channel_get() falls back to iio_channel_get_sys(), and
iio_channel_get_all() falls back to the map list on -ENODEV from
fwnode_iio_channel_get_all(). So if the race is hit, the lookup carries
on instead of failing. A code that isn't used as that sentinel would
avoid it.

> + if (index >= indio_dev->num_channels)
> + index = -EINVAL;

__fwnode_iio_simple_xlate() already checks args[0] against
num_channels, so this only matters for drivers with their own
fwnode_xlate. Could the commit message say that, or could it be a
separate patch? It is unrelated to the locking.

Thanks,
Arnav