linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: linux-iio@vger.kernel.org
Cc: Lars-Peter Clausen <lars@metafoo.de>,
	alexandru.tachici@analog.com,
	Alexandru Ardelean <ardeleanalex@gmail.com>,
	Jonathan Cameron <Jonathan.Cameron@huawei.com>
Subject: [PATCH 3/3] iio: adc: ad7124: Use devm_ managed calls for all of probe() + drop remove()
Date: Sat,  8 May 2021 19:23:19 +0100	[thread overview]
Message-ID: <20210508182319.488551-4-jic23@kernel.org> (raw)
In-Reply-To: <20210508182319.488551-1-jic23@kernel.org>

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

As not many steps were not already devm_ managed, use
devm_add_action_or_reset() to handle the rest.

Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Cc: Cc: Alexandru Ardelean <ardeleanalex@gmail.com>
---
 drivers/iio/adc/ad7124.c | 53 ++++++++++++++++++----------------------
 1 file changed, 24 insertions(+), 29 deletions(-)

diff --git a/drivers/iio/adc/ad7124.c b/drivers/iio/adc/ad7124.c
index 9c2401c5848e..deb166d2b645 100644
--- a/drivers/iio/adc/ad7124.c
+++ b/drivers/iio/adc/ad7124.c
@@ -719,6 +719,16 @@ static void ad7124_reg_disable(void *r)
 	regulator_disable(r);
 }
 
+static void ad7124_clk_disable(void *c)
+{
+	clk_disable_unprepare(c);
+}
+
+static void ad7124_buffer_cleanup(void *idev)
+{
+	ad_sd_cleanup_buffer_and_trigger(idev);
+}
+
 static int ad7124_probe(struct spi_device *spi)
 {
 	const struct ad7124_chip_info *info;
@@ -740,8 +750,6 @@ static int ad7124_probe(struct spi_device *spi)
 
 	ad_sd_init(&st->sd, indio_dev, spi, &ad7124_sigma_delta_info);
 
-	spi_set_drvdata(spi, indio_dev);
-
 	indio_dev->name = st->chip_info->name;
 	indio_dev->modes = INDIO_DIRECT_MODE;
 	indio_dev->info = &ad7124_info;
@@ -779,48 +787,36 @@ static int ad7124_probe(struct spi_device *spi)
 	if (ret < 0)
 		return ret;
 
+	ret = devm_add_action_or_reset(&spi->dev, ad7124_clk_disable, st->mclk);
+	if (ret)
+		return ret;
+
 	ret = ad7124_soft_reset(st);
 	if (ret < 0)
-		goto error_clk_disable_unprepare;
+		return ret;
 
 	ret = ad7124_check_chip_id(st);
 	if (ret)
-		goto error_clk_disable_unprepare;
+		return ret;
 
 	ret = ad7124_setup(st);
 	if (ret < 0)
-		goto error_clk_disable_unprepare;
+		return ret;
 
 	ret = ad_sd_setup_buffer_and_trigger(indio_dev);
 	if (ret < 0)
-		goto error_clk_disable_unprepare;
-
-	ret = iio_device_register(indio_dev);
-	if (ret < 0) {
-		dev_err(&spi->dev, "Failed to register iio device\n");
-		goto error_remove_trigger;
-	}
+		return ret;
 
-	return 0;
+	ret = devm_add_action_or_reset(&spi->dev, ad7124_buffer_cleanup, indio_dev);
+	if (ret)
+		return ret;
 
-error_remove_trigger:
-	ad_sd_cleanup_buffer_and_trigger(indio_dev);
-error_clk_disable_unprepare:
-	clk_disable_unprepare(st->mclk);
+	ret = devm_iio_device_register(&spi->dev, indio_dev);
+	if (ret)
+		dev_err(&spi->dev, "Failed to register iio device\n");
 
 	return ret;
-}
 
-static int ad7124_remove(struct spi_device *spi)
-{
-	struct iio_dev *indio_dev = spi_get_drvdata(spi);
-	struct ad7124_state *st = iio_priv(indio_dev);
-
-	iio_device_unregister(indio_dev);
-	ad_sd_cleanup_buffer_and_trigger(indio_dev);
-	clk_disable_unprepare(st->mclk);
-
-	return 0;
 }
 
 static const struct of_device_id ad7124_of_match[] = {
@@ -838,7 +834,6 @@ static struct spi_driver ad71124_driver = {
 		.of_match_table = ad7124_of_match,
 	},
 	.probe = ad7124_probe,
-	.remove	= ad7124_remove,
 };
 module_spi_driver(ad71124_driver);
 
-- 
2.31.1


  parent reply	other threads:[~2021-05-08 18:24 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-08 18:23 [PATCH 0/3] iio: adc: ad7124: Fixes and devm_ for all of probe Jonathan Cameron
2021-05-08 18:23 ` [PATCH 1/3] iio: adc: ad7124: Fix missbalanced regulator enable / disable on error Jonathan Cameron
2021-05-09  7:20   ` Alexandru Ardelean
2021-05-08 18:23 ` [PATCH 2/3] iio: adc: ad7124: Fix potential overflow due to non sequential channel numbers Jonathan Cameron
2021-05-09  7:22   ` Alexandru Ardelean
2021-05-08 18:23 ` Jonathan Cameron [this message]
2021-05-09  7:30   ` [PATCH 3/3] iio: adc: ad7124: Use devm_ managed calls for all of probe() + drop remove() Alexandru Ardelean
2021-05-09  7:31 ` [PATCH 0/3] iio: adc: ad7124: Fixes and devm_ for all of probe Alexandru Ardelean
2021-05-09  9:35   ` 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=20210508182319.488551-4-jic23@kernel.org \
    --to=jic23@kernel.org \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=alexandru.tachici@analog.com \
    --cc=ardeleanalex@gmail.com \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --subject='Re: [PATCH 3/3] iio: adc: ad7124: Use devm_ managed calls for all of probe() + drop remove()' \
    /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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).