Linux IIO development
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Arturas Moskvinas <arturas.moskvinas@gmail.com>
Cc: Jonathan.Cameron@huawei.com, oskar.andero@gmail.com,
	lars@metafoo.de, lukas@wunner.de, linux-iio@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] iio: adc: mcp320x: Simplify device removal logic
Date: Sat, 24 Feb 2024 16:03:46 +0000	[thread overview]
Message-ID: <20240224160346.61675eba@jic23-huawei> (raw)
In-Reply-To: <20240219074139.193464-2-arturas.moskvinas@gmail.com>

On Mon, 19 Feb 2024 09:41:40 +0200
Arturas Moskvinas <arturas.moskvinas@gmail.com> wrote:

> Use devm_* APIs to enable/disable regulator and to register in IIO infrastructure.
> 
> Signed-off-by: Arturas Moskvinas <arturas.moskvinas@gmail.com>
Applied to the togreg branch of iio.git. Initially pushed out as testing
to let 0-day have a first go at pointing out what we missed in review.

Thanks,

Jonathan

> 
> ---
> v1 -> v2:
> - Use devm_add_action_or_reset instead of devm_regulator_get_enable to automate disabling regulator
> - Remove empty mcp320x_remove function
> ---
>  drivers/iio/adc/mcp320x.c | 29 +++++++++--------------------
>  1 file changed, 9 insertions(+), 20 deletions(-)
> 
> diff --git a/drivers/iio/adc/mcp320x.c b/drivers/iio/adc/mcp320x.c
> index f3b81798b3c9..da1421bd7b62 100644
> --- a/drivers/iio/adc/mcp320x.c
> +++ b/drivers/iio/adc/mcp320x.c
> @@ -371,6 +371,11 @@ static const struct mcp320x_chip_info mcp320x_chip_infos[] = {
>  	},
>  };
>  
> +static void mcp320x_regulator_disable(void *reg)
> +{
> +	regulator_disable(reg);
> +}
> +
>  static int mcp320x_probe(struct spi_device *spi)
>  {
>  	struct iio_dev *indio_dev;
> @@ -388,7 +393,6 @@ static int mcp320x_probe(struct spi_device *spi)
>  	indio_dev->name = spi_get_device_id(spi)->name;
>  	indio_dev->modes = INDIO_DIRECT_MODE;
>  	indio_dev->info = &mcp320x_info;
> -	spi_set_drvdata(spi, indio_dev);
>  
>  	device_index = spi_get_device_id(spi)->driver_data;
>  	chip_info = &mcp320x_chip_infos[device_index];
> @@ -445,27 +449,13 @@ static int mcp320x_probe(struct spi_device *spi)
>  	if (ret < 0)
>  		return ret;
>  
> -	mutex_init(&adc->lock);
> -
> -	ret = iio_device_register(indio_dev);
> +	ret = devm_add_action_or_reset(&spi->dev, mcp320x_regulator_disable, adc->reg);
>  	if (ret < 0)
> -		goto reg_disable;
> -
> -	return 0;
> -
> -reg_disable:
> -	regulator_disable(adc->reg);
> -
> -	return ret;
> -}
> +		return ret;
>  
> -static void mcp320x_remove(struct spi_device *spi)
> -{
> -	struct iio_dev *indio_dev = spi_get_drvdata(spi);
> -	struct mcp320x *adc = iio_priv(indio_dev);
> +	mutex_init(&adc->lock);
>  
> -	iio_device_unregister(indio_dev);
> -	regulator_disable(adc->reg);
> +	return devm_iio_device_register(&spi->dev, indio_dev);
>  }
>  
>  static const struct of_device_id mcp320x_dt_ids[] = {
> @@ -520,7 +510,6 @@ static struct spi_driver mcp320x_driver = {
>  		.of_match_table = mcp320x_dt_ids,
>  	},
>  	.probe = mcp320x_probe,
> -	.remove = mcp320x_remove,
>  	.id_table = mcp320x_id,
>  };
>  module_spi_driver(mcp320x_driver);
> 
> base-commit: 8d3dea210042f54b952b481838c1e7dfc4ec751d


      reply	other threads:[~2024-02-24 16:03 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-19  7:41 [PATCH v2] iio: adc: mcp320x: Simplify device removal logic Arturas Moskvinas
2024-02-24 16:03 ` Jonathan Cameron [this message]

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=20240224160346.61675eba@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=arturas.moskvinas@gmail.com \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lukas@wunner.de \
    --cc=oskar.andero@gmail.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