[PATCH v3 3/9] iio: amplifiers: ad8366: use devm_mutex_init() and drop mutex_init()

Rodrigo Alencar via B4 Relay posted 9 patches 6 days, 3 hours ago
[PATCH v3 3/9] iio: amplifiers: ad8366: use devm_mutex_init() and drop mutex_init()
Posted by Rodrigo Alencar via B4 Relay 6 days, 3 hours ago
From: Rodrigo Alencar <rodrigo.alencar@analog.com>

Adopt proper mutex lifecycle with devm_mutex_init(),
replacing mutex_init().

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

diff --git a/drivers/iio/amplifiers/ad8366.c b/drivers/iio/amplifiers/ad8366.c
index d06ac786501c..f0d44f2769ca 100644
--- a/drivers/iio/amplifiers/ad8366.c
+++ b/drivers/iio/amplifiers/ad8366.c
@@ -255,6 +255,10 @@ static int ad8366_probe(struct spi_device *spi)
 
 	st = iio_priv(indio_dev);
 
+	ret = devm_mutex_init(&spi->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);
@@ -263,7 +267,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 v3 3/9] iio: amplifiers: ad8366: use devm_mutex_init() and drop mutex_init()
Posted by Andy Shevchenko 5 days, 13 hours ago
On Tue, Feb 03, 2026 at 11:24:09AM +0000, Rodrigo Alencar via B4 Relay wrote:

> Adopt proper mutex lifecycle with devm_mutex_init(),
> replacing mutex_init().

...

It's better to add here

	struct device *dev = &spi->dev;

and (re-)use it in all followup patches. This will make the code easier
to read.

> +	ret = devm_mutex_init(&spi->dev, &st->lock);
> +	if (ret)
> +		return ret;

-- 
With Best Regards,
Andy Shevchenko
Re: [PATCH v3 3/9] iio: amplifiers: ad8366: use devm_mutex_init() and drop mutex_init()
Posted by Jonathan Cameron 3 days, 18 hours ago
On Wed, 4 Feb 2026 03:53:36 +0200
Andy Shevchenko <andriy.shevchenko@intel.com> wrote:

> On Tue, Feb 03, 2026 at 11:24:09AM +0000, Rodrigo Alencar via B4 Relay wrote:
> 
> > Adopt proper mutex lifecycle with devm_mutex_init(),
> > replacing mutex_init().  
> 
> ...
> 
> It's better to add here
> 
> 	struct device *dev = &spi->dev;
> 
> and (re-)use it in all followup patches. This will make the code easier
> to read.

Just to be clear. Please add a patch before this making use of
what Andy suggests in existing code. Then it will be available
to use in this patch as well.

Thanks,

Jonathan

> 
> > +	ret = devm_mutex_init(&spi->dev, &st->lock);
> > +	if (ret)
> > +		return ret;  
>