* [PATCH] iio: accel: bma180: use devm_iio_triggered_buffer_setup()
@ 2026-03-21 11:48 Shi Hao
2026-03-21 13:00 ` Jonathan Cameron
0 siblings, 1 reply; 3+ messages in thread
From: Shi Hao @ 2026-03-21 11:48 UTC (permalink / raw)
To: jic23; +Cc: dlechner, andy, linux-iio, linux-kernel, i.shihao.999
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.
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
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] iio: accel: bma180: use devm_iio_triggered_buffer_setup()
2026-03-21 11:48 [PATCH] iio: accel: bma180: use devm_iio_triggered_buffer_setup() Shi Hao
@ 2026-03-21 13:00 ` Jonathan Cameron
2026-03-28 11:19 ` ShiHao
0 siblings, 1 reply; 3+ messages in thread
From: Jonathan Cameron @ 2026-03-21 13:00 UTC (permalink / raw)
To: Shi Hao; +Cc: dlechner, andy, linux-iio, linux-kernel
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
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] iio: accel: bma180: use devm_iio_triggered_buffer_setup()
2026-03-21 13:00 ` Jonathan Cameron
@ 2026-03-28 11:19 ` ShiHao
0 siblings, 0 replies; 3+ messages in thread
From: ShiHao @ 2026-03-28 11:19 UTC (permalink / raw)
To: Jonathan Cameron; +Cc: dlechner, andy, linux-iio, linux-kernel, i.shihao.999
On Sat, Mar 21, 2026 at 01:00:18PM +0000, Jonathan Cameron wrote:
> 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 for you review. I will make sure to remember it.
Best regards
Shihao
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-03-28 11:19 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-21 11:48 [PATCH] iio: accel: bma180: use devm_iio_triggered_buffer_setup() Shi Hao
2026-03-21 13:00 ` Jonathan Cameron
2026-03-28 11:19 ` ShiHao
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox