linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Bartosz Golaszewski <brgl@bgdev.pl>
Cc: Lars-Peter Clausen <lars@metafoo.de>,
	Michael Hennerich <Michael.Hennerich@analog.com>,
	Linus Walleij <linus.walleij@linaro.org>,
	Cosmin Tanislav <cosmin.tanislav@analog.com>,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-gpio@vger.kernel.org,
	Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Subject: Re: [PATCH 2/7] iio: dac: ad5592r: use lock guards
Date: Mon, 7 Apr 2025 20:12:02 +0100	[thread overview]
Message-ID: <20250407201202.7c74a39d@jic23-huawei> (raw)
In-Reply-To: <20250407-gpiochip-set-rv-iio-v1-2-8431b003a145@linaro.org>

On Mon, 07 Apr 2025 09:18:10 +0200
Bartosz Golaszewski <brgl@bgdev.pl> wrote:

> From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
> 
> Use lock guards from linux/cleanup.h to simplify the code and remove
> some labels.
> 
> Note that we need to initialize some variables even though it's not
> technically required as scoped_guards() are implemented as for loops.
That is always a tiny bit irritating. Thanks for calling it out.
> 
> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
> ---
>  drivers/iio/dac/ad5592r-base.c | 119 ++++++++++++++++-------------------------
>  1 file changed, 47 insertions(+), 72 deletions(-)
> 
> diff --git a/drivers/iio/dac/ad5592r-base.c b/drivers/iio/dac/ad5592r-base.c
> index fe4c35689d4d..bbe3b52c6a12 100644
> --- a/drivers/iio/dac/ad5592r-base.c
> +++ b/drivers/iio/dac/ad5592r-base.c

Just one case I'd prefer done a tiny bit differently so as to alway do
early returns rather than very nearly always.


>  	udelay(250);
> @@ -249,45 +235,43 @@ static int ad5592r_set_channel_modes(struct ad5592r_state *st)
>  		}
>  	}
>  
> -	mutex_lock(&st->lock);
> +	guard(mutex)(&st->lock);
>  
>  	/* Pull down unused pins to GND */
>  	ret = ops->reg_write(st, AD5592R_REG_PULLDOWN, pulldown);
>  	if (ret)
> -		goto err_unlock;
> +		return ret;
>  
>  	ret = ops->reg_write(st, AD5592R_REG_TRISTATE, tristate);
>  	if (ret)
> -		goto err_unlock;
> +		return ret;
>  
>  	/* Configure pins that we use */
>  	ret = ops->reg_write(st, AD5592R_REG_DAC_EN, dac);
>  	if (ret)
> -		goto err_unlock;
> +		return ret;
>  
>  	ret = ops->reg_write(st, AD5592R_REG_ADC_EN, adc);
>  	if (ret)
> -		goto err_unlock;
> +		return ret;
>  
>  	ret = ops->reg_write(st, AD5592R_REG_GPIO_SET, st->gpio_val);
>  	if (ret)
> -		goto err_unlock;
> +		return ret;
>  
>  	ret = ops->reg_write(st, AD5592R_REG_GPIO_OUT_EN, st->gpio_out);
>  	if (ret)
> -		goto err_unlock;
> +		return ret;
>  
>  	ret = ops->reg_write(st, AD5592R_REG_GPIO_IN_EN, st->gpio_in);
>  	if (ret)
> -		goto err_unlock;
> +		return ret;
>  
>  	/* Verify that we can read back at least one register */
>  	ret = ops->reg_read(st, AD5592R_REG_ADC_EN, &read_back);
>  	if (!ret && (read_back & 0xff) != adc)
>  		ret = -EIO;
		return -EIO; 
for this one.

>  
> -err_unlock:
> -	mutex_unlock(&st->lock);
>  	return ret;
return 0; here

>  }

  reply	other threads:[~2025-04-07 19:12 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-07  7:18 [PATCH 0/7] iio: convert GPIO chips to using new value setters Bartosz Golaszewski
2025-04-07  7:18 ` [PATCH 1/7] iio: dac: ad5592r: destroy mutexes in detach paths Bartosz Golaszewski
2025-04-07 19:06   ` Jonathan Cameron
2025-04-07  7:18 ` [PATCH 2/7] iio: dac: ad5592r: use lock guards Bartosz Golaszewski
2025-04-07 19:12   ` Jonathan Cameron [this message]
2025-04-08  2:58   ` kernel test robot
2025-04-07  7:18 ` [PATCH 3/7] iio: dac: ad5592r: use new GPIO line value setter callbacks Bartosz Golaszewski
2025-04-07  7:18 ` [PATCH 4/7] iio: adc: ti-ads7950: " Bartosz Golaszewski
2025-04-07  7:18 ` [PATCH 5/7] iio: adc: ad4130: " Bartosz Golaszewski
2025-04-07  7:18 ` [PATCH 6/7] iio: addac: ad74413r: " Bartosz Golaszewski
2025-04-07  7:18 ` [PATCH 7/7] iio: addac: ad74115: " Bartosz Golaszewski
2025-04-07 19:16 ` [PATCH 0/7] iio: convert GPIO chips to using new value setters 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=20250407201202.7c74a39d@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=Michael.Hennerich@analog.com \
    --cc=bartosz.golaszewski@linaro.org \
    --cc=brgl@bgdev.pl \
    --cc=cosmin.tanislav@analog.com \
    --cc=lars@metafoo.de \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.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;
as well as URLs for NNTP newsgroup(s).