iio: proximity: pulsedlight: fix iio_device left registered on PM setup failure
PATCH 1/1 iio: proximity: pulsedlight: fix iio_device left registered on PM setup failure
pm_runtime_set_active() failing in probe() jumps to error_unreg_buffer, which only calls iio_triggered_buffer_cleanup() -- it does not undo the iio_device_register() that already succeeded a few lines above. probe() then returns the error, the devm-managed indio_dev is freed, but the iio core still has it registered: the sysfs/chardev nodes stay live and point at freed memory.
Add an error_unreg_dev label that unregisters the iio device before falling through to the existing buffer cleanup, mirroring the teardown order already used in lidar_remove().
--- drivers/iio/proximity/pulsedlight-lidar-lite-v2.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/iio/proximity/pulsedlight-lidar-lite-v2.c +3 -1
@@ -294,12 +294,14 @@ static int lidar_probe(struct i2c_client *client) ret =pm_runtime_set_active (&client->dev);if (ret) - goto error_unreg_buffer; + goto error_unreg_dev;pm_runtime_enable (&client->dev);pm_runtime_idle (&client->dev);return 0 ; +error_unreg_dev: +iio_device_unregister (indio_dev); error_unreg_buffer:iio_triggered_buffer_cleanup (indio_dev);
Signature · 1 line
2.25.1
Quoted 23 lines · On Fri, 28 Aug 2026 17:59:09 +0700 Cong Nguyen <[email protected]> wrote:
pm_runtime_set_active()failing inprobe()jumps toerror_unreg_buffer, which only callsiio_triggered_buffer_cleanup()-- it does not undo theiio_device_register()that already succeeded a few lines above.probe()then returns the error, the devm-managedindio_devis freed, but the iio core still has it registered: the sysfs/chardev nodes stay live and point at freed memory.Add an
error_unreg_devlabel that unregisters the iio device before falling through to the existing buffer cleanup, mirroring the teardown order already used inlidar_remove().Fixes 4ac4e086fd8c ("iio: pulsedlight-lidar-lite: add runtime PM")Assisted-by Claude:claude-opus-4Signed-off-by Cong Nguyen <[email protected]>--- drivers/iio/proximity/pulsedlight-lidar-lite-v2.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/iio/proximity/pulsedlight-lidar-lite-v2.c +0
-0
drivers/iio/proximity/pulsedlight-lidar-lite-v2.c static int lidar_probe(struct i2c_client *client) · line 301
Quoted 9 lines
drivers/iio/proximity/pulsedlight-lidar-lite-v2.c +1
-1@@ -294,12 +294,14 @@ static int lidar_probe(struct i2c_client *client) ret =pm_runtime_set_active (&client->dev);if (ret) - goto error_unreg_buffer; + goto error_unreg_dev;pm_runtime_enable (&client->dev);pm_runtime_idle (&client->dev);return 0 ;
Hmm, you should just return iio_device_register() here instead of 0, as that should always be the last function called in any *_probe() function.
No need to add a new label then.
Quoted 5 lines
drivers/iio/proximity/pulsedlight-lidar-lite-v2.c +2
-0+error_unreg_dev: +iio_device_unregister (indio_dev); error_unreg_buffer:iio_triggered_buffer_cleanup (indio_dev);
Signature · 2 lines
Kind regards, Joshua Crofts
Jonathan Cameron
maintainerQuoted 34 lines · On Sat, 29 Aug 2026 18:34:43 +0200 Joshua Crofts <[email protected]>…
Quoted 31 lines · On Fri, 28 Aug 2026 17:59:09 +0700 Cong Nguyen <[email protected]> wrote:
pm_runtime_set_active()failing inprobe()jumps toerror_unreg_buffer, which only callsiio_triggered_buffer_cleanup()-- it does not undo theiio_device_register()that already succeeded a few lines above.probe()then returns the error, the devm-managedindio_devis freed, but the iio core still has it registered: the sysfs/chardev nodes stay live and point at freed memory.Add an
error_unreg_devlabel that unregisters the iio device before falling through to the existing buffer cleanup, mirroring the teardown order already used inlidar_remove().Fixes 4ac4e086fd8c ("iio: pulsedlight-lidar-lite: add runtime PM")Assisted-by Claude:claude-opus-4Signed-off-by Cong Nguyen <[email protected]>--- drivers/iio/proximity/pulsedlight-lidar-lite-v2.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/iio/proximity/pulsedlight-lidar-lite-v2.c +1
-1@@ -294,12 +294,14 @@ static int lidar_probe(struct i2c_client *client) ret =pm_runtime_set_active (&client->dev);if (ret) - goto error_unreg_buffer; + goto error_unreg_dev;pm_runtime_enable (&client->dev);pm_runtime_idle (&client->dev);
Quoted 7 lines
drivers/iio/proximity/pulsedlight-lidar-lite-v2.c static int lidar_probe(struct i2c_client *client) · line 301
Quoted 1 line
drivers/iio/proximity/pulsedlight-lidar-lite-v2.c +0
-0return 0 ;Hmm, you should just return
iio_device_register()here instead of 0, as that should always be the last function called in any*_probe()function.No need to add a new label then.
Lets keep this fix minimal. Agreed that it gets interesting if runtime pm is enabled only after the userspace interfaces are exposed, but we'd need to find if there is actual bug to 'fix' it as opposed to moving to a easier to understand flow.
So applied this one to the fixes-togreg branch of iio.git
Thanks,
Jonathan
Quoted 7 lines
Quoted 6 lines
drivers/iio/proximity/pulsedlight-lidar-lite-v2.c +2
-0+error_unreg_dev: +iio_device_unregister (indio_dev); error_unreg_buffer:iio_triggered_buffer_cleanup (indio_dev);