Linux-IIO Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] iio: hi8435: Drop hi8435_remove()
@ 2019-08-11  5:45 Andrey Smirnov
  2019-08-11  9:00 ` Jonathan Cameron
  0 siblings, 1 reply; 2+ messages in thread
From: Andrey Smirnov @ 2019-08-11  5:45 UTC (permalink / raw)
  To: linux-iio; +Cc: Andrey Smirnov, linux-kernel, Jonathan Cameron, Chris Healy

Convert the remainder of hi8435_probe() to use devres and get rid of
hi8435_remove().

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
Cc: linux-kernel@vger.kernel.org
Cc: linux-iio@vger.kernel.org
Cc: Jonathan Cameron <jic23@kernel.org>
Cc: Chris Healy <cphealy@gmail.com>
---
 drivers/iio/adc/hi8435.c | 30 +++++++++++++-----------------
 1 file changed, 13 insertions(+), 17 deletions(-)

diff --git a/drivers/iio/adc/hi8435.c b/drivers/iio/adc/hi8435.c
index c15f0e154e4d..fe1341383d30 100644
--- a/drivers/iio/adc/hi8435.c
+++ b/drivers/iio/adc/hi8435.c
@@ -456,6 +456,11 @@ static irqreturn_t hi8435_trigger_handler(int irq, void *private)
 	return IRQ_HANDLED;
 }
 
+static void hi8435_triggered_event_cleanup(void *data)
+{
+	iio_triggered_event_cleanup(data);
+}
+
 static int hi8435_probe(struct spi_device *spi)
 {
 	struct iio_dev *idev;
@@ -513,26 +518,18 @@ static int hi8435_probe(struct spi_device *spi)
 	if (ret)
 		return ret;
 
-	ret = iio_device_register(idev);
+	ret = devm_add_action_or_reset(&spi->dev,
+				       hi8435_triggered_event_cleanup,
+				       idev);
+	if (ret)
+		return ret;
+
+	ret = devm_iio_device_register(&spi->dev, idev);
 	if (ret < 0) {
 		dev_err(&spi->dev, "unable to register device\n");
-		goto unregister_triggered_event;
+		return ret;
 	}
 
-	return 0;
-
-unregister_triggered_event:
-	iio_triggered_event_cleanup(idev);
-	return ret;
-}
-
-static int hi8435_remove(struct spi_device *spi)
-{
-	struct iio_dev *idev = spi_get_drvdata(spi);
-
-	iio_device_unregister(idev);
-	iio_triggered_event_cleanup(idev);
-
 	return 0;
 }
 
@@ -554,7 +551,6 @@ static struct spi_driver hi8435_driver = {
 		.of_match_table	= of_match_ptr(hi8435_dt_ids),
 	},
 	.probe		= hi8435_probe,
-	.remove		= hi8435_remove,
 	.id_table	= hi8435_id,
 };
 module_spi_driver(hi8435_driver);
-- 
2.21.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] iio: hi8435: Drop hi8435_remove()
  2019-08-11  5:45 [PATCH] iio: hi8435: Drop hi8435_remove() Andrey Smirnov
@ 2019-08-11  9:00 ` Jonathan Cameron
  0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Cameron @ 2019-08-11  9:00 UTC (permalink / raw)
  To: Andrey Smirnov
  Cc: linux-iio, linux-kernel, Chris Healy, Vladimir Barinov,
	Nikita Yushchenko

On Sat, 10 Aug 2019 22:45:45 -0700
Andrey Smirnov <andrew.smirnov@gmail.com> wrote:

> Convert the remainder of hi8435_probe() to use devres and get rid of
> hi8435_remove().
> 
> Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
> Cc: linux-kernel@vger.kernel.org
> Cc: linux-iio@vger.kernel.org
> Cc: Jonathan Cameron <jic23@kernel.org>
> Cc: Chris Healy <cphealy@gmail.com>
+CC as before.

I've tweaked things a little bit (see below)

Applied to the togreg branch of iio.git and pushed out as testing
for the autobuilders to play with it.

Still time for others to comment btw!

Thanks,

Jonathan

> ---
>  drivers/iio/adc/hi8435.c | 30 +++++++++++++-----------------
>  1 file changed, 13 insertions(+), 17 deletions(-)
> 
> diff --git a/drivers/iio/adc/hi8435.c b/drivers/iio/adc/hi8435.c
> index c15f0e154e4d..fe1341383d30 100644
> --- a/drivers/iio/adc/hi8435.c
> +++ b/drivers/iio/adc/hi8435.c
> @@ -456,6 +456,11 @@ static irqreturn_t hi8435_trigger_handler(int irq, void *private)
>  	return IRQ_HANDLED;
>  }
>  
> +static void hi8435_triggered_event_cleanup(void *data)
> +{
> +	iio_triggered_event_cleanup(data);
> +}

Hmm. I wonder if we should do a full devm_iio_triggered_event_setup()
but given we have very few callers that can be a job for another day.

> +
>  static int hi8435_probe(struct spi_device *spi)
>  {
>  	struct iio_dev *idev;
> @@ -513,26 +518,18 @@ static int hi8435_probe(struct spi_device *spi)
>  	if (ret)
>  		return ret;
>  
> -	ret = iio_device_register(idev);
> +	ret = devm_add_action_or_reset(&spi->dev,
> +				       hi8435_triggered_event_cleanup,
> +				       idev);
> +	if (ret)
> +		return ret;
> +
> +	ret = devm_iio_device_register(&spi->dev, idev);
>  	if (ret < 0) {
>  		dev_err(&spi->dev, "unable to register device\n");
> -		goto unregister_triggered_event;
> +		return ret;

We could tidy up a little more and do
	if (ret)
		dev_err...

	return ret;

Or, given all the likely paths in iio_device_register() have 
error prints anyway, can just do
	return devm_iio_device_register();

I'll change it to this last one whilst applying.

>  	}
>  
> -	return 0;
> -
> -unregister_triggered_event:
> -	iio_triggered_event_cleanup(idev);
> -	return ret;
> -}
> -
> -static int hi8435_remove(struct spi_device *spi)
> -{
> -	struct iio_dev *idev = spi_get_drvdata(spi);
> -
> -	iio_device_unregister(idev);
> -	iio_triggered_event_cleanup(idev);
> -
>  	return 0;
>  }
>  
> @@ -554,7 +551,6 @@ static struct spi_driver hi8435_driver = {
>  		.of_match_table	= of_match_ptr(hi8435_dt_ids),
>  	},
>  	.probe		= hi8435_probe,
> -	.remove		= hi8435_remove,
>  	.id_table	= hi8435_id,
>  };
>  module_spi_driver(hi8435_driver);


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-11  5:45 [PATCH] iio: hi8435: Drop hi8435_remove() Andrey Smirnov
2019-08-11  9:00 ` Jonathan Cameron

Linux-IIO Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-iio/0 linux-iio/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-iio linux-iio/ https://lore.kernel.org/linux-iio \
		linux-iio@vger.kernel.org linux-iio@archiver.kernel.org
	public-inbox-index linux-iio


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-iio


AGPL code for this site: git clone https://public-inbox.org/ public-inbox