mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Nuno Sá" <noname.nuno@gmail.com>
To: David Lechner <dlechner@baylibre.com>,
	Jonathan Cameron <jic23@kernel.org>
Cc: "Marcelo Schmitt" <marcelo.schmitt1@gmail.com>,
	"Nuno Sá" <nuno.sa@analog.com>,
	"Michael Hennerich" <Michael.Hennerich@analog.com>,
	"Mark Brown" <broonie@kernel.org>,
	"Liam Girdwood" <lgirdwood@gmail.com>,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/5] iio: adc: ad7266: use devm_regulator_get_enable_read_voltage
Date: Tue, 04 Jun 2024 13:19:30 +0200	[thread overview]
Message-ID: <edb66fe8c2722e600179b1f9a0d81242d84582a0.camel@gmail.com> (raw)
In-Reply-To: <20240531-iio-adc-ref-supply-refactor-v1-2-4b313c0615ad@baylibre.com>

On Fri, 2024-05-31 at 16:19 -0500, David Lechner wrote:
> This makes use of the new devm_regulator_get_enable_read_voltage()
> function to reduce boilerplate code.
> 
> Signed-off-by: David Lechner <dlechner@baylibre.com>
> ---
>  drivers/iio/adc/ad7266.c | 37 ++++++++++---------------------------
>  1 file changed, 10 insertions(+), 27 deletions(-)
> 
> diff --git a/drivers/iio/adc/ad7266.c b/drivers/iio/adc/ad7266.c
> index 353a97f9c086..026db1bedc0a 100644
> --- a/drivers/iio/adc/ad7266.c
> +++ b/drivers/iio/adc/ad7266.c
> @@ -25,7 +25,6 @@
>  
>  struct ad7266_state {
>  	struct spi_device	*spi;
> -	struct regulator	*reg;
>  	unsigned long		vref_mv;
>  
>  	struct spi_transfer	single_xfer[3];
> @@ -377,11 +376,6 @@ static const char * const ad7266_gpio_labels[] = {
>  	"ad0", "ad1", "ad2",
>  };
>  
> -static void ad7266_reg_disable(void *reg)
> -{
> -	regulator_disable(reg);
> -}
> -
>  static int ad7266_probe(struct spi_device *spi)
>  {
>  	struct ad7266_platform_data *pdata = spi->dev.platform_data;
> @@ -396,28 +390,17 @@ static int ad7266_probe(struct spi_device *spi)
>  
>  	st = iio_priv(indio_dev);
>  
> -	st->reg = devm_regulator_get_optional(&spi->dev, "vref");
> -	if (!IS_ERR(st->reg)) {
> -		ret = regulator_enable(st->reg);
> -		if (ret)
> -			return ret;
> -
> -		ret = devm_add_action_or_reset(&spi->dev, ad7266_reg_disable, st-
> >reg);
> -		if (ret)
> -			return ret;
> -
> -		ret = regulator_get_voltage(st->reg);
> -		if (ret < 0)
> -			return ret;
> -
> -		st->vref_mv = ret / 1000;
> -	} else {
> -		/* Any other error indicates that the regulator does exist */
> -		if (PTR_ERR(st->reg) != -ENODEV)
> -			return PTR_ERR(st->reg);
> -		/* Use internal reference */
> +	/*
> +	 * Use external reference from vref if present, otherwise use 2.5V
> +	 * internal reference.
> +	 */

Not sure the comment brings any added value. The code is fairly self explanatory
IMO...

> +	ret = devm_regulator_get_enable_read_voltage(&spi->dev, "vref");
> +	if (ret == -ENODEV)
>  		st->vref_mv = 2500;
> -	}
> +	else if (ret < 0)
> +		return ret;
> +	else

I think it would be better (as that is the typical pattern) to first check for
errors. Also the 'return' in the middle of the else if () is a bit weird to me...
Maybe something like this?

if (ret < 0 && ret != -ENODEV)
	return ret;
if (ret == -ENODEV)
	st->vref_mv = 2500;
else
	st->vref_mv = ret / 1000;

or even replacing the if() else by
st->vref_mv = ret == -ENODEV ? 2500 : ret / 1000;

- Nuno Sá


  reply	other threads:[~2024-06-04 11:19 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-31 21:19 [PATCH 0/5] iio: adc: use devm_regulator_get_enable_read_voltage round 1 David Lechner
2024-05-31 21:19 ` [PATCH 1/5] iio: adc: ad7192: use devm_regulator_get_enable_read_voltage David Lechner
2024-06-01 12:48   ` Jonathan Cameron
2024-06-03 13:36     ` David Lechner
2024-06-03 20:10       ` Jonathan Cameron
2024-05-31 21:19 ` [PATCH 2/5] iio: adc: ad7266: " David Lechner
2024-06-04 11:19   ` Nuno Sá [this message]
2024-06-04 14:10     ` David Lechner
2024-06-05  9:33       ` Nuno Sá
2024-05-31 21:19 ` [PATCH 3/5] iio: adc: ad7292: " David Lechner
2024-06-08  4:28   ` Marcelo Schmitt
2024-05-31 21:19 ` [PATCH 4/5] iio: adc: ad7793: " David Lechner
2024-05-31 21:19 ` [PATCH 5/5] iio: adc: ad7944: " David Lechner
2024-06-01 13:01   ` Jonathan Cameron
2024-06-03 13:38     ` David Lechner

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=edb66fe8c2722e600179b1f9a0d81242d84582a0.camel@gmail.com \
    --to=noname.nuno@gmail.com \
    --cc=Michael.Hennerich@analog.com \
    --cc=broonie@kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=jic23@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marcelo.schmitt1@gmail.com \
    --cc=nuno.sa@analog.com \
    /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

all inboxes | Powered by JetHome®