diff mbox series

[5.10,036/530] iio:adc:ad7476: Fix remove handling

Message ID 20210512144820.931257479@linuxfoundation.org
State Superseded
Headers show
Series None | expand

Commit Message

Greg KH May 12, 2021, 2:42 p.m. UTC
From: Jonathan Cameron <Jonathan.Cameron@huawei.com>


commit 6baee4bd63f5fdf1716f88e95c21a683e94fe30d upstream.

This driver was in an odd half way state between devm based cleanup
and manual cleanup (most of which was missing).
I would guess something went wrong with a rebase or similar.
Anyhow, this basically finishes the job as a precursor to improving
the regulator handling.

Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

Fixes: 4bb2b8f94ace3 ("iio: adc: ad7476: implement devm_add_action_or_reset")
Cc: Michael Hennerich <michael.hennerich@analog.com>
Reviewed-by: Alexandru Ardelean <ardeleanalex@gmail.com>

Cc: <Stable@vger.kernel.org>
Link: https://lore.kernel.org/r/20210401171759.318140-2-jic23@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 drivers/iio/adc/ad7476.c |   18 ++++--------------
 1 file changed, 4 insertions(+), 14 deletions(-)

Comments

Pavel Machek May 15, 2021, 7:52 p.m. UTC | #1
Hi!
> 

> commit 6baee4bd63f5fdf1716f88e95c21a683e94fe30d upstream.

> 

> This driver was in an odd half way state between devm based cleanup

> and manual cleanup (most of which was missing).

> I would guess something went wrong with a rebase or similar.

> Anyhow, this basically finishes the job as a precursor to improving

> the regulator handling.


I don't think this is correct:

> --- a/drivers/iio/adc/ad7476.c

> +++ b/drivers/iio/adc/ad7476.c

> @@ -316,25 +316,15 @@ static int ad7476_probe(struct spi_devic

>  	spi_message_init(&st->msg);

>  	spi_message_add_tail(&st->xfer, &st->msg);

>  

> -	ret = iio_triggered_buffer_setup(indio_dev, NULL,

> -			&ad7476_trigger_handler, NULL);

> +	ret = devm_iio_triggered_buffer_setup(&spi->dev, indio_dev, NULL,

> +					      &ad7476_trigger_handler, NULL);

>  	if (ret)

> -		goto error_disable_reg;

> +		return ret;

>  

>  	if (st->chip_info->reset)

>  		st->chip_info->reset(st);

>  

> -	ret = iio_device_register(indio_dev);

> -	if (ret)

> -		goto error_ring_unregister;

> -	return 0;

> -

> -error_ring_unregister:

> -	iio_triggered_buffer_cleanup(indio_dev);

> -error_disable_reg:

> -	regulator_disable(st->reg);

> -


Regulator_disable is now removed, but we still use regulator_enable,
and we still need to keep it balanced.

> -	return ret;

> +	return devm_iio_device_register(&spi->dev, indio_dev);

>  }


Best regards,
								Pavel

-- 
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Alexandru Ardelean May 16, 2021, 5:28 a.m. UTC | #2
On Sat, May 15, 2021 at 10:52 PM Pavel Machek <pavel@denx.de> wrote:
>

> Hi!

> >

> > commit 6baee4bd63f5fdf1716f88e95c21a683e94fe30d upstream.

> >

> > This driver was in an odd half way state between devm based cleanup

> > and manual cleanup (most of which was missing).

> > I would guess something went wrong with a rebase or similar.

> > Anyhow, this basically finishes the job as a precursor to improving

> > the regulator handling.

>

> I don't think this is correct:

>

> > --- a/drivers/iio/adc/ad7476.c

> > +++ b/drivers/iio/adc/ad7476.c

> > @@ -316,25 +316,15 @@ static int ad7476_probe(struct spi_devic

> >       spi_message_init(&st->msg);

> >       spi_message_add_tail(&st->xfer, &st->msg);

> >

> > -     ret = iio_triggered_buffer_setup(indio_dev, NULL,

> > -                     &ad7476_trigger_handler, NULL);

> > +     ret = devm_iio_triggered_buffer_setup(&spi->dev, indio_dev, NULL,

> > +                                           &ad7476_trigger_handler, NULL);

> >       if (ret)

> > -             goto error_disable_reg;

> > +             return ret;

> >

> >       if (st->chip_info->reset)

> >               st->chip_info->reset(st);

> >

> > -     ret = iio_device_register(indio_dev);

> > -     if (ret)

> > -             goto error_ring_unregister;

> > -     return 0;

> > -

> > -error_ring_unregister:

> > -     iio_triggered_buffer_cleanup(indio_dev);

> > -error_disable_reg:

> > -     regulator_disable(st->reg);

> > -

>

> Regulator_disable is now removed, but we still use regulator_enable,

> and we still need to keep it balanced.


Yes, but that's what this block does:
    ret = devm_add_action_or_reset(&spi->dev, ad7476_reg_disable,
                       st);
    if (ret)
        return ret;

It registers a device-managed action to disable the regulator on error
or remove.
That ad7476_reg_disable() hook was implemented on commit:
4bb2b8f94ace3 ("iio: adc: ad7476: implement devm_add_action_or_reset")

But for some reason it wasn't done correctly, as this part [in this
patch] wasn't included in the 4bb2b8f94ace3  commit.

>

> > -     return ret;

> > +     return devm_iio_device_register(&spi->dev, indio_dev);

> >  }

>

> Best regards,

>                                                                 Pavel

>

> --

> DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk

> HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
diff mbox series

Patch

--- a/drivers/iio/adc/ad7476.c
+++ b/drivers/iio/adc/ad7476.c
@@ -316,25 +316,15 @@  static int ad7476_probe(struct spi_devic
 	spi_message_init(&st->msg);
 	spi_message_add_tail(&st->xfer, &st->msg);
 
-	ret = iio_triggered_buffer_setup(indio_dev, NULL,
-			&ad7476_trigger_handler, NULL);
+	ret = devm_iio_triggered_buffer_setup(&spi->dev, indio_dev, NULL,
+					      &ad7476_trigger_handler, NULL);
 	if (ret)
-		goto error_disable_reg;
+		return ret;
 
 	if (st->chip_info->reset)
 		st->chip_info->reset(st);
 
-	ret = iio_device_register(indio_dev);
-	if (ret)
-		goto error_ring_unregister;
-	return 0;
-
-error_ring_unregister:
-	iio_triggered_buffer_cleanup(indio_dev);
-error_disable_reg:
-	regulator_disable(st->reg);
-
-	return ret;
+	return devm_iio_device_register(&spi->dev, indio_dev);
 }
 
 static const struct spi_device_id ad7476_id[] = {