public inbox for linux-iio@vger.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: linux-iio@vger.kernel.org
Cc: Alexandru Ardelean <aardelean@deviqon.com>,
	Jonathan Cameron <Jonathan.Cameron@huawei.com>,
	Akinobu Mita <akinobu.mita@gmail.com>
Subject: [PATCH 3/8] iio: adc: max1118: Use devm_ managed functions for all of probe
Date: Sun, 16 May 2021 18:25:15 +0100	[thread overview]
Message-ID: <20210516172520.1398835-4-jic23@kernel.org> (raw)
In-Reply-To: <20210516172520.1398835-1-jic23@kernel.org>

From: Jonathan Cameron <Jonathan.Cameron@huawei.com>

This simplifies error handling and allows us to drop the remove
function entirely.

Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Cc: Akinobu Mita <akinobu.mita@gmail.com>
---
 drivers/iio/adc/max1118.c | 46 +++++++++++++--------------------------
 1 file changed, 15 insertions(+), 31 deletions(-)

diff --git a/drivers/iio/adc/max1118.c b/drivers/iio/adc/max1118.c
index 6efb0b43d938..4dfbed63ad7f 100644
--- a/drivers/iio/adc/max1118.c
+++ b/drivers/iio/adc/max1118.c
@@ -201,6 +201,11 @@ static irqreturn_t max1118_trigger_handler(int irq, void *p)
 	return IRQ_HANDLED;
 }
 
+static void max1118_reg_disable(void *reg)
+{
+	regulator_disable(reg);
+}
+
 static int max1118_probe(struct spi_device *spi)
 {
 	struct iio_dev *indio_dev;
@@ -225,6 +230,12 @@ static int max1118_probe(struct spi_device *spi)
 		ret = regulator_enable(adc->reg);
 		if (ret)
 			return ret;
+
+		ret = devm_add_action_or_reset(&spi->dev, max1118_reg_disable,
+					       adc->reg);
+		if (ret)
+			return ret;
+
 	}
 
 	spi_set_drvdata(spi, indio_dev);
@@ -243,38 +254,12 @@ static int max1118_probe(struct spi_device *spi)
 	 */
 	max1118_read(spi, 0);
 
-	ret = iio_triggered_buffer_setup(indio_dev, NULL,
-					max1118_trigger_handler, NULL);
+	ret = devm_iio_triggered_buffer_setup(&spi->dev, indio_dev, NULL,
+					      max1118_trigger_handler, NULL);
 	if (ret)
-		goto err_reg_disable;
-
-	ret = iio_device_register(indio_dev);
-	if (ret)
-		goto err_buffer_cleanup;
-
-	return 0;
-
-err_buffer_cleanup:
-	iio_triggered_buffer_cleanup(indio_dev);
-err_reg_disable:
-	if (id->driver_data == max1118)
-		regulator_disable(adc->reg);
-
-	return ret;
-}
-
-static int max1118_remove(struct spi_device *spi)
-{
-	struct iio_dev *indio_dev = spi_get_drvdata(spi);
-	struct max1118 *adc = iio_priv(indio_dev);
-	const struct spi_device_id *id = spi_get_device_id(spi);
-
-	iio_device_unregister(indio_dev);
-	iio_triggered_buffer_cleanup(indio_dev);
-	if (id->driver_data == max1118)
-		return regulator_disable(adc->reg);
+		return ret;
 
-	return 0;
+	return devm_iio_device_register(&spi->dev, indio_dev);
 }
 
 static const struct spi_device_id max1118_id[] = {
@@ -299,7 +284,6 @@ static struct spi_driver max1118_spi_driver = {
 		.of_match_table = max1118_dt_ids,
 	},
 	.probe = max1118_probe,
-	.remove = max1118_remove,
 	.id_table = max1118_id,
 };
 module_spi_driver(max1118_spi_driver);
-- 
2.31.1


  parent reply	other threads:[~2021-05-16 17:26 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-16 17:25 [PATCH 0/8] iio: adc: Maxim and TI ADC driver cleanups Jonathan Cameron
2021-05-16 17:25 ` [PATCH 1/8] iio: adc: max11100: Use get_unaligned_be16() rather than opencoding Jonathan Cameron
2021-05-17  6:59   ` Alexandru Ardelean
2021-05-16 17:25 ` [PATCH 2/8] iio: adc: max11100: Use devm_ functions for rest of probe() Jonathan Cameron
2021-05-17  7:08   ` Alexandru Ardelean
2021-05-17  7:22     ` Alexandru Ardelean
2021-05-16 17:25 ` Jonathan Cameron [this message]
2021-05-17  7:18   ` [PATCH 3/8] iio: adc: max1118: Use devm_ managed functions for all of probe Alexandru Ardelean
2021-05-16 17:25 ` [PATCH 4/8] iio: adc: max1118: Avoid jumping back and forth between spi and iio structures Jonathan Cameron
2021-05-17  7:24   ` Alexandru Ardelean
2021-05-16 17:25 ` [PATCH 5/8] iio: adc: ti-adc081c: Use devm managed functions for all of probe() Jonathan Cameron
2021-05-17  7:26   ` Alexandru Ardelean
2021-05-16 17:25 ` [PATCH 6/8] iio: adc: ti-adc0832: " Jonathan Cameron
2021-05-17  7:28   ` Alexandru Ardelean
2021-05-16 17:25 ` [PATCH 7/8] iio: adc: ti-adc108s102: " Jonathan Cameron
2021-05-17  7:31   ` Alexandru Ardelean
2021-05-17  7:37     ` Alexandru Ardelean
2021-05-22 18:29       ` Jonathan Cameron
2021-05-16 17:25 ` [PATCH 8/8] iio: adc: ti-adc161s626: Use devm managed functions for all of probe Jonathan Cameron
2021-05-16 20:04   ` Matt Ranostay
2021-05-17  7:35   ` Alexandru Ardelean
2021-05-22 18:31 ` [PATCH 0/8] iio: adc: Maxim and TI ADC driver cleanups 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=20210516172520.1398835-4-jic23@kernel.org \
    --to=jic23@kernel.org \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=aardelean@deviqon.com \
    --cc=akinobu.mita@gmail.com \
    --cc=linux-iio@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