public inbox for devicetree@vger.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Matti Vaittinen <mazziesaccount@gmail.com>
Cc: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>,
	Lars-Peter Clausen <lars@metafoo.de>,
	Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>, Nuno Sa <nuno.sa@analog.com>,
	David Lechner <dlechner@baylibre.com>,
	Javier Carrasco <javier.carrasco.cruz@gmail.com>,
	linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 5/6] iio: adc: ti-adc128s052: Simplify using guard(mutex)
Date: Mon, 31 Mar 2025 12:14:53 +0100	[thread overview]
Message-ID: <20250331121453.690642f7@jic23-huawei> (raw)
In-Reply-To: <93a9d7ab74cd045949a2e2b6301f29c7d83d72ea.1742474322.git.mazziesaccount@gmail.com>

On Mon, 31 Mar 2025 11:03:44 +0300
Matti Vaittinen <mazziesaccount@gmail.com> wrote:

> Error path in ADC reading function can be slighly simplified using the
> guard(mutex). Do just that.
> 
> Also, document the mutex purpose while at it.
Ah. I should have read on before earlier comment!

That's what I get for an efficient linear pass of patches :)
> 
> Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
> ---
>  drivers/iio/adc/ti-adc128s052.c | 11 ++++-------
>  1 file changed, 4 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/iio/adc/ti-adc128s052.c b/drivers/iio/adc/ti-adc128s052.c
> index 90b23c68daea..c68ee4e17a03 100644
> --- a/drivers/iio/adc/ti-adc128s052.c
> +++ b/drivers/iio/adc/ti-adc128s052.c
> @@ -9,6 +9,7 @@
>   * https://www.ti.com/lit/ds/symlink/adc124s021.pdf
>   */
>  
> +#include <linux/cleanup.h>
>  #include <linux/err.h>
>  #include <linux/iio/iio.h>
>  #include <linux/mod_devicetable.h>
> @@ -26,6 +27,7 @@ struct adc128 {
>  	struct spi_device *spi;
>  
>  	struct regulator *reg;
> +	/* Serialize the SPI 'write-channel + read data' accesses */
>  	struct mutex lock;
>  
>  	__be16 buffer __aligned(IIO_DMA_MINALIGN);
> @@ -39,18 +41,13 @@ static int adc128_adc_conversion(struct adc128 *adc, u8 channel)
>  	msg[0] = channel << 3;
>  	msg[1] = 0;
>  
> -	mutex_lock(&adc->lock);
> +	guard(mutex)(&adc->lock);
As per earlier comment, I think you need to protect msg as well.

>  
>  	ret = spi_write(adc->spi, msg, 2);
> -	if (ret < 0) {
> -		mutex_unlock(&adc->lock);
> +	if (ret < 0)
>  		return ret;
> -	}
>  
>  	ret = spi_read(adc->spi, &adc->buffer, 2);
> -
> -	mutex_unlock(&adc->lock);
> -
>  	if (ret < 0)
>  		return ret;
>  


  reply	other threads:[~2025-03-31 11:15 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-31  8:01 [PATCH 0/6] Support ROHM BD79104 ADC Matti Vaittinen
2025-03-31  8:02 ` [PATCH 1/6] dt-bindings: " Matti Vaittinen
2025-03-31 15:47   ` Conor Dooley
2025-03-31  8:02 ` [PATCH 2/6] iio: adc: ti-adc128s052: Fix ADC value on BE systems Matti Vaittinen
2025-03-31 11:11   ` Jonathan Cameron
2025-03-31 12:07     ` Matti Vaittinen
2025-03-31  8:03 ` [PATCH 3/6] iio: adc: ti-adc128s052: Be consistent with arrays Matti Vaittinen
2025-03-31 11:13   ` Jonathan Cameron
2025-03-31  8:03 ` [PATCH 4/6] iio: adc: ti-adc128s052: Use devm_mutex_init() Matti Vaittinen
2025-03-31 11:13   ` Jonathan Cameron
2025-03-31  8:03 ` [PATCH 5/6] iio: adc: ti-adc128s052: Simplify using guard(mutex) Matti Vaittinen
2025-03-31 11:14   ` Jonathan Cameron [this message]
2025-03-31  8:03 ` [PATCH 6/6] iio: adc: ti-adc128s052: Support ROHM BD79104 Matti Vaittinen
2025-03-31 11:22   ` Jonathan Cameron
2025-04-01 12:33     ` Matti Vaittinen
2025-04-05 17:43       ` Jonathan Cameron
2025-04-07  6:10         ` Matti Vaittinen
2025-04-07 18:44           ` Jonathan Cameron

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250331121453.690642f7@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=javier.carrasco.cruz@gmail.com \
    --cc=krzk+dt@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matti.vaittinen@fi.rohmeurope.com \
    --cc=mazziesaccount@gmail.com \
    --cc=nuno.sa@analog.com \
    --cc=robh@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox