[PATCH 05/11] iio: adc: ad7606: use devm_mutex_init()

David Lechner posted 11 patches 9 months, 1 week ago
There is a newer version of this series
[PATCH 05/11] iio: adc: ad7606: use devm_mutex_init()
Posted by David Lechner 9 months, 1 week ago
Use devm_mutex_init() in ad7606_probe(). Mutexes should be cleaned up
on driver removal.

Also add missing include while we are touching this.

Signed-off-by: David Lechner <dlechner@baylibre.com>
---
 drivers/iio/adc/ad7606.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c
index 440e1e5a9b18570dc6441bff91afbc51d20cbc47..f190269ac8ddd859e94eb24c26f5f010d0951646 100644
--- a/drivers/iio/adc/ad7606.c
+++ b/drivers/iio/adc/ad7606.c
@@ -13,6 +13,7 @@
 #include <linux/interrupt.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
+#include <linux/mutex.h>
 #include <linux/property.h>
 #include <linux/pwm.h>
 #include <linux/regulator/consumer.h>
@@ -1332,8 +1333,11 @@ int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
 	st = iio_priv(indio_dev);
 	dev_set_drvdata(dev, indio_dev);
 
+	ret = devm_mutex_init(dev, &st->lock);
+	if (ret)
+		return ret;
+
 	st->dev = dev;
-	mutex_init(&st->lock);
 	st->bops = bops;
 	st->base_address = base_address;
 	st->oversampling = 1;

-- 
2.43.0
Re: [PATCH 05/11] iio: adc: ad7606: use devm_mutex_init()
Posted by Jonathan Cameron 9 months, 1 week ago
On Wed, 12 Mar 2025 20:15:43 -0500
David Lechner <dlechner@baylibre.com> wrote:

> Use devm_mutex_init() in ad7606_probe(). Mutexes should be cleaned up
> on driver removal.
> 
> Also add missing include while we are touching this.
> 
> Signed-off-by: David Lechner <dlechner@baylibre.com>

Just for the record (in case anyone other than us two is watching ;)
I'm not keen to have large numbers of patches doing this at this
point as the benefit in debug ability this brings is pretty tiny.

I'm absolutely fine with it in a series making other cleanup
type changes to a driver though - so fine here!

Note I will probably pick up the fixes soon after rc1 given
some look pretty important. That means stuff like this may have
to wait a while for the fixes to circulate around to the char-misc-next branch.

Jonathan

> ---
>  drivers/iio/adc/ad7606.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c
> index 440e1e5a9b18570dc6441bff91afbc51d20cbc47..f190269ac8ddd859e94eb24c26f5f010d0951646 100644
> --- a/drivers/iio/adc/ad7606.c
> +++ b/drivers/iio/adc/ad7606.c
> @@ -13,6 +13,7 @@
>  #include <linux/interrupt.h>
>  #include <linux/kernel.h>
>  #include <linux/module.h>
> +#include <linux/mutex.h>
>  #include <linux/property.h>
>  #include <linux/pwm.h>
>  #include <linux/regulator/consumer.h>
> @@ -1332,8 +1333,11 @@ int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
>  	st = iio_priv(indio_dev);
>  	dev_set_drvdata(dev, indio_dev);
>  
> +	ret = devm_mutex_init(dev, &st->lock);
> +	if (ret)
> +		return ret;
> +
>  	st->dev = dev;
> -	mutex_init(&st->lock);
>  	st->bops = bops;
>  	st->base_address = base_address;
>  	st->oversampling = 1;
>