All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] iio: adc: ad7887: convert probe to device-managed functions
@ 2020-11-13  9:16 Alexandru Ardelean
  2020-11-14 16:45 ` Jonathan Cameron
  0 siblings, 1 reply; 2+ messages in thread
From: Alexandru Ardelean @ 2020-11-13  9:16 UTC (permalink / raw)
  To: linux-iio, linux-kernel; +Cc: jic23, Alexandru Ardelean

This is conversion of the driver to use device-managed functions.
The IIO registration and triggered buffer setup both have device-managed
versions.
The regulator disable needs to be handled via an action_or_reset handler.

With these changes, the remove hook is removed, and the error path is
cleaned up in probe.

Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
---
 drivers/iio/adc/ad7887.c | 43 ++++++++++++++--------------------------
 1 file changed, 15 insertions(+), 28 deletions(-)

diff --git a/drivers/iio/adc/ad7887.c b/drivers/iio/adc/ad7887.c
index 99a480ad3985..4f6f0e0e03ee 100644
--- a/drivers/iio/adc/ad7887.c
+++ b/drivers/iio/adc/ad7887.c
@@ -232,6 +232,13 @@ static const struct iio_info ad7887_info = {
 	.read_raw = &ad7887_read_raw,
 };
 
+static void ad7887_reg_disable(void *data)
+{
+	struct regulator *reg = data;
+
+	regulator_disable(reg);
+}
+
 static int ad7887_probe(struct spi_device *spi)
 {
 	struct ad7887_platform_data *pdata = spi->dev.platform_data;
@@ -258,6 +265,10 @@ static int ad7887_probe(struct spi_device *spi)
 		ret = regulator_enable(st->reg);
 		if (ret)
 			return ret;
+
+		ret = devm_add_action_or_reset(&spi->dev, ad7887_reg_disable, st->reg);
+		if (ret)
+			return ret;
 	}
 
 	st->chip_info =
@@ -316,36 +327,13 @@ static int ad7887_probe(struct spi_device *spi)
 		indio_dev->num_channels = st->chip_info->num_channels;
 	}
 
-	ret = iio_triggered_buffer_setup(indio_dev, &iio_pollfunc_store_time,
+	ret = devm_iio_triggered_buffer_setup(&spi->dev, indio_dev,
+			&iio_pollfunc_store_time,
 			&ad7887_trigger_handler, &ad7887_ring_setup_ops);
 	if (ret)
-		goto error_disable_reg;
-
-	ret = iio_device_register(indio_dev);
-	if (ret)
-		goto error_unregister_ring;
-
-	return 0;
-error_unregister_ring:
-	iio_triggered_buffer_cleanup(indio_dev);
-error_disable_reg:
-	if (st->reg)
-		regulator_disable(st->reg);
-
-	return ret;
-}
-
-static int ad7887_remove(struct spi_device *spi)
-{
-	struct iio_dev *indio_dev = spi_get_drvdata(spi);
-	struct ad7887_state *st = iio_priv(indio_dev);
-
-	iio_device_unregister(indio_dev);
-	iio_triggered_buffer_cleanup(indio_dev);
-	if (st->reg)
-		regulator_disable(st->reg);
+		return ret;
 
-	return 0;
+	return devm_iio_device_register(&spi->dev, indio_dev);
 }
 
 static const struct spi_device_id ad7887_id[] = {
@@ -359,7 +347,6 @@ static struct spi_driver ad7887_driver = {
 		.name	= "ad7887",
 	},
 	.probe		= ad7887_probe,
-	.remove		= ad7887_remove,
 	.id_table	= ad7887_id,
 };
 module_spi_driver(ad7887_driver);
-- 
2.27.0


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

* Re: [PATCH] iio: adc: ad7887: convert probe to device-managed functions
  2020-11-13  9:16 [PATCH] iio: adc: ad7887: convert probe to device-managed functions Alexandru Ardelean
@ 2020-11-14 16:45 ` Jonathan Cameron
  0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Cameron @ 2020-11-14 16:45 UTC (permalink / raw)
  To: Alexandru Ardelean; +Cc: linux-iio, linux-kernel

On Fri, 13 Nov 2020 11:16:48 +0200
Alexandru Ardelean <alexandru.ardelean@analog.com> wrote:

> This is conversion of the driver to use device-managed functions.
> The IIO registration and triggered buffer setup both have device-managed
> versions.
> The regulator disable needs to be handled via an action_or_reset handler.
> 
> With these changes, the remove hook is removed, and the error path is
> cleaned up in probe.
> 
> Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
Applied.

Thanks,

Jonathan

> ---
>  drivers/iio/adc/ad7887.c | 43 ++++++++++++++--------------------------
>  1 file changed, 15 insertions(+), 28 deletions(-)
> 
> diff --git a/drivers/iio/adc/ad7887.c b/drivers/iio/adc/ad7887.c
> index 99a480ad3985..4f6f0e0e03ee 100644
> --- a/drivers/iio/adc/ad7887.c
> +++ b/drivers/iio/adc/ad7887.c
> @@ -232,6 +232,13 @@ static const struct iio_info ad7887_info = {
>  	.read_raw = &ad7887_read_raw,
>  };
>  
> +static void ad7887_reg_disable(void *data)
> +{
> +	struct regulator *reg = data;
> +
> +	regulator_disable(reg);
> +}
> +
>  static int ad7887_probe(struct spi_device *spi)
>  {
>  	struct ad7887_platform_data *pdata = spi->dev.platform_data;
> @@ -258,6 +265,10 @@ static int ad7887_probe(struct spi_device *spi)
>  		ret = regulator_enable(st->reg);
>  		if (ret)
>  			return ret;
> +
> +		ret = devm_add_action_or_reset(&spi->dev, ad7887_reg_disable, st->reg);
> +		if (ret)
> +			return ret;
>  	}
>  
>  	st->chip_info =
> @@ -316,36 +327,13 @@ static int ad7887_probe(struct spi_device *spi)
>  		indio_dev->num_channels = st->chip_info->num_channels;
>  	}
>  
> -	ret = iio_triggered_buffer_setup(indio_dev, &iio_pollfunc_store_time,
> +	ret = devm_iio_triggered_buffer_setup(&spi->dev, indio_dev,
> +			&iio_pollfunc_store_time,
>  			&ad7887_trigger_handler, &ad7887_ring_setup_ops);
>  	if (ret)
> -		goto error_disable_reg;
> -
> -	ret = iio_device_register(indio_dev);
> -	if (ret)
> -		goto error_unregister_ring;
> -
> -	return 0;
> -error_unregister_ring:
> -	iio_triggered_buffer_cleanup(indio_dev);
> -error_disable_reg:
> -	if (st->reg)
> -		regulator_disable(st->reg);
> -
> -	return ret;
> -}
> -
> -static int ad7887_remove(struct spi_device *spi)
> -{
> -	struct iio_dev *indio_dev = spi_get_drvdata(spi);
> -	struct ad7887_state *st = iio_priv(indio_dev);
> -
> -	iio_device_unregister(indio_dev);
> -	iio_triggered_buffer_cleanup(indio_dev);
> -	if (st->reg)
> -		regulator_disable(st->reg);
> +		return ret;
>  
> -	return 0;
> +	return devm_iio_device_register(&spi->dev, indio_dev);
>  }
>  
>  static const struct spi_device_id ad7887_id[] = {
> @@ -359,7 +347,6 @@ static struct spi_driver ad7887_driver = {
>  		.name	= "ad7887",
>  	},
>  	.probe		= ad7887_probe,
> -	.remove		= ad7887_remove,
>  	.id_table	= ad7887_id,
>  };
>  module_spi_driver(ad7887_driver);


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

end of thread, other threads:[~2020-11-14 16:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-13  9:16 [PATCH] iio: adc: ad7887: convert probe to device-managed functions Alexandru Ardelean
2020-11-14 16:45 ` Jonathan Cameron

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.