diff mbox series

[2/8] iio: adc: max11100: Use devm_ functions for rest of probe()

Message ID 20210516172520.1398835-3-jic23@kernel.org (mailing list archive)
State Accepted
Headers show
Series iio: adc: Maxim and TI ADC driver cleanups | expand

Commit Message

Jonathan Cameron May 16, 2021, 5:25 p.m. UTC
From: Jonathan Cameron <Jonathan.Cameron@huawei.com>

By using devm_add_action_or_reset() to manage the regulator disable,
it becomes simple to use managed functions for all of remove.
This simplifies error handling and allows us to drop the remove()
function entirely.

Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Cc: Jacopo Mondi <jacopo@jmondi.org>
---
 drivers/iio/adc/max11100.c | 29 +++++++++--------------------
 1 file changed, 9 insertions(+), 20 deletions(-)

Comments

Alexandru Ardelean May 17, 2021, 7:08 a.m. UTC | #1
On Sun, 16 May 2021 at 20:26, Jonathan Cameron <jic23@kernel.org> wrote:
>
> From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
>
> By using devm_add_action_or_reset() to manage the regulator disable,
> it becomes simple to use managed functions for all of remove.
> This simplifies error handling and allows us to drop the remove()
> function entirely.
>

Reviewed-by: Alexandru Ardelean <aardelean@deviqon.com>

> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> Cc: Jacopo Mondi <jacopo@jmondi.org>
> ---
>  drivers/iio/adc/max11100.c | 29 +++++++++--------------------
>  1 file changed, 9 insertions(+), 20 deletions(-)
>
> diff --git a/drivers/iio/adc/max11100.c b/drivers/iio/adc/max11100.c
> index 69d607fa17aa..9951f6a6a4b9 100644
> --- a/drivers/iio/adc/max11100.c
> +++ b/drivers/iio/adc/max11100.c
> @@ -102,6 +102,11 @@ static const struct iio_info max11100_info = {
>         .read_raw = max11100_read_raw,
>  };
>
> +static void max11100_regulator_disable(void *reg)
> +{
> +       regulator_disable(reg);
> +}
> +
>  static int max11100_probe(struct spi_device *spi)
>  {
>         int ret;
> @@ -131,27 +136,12 @@ static int max11100_probe(struct spi_device *spi)
>         if (ret)
>                 return ret;
>
> -       ret = iio_device_register(indio_dev);
> +       ret = devm_add_action_or_reset(&spi->dev, max11100_regulator_disable,
> +                               state->vref_reg);
>         if (ret)
> -               goto disable_regulator;
> -
> -       return 0;
> -
> -disable_regulator:
> -       regulator_disable(state->vref_reg);
> -
> -       return ret;
> -}
> -
> -static int max11100_remove(struct spi_device *spi)
> -{
> -       struct iio_dev *indio_dev = spi_get_drvdata(spi);
> -       struct max11100_state *state = iio_priv(indio_dev);
> -
> -       iio_device_unregister(indio_dev);
> -       regulator_disable(state->vref_reg);
> +               return ret;
>
> -       return 0;
> +       return devm_iio_device_register(&spi->dev, indio_dev);
>  }
>
>  static const struct of_device_id max11100_ids[] = {
> @@ -166,7 +156,6 @@ static struct spi_driver max11100_driver = {
>                 .of_match_table = max11100_ids,
>         },
>         .probe          = max11100_probe,
> -       .remove         = max11100_remove,
>  };
>
>  module_spi_driver(max11100_driver);
> --
> 2.31.1
>
Alexandru Ardelean May 17, 2021, 7:22 a.m. UTC | #2
On Mon, 17 May 2021 at 10:08, Alexandru Ardelean <aardelean@deviqon.com> wrote:
>
> On Sun, 16 May 2021 at 20:26, Jonathan Cameron <jic23@kernel.org> wrote:
> >
> > From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> >
> > By using devm_add_action_or_reset() to manage the regulator disable,
> > it becomes simple to use managed functions for all of remove.
> > This simplifies error handling and allows us to drop the remove()
> > function entirely.
> >
>

Apologies to come back on this.
But "spi_set_drvdata(spi, indio_dev);"  can be removed in this patch.
And while at it, the "state->vref_reg" parameter can be indented a bit.

> Reviewed-by: Alexandru Ardelean <aardelean@deviqon.com>
>
> > Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> > Cc: Jacopo Mondi <jacopo@jmondi.org>
> > ---
> >  drivers/iio/adc/max11100.c | 29 +++++++++--------------------
> >  1 file changed, 9 insertions(+), 20 deletions(-)
> >
> > diff --git a/drivers/iio/adc/max11100.c b/drivers/iio/adc/max11100.c
> > index 69d607fa17aa..9951f6a6a4b9 100644
> > --- a/drivers/iio/adc/max11100.c
> > +++ b/drivers/iio/adc/max11100.c
> > @@ -102,6 +102,11 @@ static const struct iio_info max11100_info = {
> >         .read_raw = max11100_read_raw,
> >  };
> >
> > +static void max11100_regulator_disable(void *reg)
> > +{
> > +       regulator_disable(reg);
> > +}
> > +
> >  static int max11100_probe(struct spi_device *spi)
> >  {
> >         int ret;
> > @@ -131,27 +136,12 @@ static int max11100_probe(struct spi_device *spi)
> >         if (ret)
> >                 return ret;
> >
> > -       ret = iio_device_register(indio_dev);
> > +       ret = devm_add_action_or_reset(&spi->dev, max11100_regulator_disable,
> > +                               state->vref_reg);
> >         if (ret)
> > -               goto disable_regulator;
> > -
> > -       return 0;
> > -
> > -disable_regulator:
> > -       regulator_disable(state->vref_reg);
> > -
> > -       return ret;
> > -}
> > -
> > -static int max11100_remove(struct spi_device *spi)
> > -{
> > -       struct iio_dev *indio_dev = spi_get_drvdata(spi);
> > -       struct max11100_state *state = iio_priv(indio_dev);
> > -
> > -       iio_device_unregister(indio_dev);
> > -       regulator_disable(state->vref_reg);
> > +               return ret;
> >
> > -       return 0;
> > +       return devm_iio_device_register(&spi->dev, indio_dev);
> >  }
> >
> >  static const struct of_device_id max11100_ids[] = {
> > @@ -166,7 +156,6 @@ static struct spi_driver max11100_driver = {
> >                 .of_match_table = max11100_ids,
> >         },
> >         .probe          = max11100_probe,
> > -       .remove         = max11100_remove,
> >  };
> >
> >  module_spi_driver(max11100_driver);
> > --
> > 2.31.1
> >
diff mbox series

Patch

diff --git a/drivers/iio/adc/max11100.c b/drivers/iio/adc/max11100.c
index 69d607fa17aa..9951f6a6a4b9 100644
--- a/drivers/iio/adc/max11100.c
+++ b/drivers/iio/adc/max11100.c
@@ -102,6 +102,11 @@  static const struct iio_info max11100_info = {
 	.read_raw = max11100_read_raw,
 };
 
+static void max11100_regulator_disable(void *reg)
+{
+	regulator_disable(reg);
+}
+
 static int max11100_probe(struct spi_device *spi)
 {
 	int ret;
@@ -131,27 +136,12 @@  static int max11100_probe(struct spi_device *spi)
 	if (ret)
 		return ret;
 
-	ret = iio_device_register(indio_dev);
+	ret = devm_add_action_or_reset(&spi->dev, max11100_regulator_disable,
+				state->vref_reg);
 	if (ret)
-		goto disable_regulator;
-
-	return 0;
-
-disable_regulator:
-	regulator_disable(state->vref_reg);
-
-	return ret;
-}
-
-static int max11100_remove(struct spi_device *spi)
-{
-	struct iio_dev *indio_dev = spi_get_drvdata(spi);
-	struct max11100_state *state = iio_priv(indio_dev);
-
-	iio_device_unregister(indio_dev);
-	regulator_disable(state->vref_reg);
+		return ret;
 
-	return 0;
+	return devm_iio_device_register(&spi->dev, indio_dev);
 }
 
 static const struct of_device_id max11100_ids[] = {
@@ -166,7 +156,6 @@  static struct spi_driver max11100_driver = {
 		.of_match_table = max11100_ids,
 	},
 	.probe		= max11100_probe,
-	.remove		= max11100_remove,
 };
 
 module_spi_driver(max11100_driver);