[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <e5b175ae-34d4-47f2-92a4-2788f680da36@kernel.org>
Date: Mon, 19 Jan 2026 15:43:07 +0100
From: Krzysztof Kozlowski <krzk@...nel.org>
To: rodrigo.alencar@...log.com, linux-kernel@...r.kernel.org,
linux-iio@...r.kernel.org, devicetree@...r.kernel.org
Cc: Michael Hennerich <Michael.Hennerich@...log.com>,
Lars-Peter Clausen <lars@...afoo.de>, Jonathan Cameron <jic23@...nel.org>,
David Lechner <dlechner@...libre.com>, Andy Shevchenko <andy@...nel.org>,
Rob Herring <robh@...nel.org>, Krzysztof Kozlowski <krzk+dt@...nel.org>,
Conor Dooley <conor+dt@...nel.org>
Subject: Re: [PATCH 5/7] iio: amplifiers: ad8366: use cleanup.h mutex guard
On 19/01/2026 15:36, Rodrigo Alencar via B4 Relay wrote:
> From: Rodrigo Alencar <rodrigo.alencar@...log.com>
>
> Changes related to mutex handling:
> - use guard() from cleanup for mutex locking
> - replace mutex_init() for devm_mutex_init()
Why? We see all this from the diff but I do not see benefits.
>
> Signed-off-by: Rodrigo Alencar <rodrigo.alencar@...log.com>
> ---
> drivers/iio/amplifiers/ad8366.c | 14 +++++++++-----
> 1 file changed, 9 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/iio/amplifiers/ad8366.c b/drivers/iio/amplifiers/ad8366.c
> index 160a8ab0c2ee..26856cb4216e 100644
> --- a/drivers/iio/amplifiers/ad8366.c
> +++ b/drivers/iio/amplifiers/ad8366.c
> @@ -17,6 +17,7 @@
> * Copyright 2012-2026 Analog Devices Inc.
> */
>
> +#include <linux/cleanup.h>
> #include <linux/device.h>
> #include <linux/kernel.h>
> #include <linux/slab.h>
> @@ -164,7 +165,8 @@ static int ad8366_read_raw(struct iio_dev *indio_dev,
> int ret;
> int code, gain = 0;
>
> - mutex_lock(&st->lock);
> + guard(mutex)(&st->lock);
> +
> switch (m) {
> case IIO_CHAN_INFO_HARDWAREGAIN:
> code = st->ch[chan->channel];
> @@ -210,7 +212,6 @@ static int ad8366_read_raw(struct iio_dev *indio_dev,
> default:
> ret = -EINVAL;
> }
> - mutex_unlock(&st->lock);
This does not simplify code.
>
> return ret;
> };
> @@ -267,7 +268,8 @@ static int ad8366_write_raw(struct iio_dev *indio_dev,
> break;
> }
>
> - mutex_lock(&st->lock);
> + guard(mutex)(&st->lock);
Neither this.
> +
> switch (mask) {
> case IIO_CHAN_INFO_HARDWAREGAIN:
> st->ch[chan->channel] = code;
> @@ -276,7 +278,6 @@ static int ad8366_write_raw(struct iio_dev *indio_dev,
> default:
> ret = -EINVAL;
> }
> - mutex_unlock(&st->lock);
>
> return ret;
> }
> @@ -336,10 +337,13 @@ 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;
>
> + ret = devm_mutex_init(&spi->dev, &st->lock);
And this one actually has impact - missing mutex_destroy...
> + if (ret)
> + return ret;
> +
> switch (st->type) {
> case ID_AD8366:
> indio_dev->channels = ad8366_channels;
>
Best regards,
Krzysztof
Powered by blists - more mailing lists