linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Popa <stefan.popa@analog.com>
To: <jic23@kernel.org>, <robh+dt@kernel.org>, <mark.rutland@arm.com>
Cc: Stefan Popa <stefan.popa@analog.com>,
	<Michael.Hennerich@analog.com>, <knaack.h@gmx.de>,
	<lars@metafoo.de>, <pmeerw@pmeerw.net>,
	<gregkh@linuxfoundation.org>, <linux-kernel@vger.kernel.org>,
	<linux-iio@vger.kernel.org>, <devel@driverdev.osuosl.org>,
	<stefan.popa@analog.co>
Subject: [PATCH 04/11] staging: iio: adc: ad7606: Use devm functions in probe
Date: Thu, 13 Dec 2018 14:46:16 +0200	[thread overview]
Message-ID: <1544705183-13288-5-git-send-email-stefan.popa@analog.com> (raw)
In-Reply-To: <1544705183-13288-1-git-send-email-stefan.popa@analog.com>

Switch to devm version of request_irq, iio_triggered_buffer_setup,
iio_device_register. To avoid potential ordering issues in probe,
devm_add_action_or_reset() is used for the regulator_disable(). This
simplifies the code and decreases the chance of bugs.

Signed-off-by: Stefan Popa <stefan.popa@analog.com>
---
 drivers/staging/iio/adc/ad7606.c     | 59 +++++++++++++-----------------------
 drivers/staging/iio/adc/ad7606.h     |  1 -
 drivers/staging/iio/adc/ad7606_par.c |  6 ----
 drivers/staging/iio/adc/ad7606_spi.c |  6 ----
 4 files changed, 21 insertions(+), 51 deletions(-)

diff --git a/drivers/staging/iio/adc/ad7606.c b/drivers/staging/iio/adc/ad7606.c
index 4b1bc20..7191d51 100644
--- a/drivers/staging/iio/adc/ad7606.c
+++ b/drivers/staging/iio/adc/ad7606.c
@@ -417,6 +417,13 @@ static const struct iio_info ad7606_info_range = {
 	.attrs = &ad7606_attribute_group_range,
 };
 
+static void ad7606_regulator_disable(void *data)
+{
+	struct ad7606_state *st = data;
+
+	regulator_disable(st->reg);
+}
+
 int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
 		 const char *name, unsigned int id,
 		 const struct ad7606_bus_ops *bops)
@@ -430,6 +437,7 @@ int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
 		return -ENOMEM;
 
 	st = iio_priv(indio_dev);
+	dev_set_drvdata(dev, indio_dev);
 
 	st->dev = dev;
 	mutex_init(&st->lock);
@@ -450,11 +458,15 @@ int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
 		return ret;
 	}
 
+	ret = devm_add_action_or_reset(dev, ad7606_regulator_disable, st);
+	if (ret)
+		return ret;
+
 	st->chip_info = &ad7606_chip_info_tbl[id];
 
 	ret = ad7606_request_gpios(st);
 	if (ret)
-		goto error_disable_reg;
+		return ret;
 
 	indio_dev->dev.parent = dev;
 	if (st->gpio_os) {
@@ -479,50 +491,21 @@ int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
 	if (ret)
 		dev_warn(st->dev, "failed to RESET: no RESET GPIO specified\n");
 
-	ret = request_irq(irq, ad7606_interrupt, IRQF_TRIGGER_FALLING, name,
-			  indio_dev);
-	if (ret)
-		goto error_disable_reg;
-
-	ret = iio_triggered_buffer_setup(indio_dev, &ad7606_trigger_handler,
-					 NULL, NULL);
+	ret = devm_request_irq(dev, irq, ad7606_interrupt, IRQF_TRIGGER_FALLING,
+			       name, indio_dev);
 	if (ret)
-		goto error_free_irq;
+		return ret;
 
-	ret = iio_device_register(indio_dev);
+	ret = devm_iio_triggered_buffer_setup(dev, indio_dev,
+					      &ad7606_trigger_handler,
+					      NULL, NULL);
 	if (ret)
-		goto error_unregister_ring;
-
-	dev_set_drvdata(dev, indio_dev);
-
-	return 0;
-error_unregister_ring:
-	iio_triggered_buffer_cleanup(indio_dev);
-
-error_free_irq:
-	free_irq(irq, indio_dev);
+		return ret;
 
-error_disable_reg:
-	regulator_disable(st->reg);
-	return ret;
+	return devm_iio_device_register(dev, indio_dev);
 }
 EXPORT_SYMBOL_GPL(ad7606_probe);
 
-int ad7606_remove(struct device *dev, int irq)
-{
-	struct iio_dev *indio_dev = dev_get_drvdata(dev);
-	struct ad7606_state *st = iio_priv(indio_dev);
-
-	iio_device_unregister(indio_dev);
-	iio_triggered_buffer_cleanup(indio_dev);
-
-	free_irq(irq, indio_dev);
-	regulator_disable(st->reg);
-
-	return 0;
-}
-EXPORT_SYMBOL_GPL(ad7606_remove);
-
 #ifdef CONFIG_PM_SLEEP
 
 static int ad7606_suspend(struct device *dev)
diff --git a/drivers/staging/iio/adc/ad7606.h b/drivers/staging/iio/adc/ad7606.h
index cf20ca2..70486ef 100644
--- a/drivers/staging/iio/adc/ad7606.h
+++ b/drivers/staging/iio/adc/ad7606.h
@@ -84,7 +84,6 @@ struct ad7606_bus_ops {
 int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
 		 const char *name, unsigned int id,
 		 const struct ad7606_bus_ops *bops);
-int ad7606_remove(struct device *dev, int irq);
 
 enum ad7606_supported_device_ids {
 	ID_AD7605_4,
diff --git a/drivers/staging/iio/adc/ad7606_par.c b/drivers/staging/iio/adc/ad7606_par.c
index db2fede46..6269ee7 100644
--- a/drivers/staging/iio/adc/ad7606_par.c
+++ b/drivers/staging/iio/adc/ad7606_par.c
@@ -71,11 +71,6 @@ static int ad7606_par_probe(struct platform_device *pdev)
 			    &ad7606_par8_bops);
 }
 
-static int ad7606_par_remove(struct platform_device *pdev)
-{
-	return ad7606_remove(&pdev->dev, platform_get_irq(pdev, 0));
-}
-
 static const struct platform_device_id ad7606_driver_ids[] = {
 	{
 		.name		= "ad7605-4",
@@ -97,7 +92,6 @@ MODULE_DEVICE_TABLE(platform, ad7606_driver_ids);
 
 static struct platform_driver ad7606_driver = {
 	.probe = ad7606_par_probe,
-	.remove	= ad7606_par_remove,
 	.id_table = ad7606_driver_ids,
 	.driver = {
 		.name	 = "ad7606",
diff --git a/drivers/staging/iio/adc/ad7606_spi.c b/drivers/staging/iio/adc/ad7606_spi.c
index b6553ce..9291598 100644
--- a/drivers/staging/iio/adc/ad7606_spi.c
+++ b/drivers/staging/iio/adc/ad7606_spi.c
@@ -48,11 +48,6 @@ static int ad7606_spi_probe(struct spi_device *spi)
 			    &ad7606_spi_bops);
 }
 
-static int ad7606_spi_remove(struct spi_device *spi)
-{
-	return ad7606_remove(&spi->dev, spi->irq);
-}
-
 static const struct spi_device_id ad7606_id[] = {
 	{"ad7605-4", ID_AD7605_4},
 	{"ad7606-8", ID_AD7606_8},
@@ -68,7 +63,6 @@ static struct spi_driver ad7606_driver = {
 		.pm = AD7606_PM_OPS,
 	},
 	.probe = ad7606_spi_probe,
-	.remove = ad7606_spi_remove,
 	.id_table = ad7606_id,
 };
 module_spi_driver(ad7606_driver);
-- 
2.7.4


  parent reply	other threads:[~2018-12-13 12:47 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-13 12:46 [PATCH 00/11] staging: iio: ad7606: Move out of staging Stefan Popa
2018-12-13 12:46 ` [PATCH 01/11] staging: iio: adc: ad7606: Simplify the Kconfing menu Stefan Popa
2018-12-13 15:37   ` Rob Herring
2018-12-13 12:46 ` [PATCH 02/11] staging: iio: adc: ad7606: Use SPDX identifier Stefan Popa
2018-12-13 13:21   ` Dan Carpenter
2018-12-13 12:46 ` [PATCH 03/11] staging: iio: adc: ad7606: Use wait-for-completion handler Stefan Popa
2018-12-16 13:41   ` Jonathan Cameron
2018-12-13 12:46 ` Stefan Popa [this message]
2018-12-16 13:43   ` [PATCH 04/11] staging: iio: adc: ad7606: Use devm functions in probe Jonathan Cameron
2018-12-13 12:46 ` [PATCH 05/11] staging: iio: adc: ad7606: Add support for threaded irq Stefan Popa
2018-12-13 13:28   ` Dan Carpenter
2018-12-16 13:49   ` Jonathan Cameron
2018-12-17 10:28     ` Popa, Stefan Serban
2018-12-13 12:46 ` [PATCH 06/11] staging: iio: adc: ad7606: Use find_closest() macro Stefan Popa
2018-12-16 13:51   ` Jonathan Cameron
2018-12-13 12:46 ` [PATCH 07/11] staging: iio: adc: ad7606: Use vendor prefix for DT properties Stefan Popa
2018-12-16 13:53   ` Jonathan Cameron
2018-12-13 12:46 ` [PATCH 08/11] staging: iio: adc: ad7606: Add OF device ID table Stefan Popa
2018-12-16 13:54   ` Jonathan Cameron
2018-12-13 12:46 ` [PATCH 09/11] staging: iio: adc: ad7606: Misc style fixes (no functional change) Stefan Popa
2018-12-16 13:56   ` Jonathan Cameron
2018-12-13 12:46 ` [PATCH 10/11] staging: iio: adc: ad7606: Move out of staging Stefan Popa
2018-12-16 14:14   ` Jonathan Cameron
2018-12-20 19:45   ` kbuild test robot
2018-12-13 12:46 ` [PATCH 11/11] dt-bindings: iio: adc: Add docs for AD7606 ADC Stefan Popa
2018-12-16 13:58   ` 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=1544705183-13288-5-git-send-email-stefan.popa@analog.com \
    --to=stefan.popa@analog.com \
    --cc=Michael.Hennerich@analog.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jic23@kernel.org \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=pmeerw@pmeerw.net \
    --cc=robh+dt@kernel.org \
    --cc=stefan.popa@analog.co \
    /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;
as well as URLs for NNTP newsgroup(s).