Linux IIO development
 help / color / mirror / Atom feed
From: Arturas Moskvinas <arturas.moskvinas@gmail.com>
To: Jonathan.Cameron@huawei.com, oskar.andero@gmail.com,
	lars@metafoo.de, lukas@wunner.de
Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
	Arturas Moskvinas <arturas.moskvinas@gmail.com>
Subject: [PATCH] iio: adc: mcp320x: Simplify device removal logic
Date: Thu,  8 Feb 2024 11:43:39 +0200	[thread overview]
Message-ID: <20240208094339.82633-1-arturas.moskvinas@gmail.com> (raw)

Use devm_* APIs to enable regulator and to register in IIO infrastructure.

Signed-off-by: Arturas Moskvinas <arturas.moskvinas@gmail.com>
---
 drivers/iio/adc/mcp320x.c | 19 ++-----------------
 1 file changed, 2 insertions(+), 17 deletions(-)

diff --git a/drivers/iio/adc/mcp320x.c b/drivers/iio/adc/mcp320x.c
index f3b81798b3c9..4685eed35271 100644
--- a/drivers/iio/adc/mcp320x.c
+++ b/drivers/iio/adc/mcp320x.c
@@ -388,7 +388,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];
@@ -441,31 +440,17 @@ static int mcp320x_probe(struct spi_device *spi)
 	if (IS_ERR(adc->reg))
 		return PTR_ERR(adc->reg);
 
-	ret = regulator_enable(adc->reg);
+	ret = devm_regulator_get_enable(&spi->dev, "vref");
 	if (ret < 0)
 		return ret;
 
 	mutex_init(&adc->lock);
 
-	ret = iio_device_register(indio_dev);
-	if (ret < 0)
-		goto reg_disable;
-
-	return 0;
-
-reg_disable:
-	regulator_disable(adc->reg);
-
-	return ret;
+	return devm_iio_device_register(&spi->dev, indio_dev);
 }
 
 static void mcp320x_remove(struct spi_device *spi)
 {
-	struct iio_dev *indio_dev = spi_get_drvdata(spi);
-	struct mcp320x *adc = iio_priv(indio_dev);
-
-	iio_device_unregister(indio_dev);
-	regulator_disable(adc->reg);
 }
 
 static const struct of_device_id mcp320x_dt_ids[] = {

base-commit: 047371968ffc470769f541d6933e262dc7085456
-- 
2.43.0


             reply	other threads:[~2024-02-08  9:43 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-08  9:43 Arturas Moskvinas [this message]
2024-02-10 15:58 ` [PATCH] iio: adc: mcp320x: Simplify device removal logic Jonathan Cameron
2024-02-11 15:36   ` Arturas Moskvinas

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=20240208094339.82633-1-arturas.moskvinas@gmail.com \
    --to=arturas.moskvinas@gmail.com \
    --cc=Jonathan.Cameron@huawei.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