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

From: Andy Shevchenko

Date: Fri Nov 27 2026 - 12:22:56 EST


On Fri, Nov 27, 2026 at 03:10:38AM +0000, Ilia Snezhkov via B4 Relay wrote:
>
> __fwnode_iio_channel_get() dereferences indio_dev->info->fwnode_xlate
> and invokes it without holding info_exist_lock. Concurrent
> iio_device_unregister() clears indio_dev->info under info_exist_lock,
> allowing a NULL dereference or callback execution during provider
> teardown.
>
> Hold iio_dev_opaque->info_exist_lock with scoped_guard(mutex, ...)
> matching the rest of inkern.c, and return -EPROBE_DEFER if
> indio_dev->info is NULL. Since iio_device_unregister() calls
> cdev_device_del() before clearing indio_dev->info, seeing a NULL info
> pointer corresponds to racing right before device removal from
> iio_bus_type, where !idev already returns -EPROBE_DEFER. Using
> -EPROBE_DEFER also avoids colliding with the -ENODEV sentinel used by
> callers to continue parent or map-list lookups and avoids the named
> lookup -EINVAL fallback in __fwnode_iio_channel_get_by_name().

Reviewed-by: Andy Shevchenko <andriy.shevchenko@xxxxxxxxx>

--
With Best Regards,
Andy Shevchenko