Linux IIO development
 help / color / mirror / Atom feed
* [PATCH] iio: admv1013: initialize callback mutex before registering notifier
@ 2026-08-18 14:28 Runyu Xiao
  2026-08-18 15:31 ` Andy Shevchenko
  0 siblings, 1 reply; 5+ messages in thread
From: Runyu Xiao @ 2026-08-18 14:28 UTC (permalink / raw)
  To: Antoniu Miclaus
  Cc: Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron,
	David Lechner, Nuno Sa, Andy Shevchenko, linux-iio, linux-kernel,
	stable, Runyu Xiao, Jianhao Xu

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.

Fixes: da35a7b526d9 ("iio: frequency: admv1013: add support for ADMV1013")
Cc: stable@vger.kernel.org
Signed-off-by: Runyu Xiao <runyu.xiao@seu.edu.cn>
---
 drivers/iio/frequency/admv1013.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/frequency/admv1013.c b/drivers/iio/frequency/admv1013.c
index d8e8d541990f..932f094f2b04 100644
--- a/drivers/iio/frequency/admv1013.c
+++ b/drivers/iio/frequency/admv1013.c
@@ -594,12 +594,12 @@ static int admv1013_probe(struct spi_device *spi)
 				     "failed to get the LO input clock\n");
 
 	st->nb.notifier_call = admv1013_freq_change;
+	mutex_init(&st->lock);
+
 	ret = devm_clk_notifier_register(&spi->dev, st->clkin, &st->nb);
 	if (ret)
 		return ret;
 
-	mutex_init(&st->lock);
-
 	ret = admv1013_init(st, vcm_uv);
 	if (ret) {
 		dev_err(&spi->dev, "admv1013 init failed\n");
-- 
2.34.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] iio: admv1013: initialize callback mutex before registering notifier
  2026-08-18 14:28 [PATCH] iio: admv1013: initialize callback mutex before registering notifier Runyu Xiao
@ 2026-08-18 15:31 ` Andy Shevchenko
  2026-08-19  0:46   ` Jonathan Cameron
  0 siblings, 1 reply; 5+ messages in thread
From: Andy Shevchenko @ 2026-08-18 15:31 UTC (permalink / raw)
  To: Runyu Xiao
  Cc: Antoniu Miclaus, Lars-Peter Clausen, Michael Hennerich,
	Jonathan Cameron, David Lechner, Nuno Sa, Andy Shevchenko,
	linux-iio, linux-kernel, stable, Jianhao Xu

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.

...

>  	st->nb.notifier_call = admv1013_freq_change;

> +	mutex_init(&st->lock);
> +

Make it also to be devm_mutex_init().

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

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] iio: admv1013: initialize callback mutex before registering notifier
  2026-08-18 15:31 ` Andy Shevchenko
@ 2026-08-19  0:46   ` Jonathan Cameron
  2026-08-19 14:17     ` [PATCH v2] " Runyu Xiao
  0 siblings, 1 reply; 5+ messages in thread
From: Jonathan Cameron @ 2026-08-19  0:46 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Runyu Xiao, Antoniu Miclaus, Lars-Peter Clausen,
	Michael Hennerich, David Lechner, Nuno Sa, Andy Shevchenko,
	linux-iio, linux-kernel, stable, Jianhao Xu

On Tue, 18 Aug 2026 18:31:01 +0300
Andy Shevchenko <andriy.shevchenko@intel.com> 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;  
> 


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2] iio: admv1013: initialize callback mutex before registering notifier
  2026-08-19  0:46   ` Jonathan Cameron
@ 2026-08-19 14:17     ` Runyu Xiao
  2026-08-23  0:02       ` Jonathan Cameron
  0 siblings, 1 reply; 5+ messages in thread
From: Runyu Xiao @ 2026-08-19 14:17 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Antoniu Miclaus, Lars-Peter Clausen, Michael Hennerich,
	David Lechner, Nuno Sa, Andy Shevchenko, linux-iio, linux-kernel,
	stable, Runyu Xiao, Jianhao Xu

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.

Use devm_mutex_init() so the lock lifetime is tied to the device and
cleanup stays paired with the rest of the managed probe resources.

Fixes: da35a7b526d9 ("iio: frequency: admv1013: add support for ADMV1013")
Cc: stable@vger.kernel.org
Signed-off-by: Runyu Xiao <runyu.xiao@seu.edu.cn>
---
 drivers/iio/frequency/admv1013.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/frequency/admv1013.c b/drivers/iio/frequency/admv1013.c
index d8e8d541990f..ff599b5c88ef 100644
--- a/drivers/iio/frequency/admv1013.c
+++ b/drivers/iio/frequency/admv1013.c
@@ -594,11 +594,13 @@ static int admv1013_probe(struct spi_device *spi)
 				     "failed to get the LO input clock\n");
 
 	st->nb.notifier_call = admv1013_freq_change;
-	ret = devm_clk_notifier_register(&spi->dev, st->clkin, &st->nb);
+	ret = devm_mutex_init(&spi->dev, &st->lock);
 	if (ret)
 		return ret;
 
-	mutex_init(&st->lock);
+	ret = devm_clk_notifier_register(&spi->dev, st->clkin, &st->nb);
+	if (ret)
+		return ret;
 
 	ret = admv1013_init(st, vcm_uv);
 	if (ret) {
-- 
2.34.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] iio: admv1013: initialize callback mutex before registering notifier
  2026-08-19 14:17     ` [PATCH v2] " Runyu Xiao
@ 2026-08-23  0:02       ` Jonathan Cameron
  0 siblings, 0 replies; 5+ messages in thread
From: Jonathan Cameron @ 2026-08-23  0:02 UTC (permalink / raw)
  To: Runyu Xiao
  Cc: Antoniu Miclaus, Lars-Peter Clausen, Michael Hennerich,
	David Lechner, Nuno Sa, Andy Shevchenko, linux-iio, linux-kernel,
	stable, Jianhao Xu

On Wed, 19 Aug 2026 22:17:51 +0800
Runyu Xiao <runyu.xiao@seu.edu.cn> 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.
> 
> Use devm_mutex_init() so the lock lifetime is tied to the device and
> cleanup stays paired with the rest of the managed probe resources.
> 
> Fixes: da35a7b526d9 ("iio: frequency: admv1013: add support for ADMV1013")
> Cc: stable@vger.kernel.org
> Signed-off-by: Runyu Xiao <runyu.xiao@seu.edu.cn>

The code has changed a bit, so what I applied to the fixes-togreg branch of
iio.git ended up as:

diff --git a/drivers/iio/frequency/admv1013.c b/drivers/iio/frequency/admv10
index b852378b3f68..e86b59bf23fd 100644                                     
--- a/drivers/iio/frequency/admv1013.c                                      
+++ b/drivers/iio/frequency/admv1013.c                                      
@@ -602,11 +602,14 @@ static int admv1013_probe(struct spi_device *spi)     
                                     "failed to get the LO input clock\n"); 

        st->nb.notifier_call = admv1013_freq_change;
-       ret = devm_clk_notifier_register(dev, st->clkin, &st->nb);          
+                                                                           
+       ret = devm_mutex_init(dev, &st->lock);                              
        if (ret)
                return ret;

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

        ret = admv1013_init(st, vcm_uv);
        if (ret)


It will need a manual backport as a result if we want this to
go to stable.

Note it wasn't a particularly recent change. Make sure your patches
apply on linux-next or the appropriate subsystem tree.

Also, please don't reply to an earlier version when sending an
updated one.  It didn't matter here but for more complex threads
they can become very hard to follow + your email ends up way
back in people's email history so may not get much review.

Thanks

Jonathan

> ---
>  drivers/iio/frequency/admv1013.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/iio/frequency/admv1013.c b/drivers/iio/frequency/admv1013.c
> index d8e8d541990f..ff599b5c88ef 100644
> --- a/drivers/iio/frequency/admv1013.c
> +++ b/drivers/iio/frequency/admv1013.c
> @@ -594,11 +594,13 @@ static int admv1013_probe(struct spi_device *spi)
>  				     "failed to get the LO input clock\n");
>  
>  	st->nb.notifier_call = admv1013_freq_change;
> -	ret = devm_clk_notifier_register(&spi->dev, st->clkin, &st->nb);
> +	ret = devm_mutex_init(&spi->dev, &st->lock);
>  	if (ret)
>  		return ret;
>  
> -	mutex_init(&st->lock);
> +	ret = devm_clk_notifier_register(&spi->dev, st->clkin, &st->nb);
> +	if (ret)
> +		return ret;
>  
>  	ret = admv1013_init(st, vcm_uv);
>  	if (ret) {


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-08-23  0:02 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-18 14:28 [PATCH] iio: admv1013: initialize callback mutex before registering notifier Runyu Xiao
2026-08-18 15:31 ` Andy Shevchenko
2026-08-19  0:46   ` Jonathan Cameron
2026-08-19 14:17     ` [PATCH v2] " Runyu Xiao
2026-08-23  0:02       ` Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox