[PATCH v4 05/11] iio: amplifiers: ad8366: use devm_mutex_init() and drop mutex_init()

Rodrigo Alencar via B4 Relay posted 11 patches 1 month, 2 weeks ago
There is a newer version of this series
[PATCH v4 05/11] iio: amplifiers: ad8366: use devm_mutex_init() and drop mutex_init()
Posted by Rodrigo Alencar via B4 Relay 1 month, 2 weeks ago
From: Rodrigo Alencar <rodrigo.alencar@analog.com>

Adopt proper mutex lifecycle with devm_mutex_init(), replacing
mutex_init(). Also, Include linux/mutex.h header.

Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
---
 drivers/iio/amplifiers/ad8366.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/iio/amplifiers/ad8366.c b/drivers/iio/amplifiers/ad8366.c
index 3456a31cb1ee..f0053a09cbb6 100644
--- a/drivers/iio/amplifiers/ad8366.c
+++ b/drivers/iio/amplifiers/ad8366.c
@@ -15,6 +15,7 @@
 #include <linux/err.h>
 #include <linux/gpio/consumer.h>
 #include <linux/module.h>
+#include <linux/mutex.h>
 #include <linux/regulator/consumer.h>
 #include <linux/spi/spi.h>
 
@@ -251,6 +252,10 @@ static int ad8366_probe(struct spi_device *spi)
 
 	st = iio_priv(indio_dev);
 
+	ret = devm_mutex_init(dev, &st->lock);
+	if (ret)
+		return ret;
+
 	st->reg = devm_regulator_get(&spi->dev, "vcc");
 	if (!IS_ERR(st->reg)) {
 		ret = regulator_enable(st->reg);
@@ -259,7 +264,6 @@ static int ad8366_probe(struct spi_device *spi)
 	}
 
 	spi_set_drvdata(spi, indio_dev);
-	mutex_init(&st->lock);
 	st->spi = spi;
 	st->type = spi_get_device_id(spi)->driver_data;
 

-- 
2.43.0
Re: [PATCH v4 05/11] iio: amplifiers: ad8366: use devm_mutex_init() and drop mutex_init()
Posted by Jonathan Cameron 1 month, 2 weeks ago
On Tue, 10 Feb 2026 19:42:05 +0000
Rodrigo Alencar via B4 Relay <devnull+rodrigo.alencar.analog.com@kernel.org> wrote:

> From: Rodrigo Alencar <rodrigo.alencar@analog.com>
> 
> Adopt proper mutex lifecycle with devm_mutex_init(), replacing
> mutex_init(). Also, Include linux/mutex.h header.

Why move the *mutex_init()?  Even if it is just because it looks better there,
not breaking up spi related stuff, then say that.

> 
> Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
> ---
>  drivers/iio/amplifiers/ad8366.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/iio/amplifiers/ad8366.c b/drivers/iio/amplifiers/ad8366.c
> index 3456a31cb1ee..f0053a09cbb6 100644
> --- a/drivers/iio/amplifiers/ad8366.c
> +++ b/drivers/iio/amplifiers/ad8366.c
> @@ -15,6 +15,7 @@
>  #include <linux/err.h>
>  #include <linux/gpio/consumer.h>
>  #include <linux/module.h>
> +#include <linux/mutex.h>
>  #include <linux/regulator/consumer.h>
>  #include <linux/spi/spi.h>
>  
> @@ -251,6 +252,10 @@ static int ad8366_probe(struct spi_device *spi)
>  
>  	st = iio_priv(indio_dev);
>  
> +	ret = devm_mutex_init(dev, &st->lock);
> +	if (ret)
> +		return ret;
> +
>  	st->reg = devm_regulator_get(&spi->dev, "vcc");
>  	if (!IS_ERR(st->reg)) {
>  		ret = regulator_enable(st->reg);
> @@ -259,7 +264,6 @@ static int ad8366_probe(struct spi_device *spi)
>  	}
>  
>  	spi_set_drvdata(spi, indio_dev);
> -	mutex_init(&st->lock);
>  	st->spi = spi;
>  	st->type = spi_get_device_id(spi)->driver_data;
>  
>
Re: [PATCH v4 05/11] iio: amplifiers: ad8366: use devm_mutex_init() and drop mutex_init()
Posted by Andy Shevchenko 1 month, 2 weeks ago
On Sat, Feb 14, 2026 at 06:36:16PM +0000, Jonathan Cameron wrote:
> On Tue, 10 Feb 2026 19:42:05 +0000
> Rodrigo Alencar via B4 Relay <devnull+rodrigo.alencar.analog.com@kernel.org> wrote:

> > Adopt proper mutex lifecycle with devm_mutex_init(), replacing
> > mutex_init(). Also, Include linux/mutex.h header.
> 
> Why move the *mutex_init()?  Even if it is just because it looks better there,
> not breaking up spi related stuff, then say that.

Yes, this needs to be recorded. But actually initialising mutex (and lock
in general) earlier is usually a good thing and in some cases might even
fix a hidden bug.

-- 
With Best Regards,
Andy Shevchenko
Re: [PATCH v4 05/11] iio: amplifiers: ad8366: use devm_mutex_init() and drop mutex_init()
Posted by Andy Shevchenko 1 month, 2 weeks ago
On Tue, Feb 10, 2026 at 07:42:05PM +0000, Rodrigo Alencar via B4 Relay wrote:

> Adopt proper mutex lifecycle with devm_mutex_init(), replacing
> mutex_init(). Also, Include linux/mutex.h header.

mutex.h should be included before as it's not a new API added in this patch.

Otherwise LGTM.

-- 
With Best Regards,
Andy Shevchenko