mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Krzysztof Kozlowski <krzk@kernel.org>
To: rodrigo.alencar@analog.com, linux-kernel@vger.kernel.org,
	linux-iio@vger.kernel.org, devicetree@vger.kernel.org
Cc: Michael Hennerich <Michael.Hennerich@analog.com>,
	Lars-Peter Clausen <lars@metafoo.de>,
	Jonathan Cameron <jic23@kernel.org>,
	David Lechner <dlechner@baylibre.com>,
	Andy Shevchenko <andy@kernel.org>, Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>
Subject: Re: [PATCH 6/7] iio: amplifiers: ad8366: simplify resource management
Date: Mon, 19 Jan 2026 15:45:26 +0100	[thread overview]
Message-ID: <836b3f85-1ba3-4d49-b027-06990325fc4d@kernel.org> (raw)
In-Reply-To: <20260119-iio-ad8366-update-v1-6-8044e23e964a@analog.com>

On 19/01/2026 15:37, Rodrigo Alencar via B4 Relay wrote:
> From: Rodrigo Alencar <rodrigo.alencar@analog.com>
> 
> Device resource managed simplified with:

Use more readable style.
https://elixir.bootlin.com/linux/v6.16/source/Documentation/process/submitting-patches.rst#L94

> - voltage regulator managed internally by the device.
> - IIO device registration handled with devm_iio_device_register().
> - removal of goto's from the probe function.
> - ad8366_remove() removed as it is not needed anymore.
> 
> Also, dev_err_probe() is used to report probe errors with created local
> device pointer.
> 
> Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
> ---
>  drivers/iio/amplifiers/ad8366.c | 68 +++++++++++------------------------------
>  1 file changed, 18 insertions(+), 50 deletions(-)
> 
> diff --git a/drivers/iio/amplifiers/ad8366.c b/drivers/iio/amplifiers/ad8366.c
> index 26856cb4216e..d3fd8d44eae7 100644
> --- a/drivers/iio/amplifiers/ad8366.c
> +++ b/drivers/iio/amplifiers/ad8366.c
> @@ -53,7 +53,6 @@ struct ad8366_info {
>  
>  struct ad8366_state {
>  	struct spi_device	*spi;
> -	struct regulator	*reg;
>  	struct mutex            lock; /* protect sensor state */
>  	struct gpio_desc	*reset_gpio;
>  	struct gpio_desc	*enable_gpio;
> @@ -321,26 +320,22 @@ static int ad8366_probe(struct spi_device *spi)
>  {
>  	struct iio_dev *indio_dev;
>  	struct ad8366_state *st;
> +	struct device *dev = &spi->dev;
>  	int ret;
>  
> -	indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
> +	indio_dev = devm_iio_device_alloc(dev, sizeof(*st));
>  	if (indio_dev == NULL)
>  		return -ENOMEM;
>  
>  	st = iio_priv(indio_dev);
> -
> -	st->reg = devm_regulator_get(&spi->dev, "vcc");
> -	if (!IS_ERR(st->reg)) {
> -		ret = regulator_enable(st->reg);
> -		if (ret)
> -			return ret;
> -	}
> -
> -	spi_set_drvdata(spi, indio_dev);
>  	st->spi = spi;
>  	st->type = spi_get_device_id(spi)->driver_data;
>  
> -	ret = devm_mutex_init(&spi->dev, &st->lock);

No need to change the line twice. Just use dev in previous commit. Or
re-order commits.

> +	ret = devm_regulator_get_enable(dev, "vcc");
> +	if (ret)
> +		return dev_err_probe(dev, ret, "Failed to get regulator\n");
> +
> +	ret = devm_mutex_init(dev, &st->lock);
>  	if (ret)
>  		return ret;
>  
> @@ -359,25 +354,21 @@ static int ad8366_probe(struct spi_device *spi)
>  	case ID_ADRF5731:
>  	case ID_HMC1018:
>  	case ID_HMC1019:
> -		st->reset_gpio = devm_gpiod_get_optional(&spi->dev, "reset", GPIOD_OUT_HIGH);
> -		if (IS_ERR(st->reset_gpio)) {
> -			ret = PTR_ERR(st->reset_gpio);
> -			goto error_disable_reg;
> -		}
> +		st->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);
> +		if (IS_ERR(st->reset_gpio))
> +			return dev_err_probe(dev, PTR_ERR(st->reset_gpio),
> +					     "Failed to get reset GPIO\n");
>  
> -		st->enable_gpio = devm_gpiod_get_optional(&spi->dev, "enable", GPIOD_OUT_HIGH);
> -		if (IS_ERR(st->enable_gpio)) {
> -			ret = PTR_ERR(st->enable_gpio);
> -			goto error_disable_reg;
> -		}
> +		st->enable_gpio = devm_gpiod_get_optional(dev, "enable", GPIOD_OUT_HIGH);

You just added these lines before. Cleanups always go BEFORE new
feature. Always.

> +		if (IS_ERR(st->enable_gpio))
> +			return dev_err_probe(dev, PTR_ERR(st->enable_gpio),
> +					     "Failed to get enable GPIO\n");
>  
>  		indio_dev->channels = ada4961_channels;
>  		indio_dev->num_channels = ARRAY_SIZE(ada4961_channels);
>  		break;
>  	default:
> -		dev_err(&spi->dev, "Invalid device ID\n");
> -		ret = -EINVAL;
> -		goto error_disable_reg;
> +		return dev_err_probe(dev, -EINVAL, "Invalid device ID\n");
>  	}
>  
>  	st->info = &ad8366_infos[st->type];
> @@ -387,31 +378,9 @@ static int ad8366_probe(struct spi_device *spi)
>  
>  	ret = ad8366_write(indio_dev, 0, 0);
>  	if (ret < 0)
> -		goto error_disable_reg;
> +		return dev_err_probe(dev, ret, "failed to write initial gain\n");
>  
Best regards,
Krzysztof

  reply	other threads:[~2026-01-19 14:45 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-19 14:36 [PATCH 0/7] iio: amplifiers: ad8366: driver update and dt support Rodrigo Alencar via B4 Relay
2026-01-19 14:36 ` [PATCH 1/7] MAINTAINERS: Add missing maintainer entry for AD8366 driver Rodrigo Alencar via B4 Relay
2026-01-19 14:36 ` [PATCH 2/7] dt-bindings: iio: amplifiers: Add AD8366 support Rodrigo Alencar via B4 Relay
2026-01-21  8:10   ` Krzysztof Kozlowski
2026-01-19 14:36 ` [PATCH 3/7] iio: amplifiers: ad8366: consume enable gpio for applicable parts Rodrigo Alencar via B4 Relay
2026-01-23  8:26   ` Jonathan Cameron
2026-01-19 14:36 ` [PATCH 4/7] iio: amplifiers: ad8366: Update device support Rodrigo Alencar via B4 Relay
2026-01-23  8:33   ` Jonathan Cameron
2026-01-23  8:38     ` Jonathan Cameron
2026-01-19 14:36 ` [PATCH 5/7] iio: amplifiers: ad8366: use cleanup.h mutex guard Rodrigo Alencar via B4 Relay
2026-01-19 14:43   ` Krzysztof Kozlowski
2026-01-23  8:36     ` Jonathan Cameron
2026-01-19 14:37 ` [PATCH 6/7] iio: amplifiers: ad8366: simplify resource management Rodrigo Alencar via B4 Relay
2026-01-19 14:45   ` Krzysztof Kozlowski [this message]
2026-01-19 14:37 ` [PATCH 7/7] iio: amplifiers: ad8366: add device tree support Rodrigo Alencar via B4 Relay
2026-01-19 14:47   ` Krzysztof Kozlowski
2026-01-23  8:42     ` 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=836b3f85-1ba3-4d49-b027-06990325fc4d@kernel.org \
    --to=krzk@kernel.org \
    --cc=Michael.Hennerich@analog.com \
    --cc=andy@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=jic23@kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=rodrigo.alencar@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®