Re: [PATCH] iio: admv1013: initialize callback mutex before registering notifier

From: Jonathan Cameron

Date: Tue Aug 18 2026 - 20:46:32 EST


On Tue, 18 Aug 2026 18:31:01 +0300
Andy Shevchenko <andriy.shevchenko@xxxxxxxxx> wrote:

> On Tue, Aug 18, 2026 at 10:28:11PM +0800, Runyu Xiao wrote:
> > admv1013_probe() registers a clock notifier whose callback takes
> > st->lock on POST_RATE_CHANGE. Initialize the mutex before
> > devm_clk_notifier_register() so the callback cannot observe an
> > uninitialized lock during probe.
>
> ...
>

Move the (devm_)mutex_init() up here to keep the notifier setup all together
after the change as it was before.


> > st->nb.notifier_call = admv1013_freq_change;
>
> > + mutex_init(&st->lock);
> > +
>
> Make it also to be devm_mutex_init().

Hmm. I'm a bit borderline on this as the minimal fix is indeed the
move done here. I guess it is trivial to do the
ret = devm_mutex_init(&st->lock);
if (ret)
return ret;

so we might as well do that as part of the fix rather than
adding churn by doing it as a follow up. So indeed, lets
have that for v2.

Thanks,

Jonathan

>
> > ret = devm_clk_notifier_register(&spi->dev, st->clkin, &st->nb);
> > if (ret)
> > return ret;
>