From: Jonathan Cameron <jic23@kernel.org>
To: Shi Hao <i.shihao.999@gmail.com>
Cc: dlechner@baylibre.com, andy@kernel.org,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] iio: accel: bma180: use devm_iio_triggered_buffer_setup()
Date: Sat, 21 Mar 2026 13:00:18 +0000 [thread overview]
Message-ID: <20260321130018.5ef955d1@jic23-huawei> (raw)
In-Reply-To: <20260321114848.159973-1-i.shihao.999@gmail.com>
On Sat, 21 Mar 2026 17:18:48 +0530
Shi Hao <i.shihao.999@gmail.com> wrote:
> Use devm_iio_triggered_buffer_setup() instead of
> iio_triggered_buffer_setup(). This removes the need for manual cleanup in
> both probe and remove callbacks, simplifying resource management.
This also changes the ordering so that the remove() path no longer
does things in the reverse order of probe()
Whilst that might not introduce bugs in this case, it makes reasoning
about race conditions much harder so I won't take code that does this.
The basic 'rule' for devm usage is that there must be only one transition
in the probe() from using it to not using it. You should never go back
to using it after that transition. That way the handling in remove()
and the unwinding of the devm_* happen in reverse order of probe()
and all is easy to reason about
So to make any devm_ related changes in this driver requires a
more comprehensive approach. Note that even if the change here didn't
suffer this ordering problem I'd be pushing back because of the partial
nature of applying devm in this driver. + a complete solution would
not run into the ordering issue.
Thanks
Jonathan
>
> Signed-off-by: Shi Hao <i.shihao.999@gmail.com>
> ---
> drivers/iio/accel/bma180.c | 7 ++-----
> 1 file changed, 2 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/iio/accel/bma180.c b/drivers/iio/accel/bma180.c
> index 7bc6761f5135..429d5a5c7672 100644
> --- a/drivers/iio/accel/bma180.c
> +++ b/drivers/iio/accel/bma180.c
> @@ -1004,7 +1004,7 @@ static int bma180_probe(struct i2c_client *client)
> indio_dev->trig = iio_trigger_get(data->trig);
> }
>
> - ret = iio_triggered_buffer_setup(indio_dev, NULL,
> + ret = devm_iio_triggered_buffer_setup(dev, indio_dev, NULL,
> bma180_trigger_handler, NULL);
> if (ret < 0) {
> dev_err(dev, "unable to setup iio triggered buffer\n");
> @@ -1014,13 +1014,11 @@ static int bma180_probe(struct i2c_client *client)
> ret = iio_device_register(indio_dev);
> if (ret < 0) {
> dev_err(dev, "unable to register iio device\n");
> - goto err_buffer_cleanup;
> + goto err_trigger_unregister;
> }
>
> return 0;
>
> -err_buffer_cleanup:
> - iio_triggered_buffer_cleanup(indio_dev);
> err_trigger_unregister:
> if (data->trig)
> iio_trigger_unregister(data->trig);
> @@ -1041,7 +1039,6 @@ static void bma180_remove(struct i2c_client *client)
> struct bma180_data *data = iio_priv(indio_dev);
>
> iio_device_unregister(indio_dev);
> - iio_triggered_buffer_cleanup(indio_dev);
> if (data->trig) {
> iio_trigger_unregister(data->trig);
> iio_trigger_free(data->trig);
> --
> 2.53.0
next prev parent reply other threads:[~2026-03-21 13:00 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-21 11:48 [PATCH] iio: accel: bma180: use devm_iio_triggered_buffer_setup() Shi Hao
2026-03-21 13:00 ` Jonathan Cameron [this message]
2026-03-28 11:19 ` ShiHao
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=20260321130018.5ef955d1@jic23-huawei \
--to=jic23@kernel.org \
--cc=andy@kernel.org \
--cc=dlechner@baylibre.com \
--cc=i.shihao.999@gmail.com \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/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