From: Jonathan Cameron <jic23@kernel.org>
To: Archit Anant <architanant5@gmail.com>
Cc: lars@metafoo.de, Michael.Hennerich@analog.com,
dlechner@baylibre.com, nuno.sa@analog.com, andy@kernel.org,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] iio: adc: ad799x: use devm_iio_device_register and devm buffer setup
Date: Sun, 1 Mar 2026 11:37:05 +0000 [thread overview]
Message-ID: <20260301113705.75b8224f@jic23-huawei> (raw)
In-Reply-To: <20260228154515.16639-1-architanant5@gmail.com>
On Sat, 28 Feb 2026 21:15:15 +0530
Archit Anant <architanant5@gmail.com> wrote:
> Convert the driver to use the device-managed versions of
> iio_device_register() and iio_triggered_buffer_setup().
>
> This simplifies the error handling in ad799x_probe() by removing the
> 'error_cleanup_ring' goto label. It also removes the need to manually
> call iio_device_unregister() and iio_triggered_buffer_cleanup() in
> ad799x_remove().
It's also unfortunately broken. There is a simple rule of thumb for
use of devm. It must be used for 'everything' up to the point in probe()
where you decide to stop using it. After that it cannot be used
at all.
The reason is that everything in the remove() callback occurs before the
unwinding of devm actions. Thus if you mix and match, you get ordering
problems.
In this case you turn the power off before removing the user space
interfaces which is going to be rather unexpected if someone is still
using those interfaces.
Jonathan
>
> Signed-off-by: Archit Anant <architanant5@gmail.com>
> ---
> drivers/iio/adc/ad799x.c | 13 ++++---------
> 1 file changed, 4 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/iio/adc/ad799x.c b/drivers/iio/adc/ad799x.c
> index 108bb22162ef..42712372acdb 100644
> --- a/drivers/iio/adc/ad799x.c
> +++ b/drivers/iio/adc/ad799x.c
> @@ -847,7 +847,7 @@ static int ad799x_probe(struct i2c_client *client)
> if (ret)
> goto error_disable_vref;
>
> - ret = iio_triggered_buffer_setup(indio_dev, NULL,
> + ret = devm_iio_triggered_buffer_setup(&client->dev, indio_dev, NULL,
> &ad799x_trigger_handler, NULL);
> if (ret)
> goto error_disable_vref;
> @@ -862,19 +862,17 @@ static int ad799x_probe(struct i2c_client *client)
> client->name,
> indio_dev);
> if (ret)
> - goto error_cleanup_ring;
> + goto error_disable_vref;
> }
>
> mutex_init(&st->lock);
>
> - ret = iio_device_register(indio_dev);
> + ret = devm_iio_device_register(&client->dev, indio_dev);
> if (ret)
> - goto error_cleanup_ring;
> + goto error_disable_vref;
>
> return 0;
>
> -error_cleanup_ring:
> - iio_triggered_buffer_cleanup(indio_dev);
> error_disable_vref:
> if (st->vref)
> regulator_disable(st->vref);
> @@ -889,9 +887,6 @@ static void ad799x_remove(struct i2c_client *client)
> struct iio_dev *indio_dev = i2c_get_clientdata(client);
> struct ad799x_state *st = iio_priv(indio_dev);
>
> - iio_device_unregister(indio_dev);
> -
> - iio_triggered_buffer_cleanup(indio_dev);
> if (st->vref)
> regulator_disable(st->vref);
> regulator_disable(st->reg);
prev parent reply other threads:[~2026-03-01 11:37 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-28 15:45 [PATCH] iio: adc: ad799x: use devm_iio_device_register and devm buffer setup Archit Anant
2026-02-28 16:36 ` David Lechner
2026-02-28 17:19 ` Archit Anant
2026-02-28 17:35 ` David Lechner
2026-03-01 11:34 ` Jonathan Cameron
2026-03-01 16:46 ` David Lechner
2026-03-01 11:37 ` Jonathan Cameron [this message]
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=20260301113705.75b8224f@jic23-huawei \
--to=jic23@kernel.org \
--cc=Michael.Hennerich@analog.com \
--cc=andy@kernel.org \
--cc=architanant5@gmail.com \
--cc=dlechner@baylibre.com \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nuno.sa@analog.com \
/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