iio: PM-enable leak on probe error path (goto-variant drivers)
cover iio: PM-enable leak on probe error path (goto-variant drivers)
This is the goto-variant follow-up to the standalone ti-ads1015 patch and the 4-patch series for the simple drivers. In these four drivers probe calls pm_runtime_enable() but the existing register-failure path jumps to a manual cleanup label (out_err / buffer_cleanup / error_power_down) rather than returning directly. None of those cleanup labels call pm_runtime_disable(), so the runtime PM enable_count leaks on probe failure and on subsequent rebind.
The conversion is the same as in the rest of the class: replace pm_runtime_enable() with devm_pm_runtime_enable() and drop the pm_runtime_disable() / pm_runtime_set_suspended() calls in .remove(). On the new error path from devm_pm_runtime_enable() each patch jumps to the same existing cleanup label that iio_device_register() uses, so the manual unwind for the non-devm resources held earlier in probe still runs. In apds9960 nothing is powered or registered at that point so a plain return is used.
Standalone precedent already on the list:
iio: adc: ti-ads1015 -
https://lore.kernel.org/all/[email protected]/
Companion 4-patch series for the simple-return drivers (isl29028, tsl2583, mlx90614, bmi088-accel) was posted alongside this one.
Stepan Ionichev (4):
iio: light: pa12203001: use devm_pm_runtime_enable() to fix probe
error path
iio: light: us5182d: use devm_pm_runtime_enable() to fix probe error
path
iio: light: apds9960: use devm_pm_runtime_enable() to fix probe error
path
iio: accel: mma8452: use devm_pm_runtime_enable() to fix probe error
path
drivers/iio/accel/mma8452.c | 7 +++---- drivers/iio/light/apds9960.c | 6 +++--- drivers/iio/light/pa12203001.c | 7 +++---- drivers/iio/light/us5182d.c | 7 +++---- 4 files changed, 12 insertions(+), 15 deletions(-)
base-commit: 7cb1c5b32a2bfde961fff8d5204526b609bcb30a
Signature · 1 line
2.43.0
PATCH 1/4 iio: light: pa12203001: use devm_pm_runtime_enable() to fix probe error path
pa12203001_probe() calls pm_runtime_enable() and then iio_device_register(). If iio_device_register() fails the function jumps to out_err but the existing out_err handler does not call pm_runtime_disable(), leaking the runtime PM enable_count on probe failure and on subsequent rebind.
Switch to devm_pm_runtime_enable() so the enable (and the matching dont_use_autosuspend) are torn down automatically. On its new error path the probe jumps to the existing out_err label so the chip-disable cleanup stays in step with the rest of the manual unwind. The pm_runtime_disable() and pm_runtime_set_suspended() calls in pa12203001_remove() are dropped; the devm action runs after .remove() and handles the teardown.
--- drivers/iio/light/pa12203001.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/iio/light/pa12203001.c +3 -4
@@ -372,7 +372,9 @@ static int pa12203001_probe(struct i2c_client *client)if (ret <0 ) goto out_err; -pm_runtime_enable (&client->dev); + ret =devm_pm_runtime_enable (&client->dev); +if (ret) + goto out_err;pm_runtime_set_autosuspend_delay (&client->dev,PA12203001_SLEEP_DELAY_MS );pm_runtime_use_autosuspend (&client->dev);
@@ -395,9 +397,6 @@ static void pa12203001_remove(struct i2c_client *client)iio_device_unregister (indio_dev); -pm_runtime_disable (&client->dev); -pm_runtime_set_suspended (&client->dev); - ret =pa12203001_power_chip (indio_dev,PA12203001_CHIP_DISABLE );if (ret) dev_warn(&client->dev, "Failed to power down (%pe)\n",
Signature · 1 line
2.43.0
Jonathan Cameron
maintainerRe: [PATCH 1/4] iio: light: pa12203001: use devm_pm_runtime_enable() to fix probe error path
Quoted 23 lines · On Fri, 29 May 2026 15:45:41 +0500 Stepan Ionichev <[email protected]> wrote:
pa12203001_probe()callspm_runtime_enable()and theniio_device_register(). Ifiio_device_register()fails the function jumps toout_errbut the existingout_errhandler does not callpm_runtime_disable(), leaking the runtime PMenable_counton probe failure and on subsequent rebind.Switch to
devm_pm_runtime_enable()so the enable (and the matchingdont_use_autosuspend) are torn down automatically. On its new error path the probe jumps to the existingout_errlabel so the chip-disable cleanup stays in step with the rest of the manual unwind. Thepm_runtime_disable()andpm_runtime_set_suspended()calls inpa12203001_remove()are dropped; the devm action runs after .remove() and handles the teardown.Signed-off-by Stepan Ionichev <[email protected]>--- drivers/iio/light/pa12203001.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)drivers/iio/light/pa12203001.c +0
-0
drivers/iio/light/pa12203001.c static int pa12203001_probe(struct i2c_client *client) · line 377
Quoted 7 lines
drivers/iio/light/pa12203001.c +3
-1@@ -372,7 +372,9 @@ static int pa12203001_probe(struct i2c_client *client)if (ret <0 ) goto out_err; -pm_runtime_enable (&client->dev); + ret =devm_pm_runtime_enable (&client->dev); +if (ret) + goto out_err;
A goto after a devm call is a big warning flag.
A quick look suggests easy enough to solve with a devm_add_action_or_reset(); Probably needs to be a precursor patch to this one.
Quoted 13 lines
drivers/iio/light/pa12203001.c +0
-3pm_runtime_set_autosuspend_delay (&client->dev,PA12203001_SLEEP_DELAY_MS );pm_runtime_use_autosuspend (&client->dev);@@ -395,9 +397,6 @@ static void pa12203001_remove(struct i2c_client *client)iio_device_unregister (indio_dev); -pm_runtime_disable (&client->dev); -pm_runtime_set_suspended (&client->dev); - ret =pa12203001_power_chip (indio_dev,PA12203001_CHIP_DISABLE );if (ret) dev_warn(&client->dev, "Failed to power down (%pe)\n",
PATCH 2/4 iio: light: us5182d: use devm_pm_runtime_enable() to fix probe error path
In reply to Stepan Ionichevus5182d_probe() calls pm_runtime_enable() and then iio_device_register(). If iio_device_register() fails the function jumps to out_err but the existing out_err handler does not call pm_runtime_disable(), leaking the runtime PM enable_count on probe failure and on subsequent rebind.
Switch to devm_pm_runtime_enable() so the enable (and the matching dont_use_autosuspend) are torn down automatically. On its new error path the probe jumps to the existing out_err label so the shutdown_en() cleanup stays in step with the rest of the manual unwind. The pm_runtime_disable() and pm_runtime_set_suspended() calls in us5182d_remove() are dropped; the devm action runs after .remove() and handles the teardown.
--- drivers/iio/light/us5182d.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/iio/light/us5182d.c +3 -4
@@ -880,7 +880,9 @@ static int us5182d_probe(struct i2c_client *client) goto out_err; } -pm_runtime_enable (&client->dev); + ret =devm_pm_runtime_enable (&client->dev); +if (ret) + goto out_err;pm_runtime_set_autosuspend_delay (&client->dev,US5182D_SLEEP_MS );pm_runtime_use_autosuspend (&client->dev);
@@ -904,9 +906,6 @@ static void us5182d_remove(struct i2c_client *client)iio_device_unregister (i2c_get_clientdata (client)); -pm_runtime_disable (&client->dev); -pm_runtime_set_suspended (&client->dev); - ret =us5182d_shutdown_en (data,US5182D_CFG0_SHUTDOWN_EN );if (ret) dev_warn(&client->dev, "Failed to shut down (%pe)\n",
Signature · 1 line
2.43.0
Jonathan Cameron
maintainerRe: [PATCH 2/4] iio: light: us5182d: use devm_pm_runtime_enable() to fix probe error path
Quoted 5 lines · On Fri, 29 May 2026 15:45:42 +0500 Stepan Ionichev <[email protected]> wrote:
us5182d_probe()callspm_runtime_enable()and theniio_device_register(). Ifiio_device_register()fails the function jumps toout_errbut the existingout_errhandler does not callpm_runtime_disable(), leaking the runtime PMenable_counton probe failure and on subsequent rebind.
Quoted 8 lines
Switch to
devm_pm_runtime_enable()so the enable (and the matchingdont_use_autosuspend) are torn down automatically. On its new error path the probe jumps to the existingout_errlabel so theshutdown_en()cleanup stays in step with the rest of the manual unwind. Thepm_runtime_disable()andpm_runtime_set_suspended()calls inus5182d_remove()are dropped; the devm action runs after .remove() and handles the teardown.Signed-off-by Stepan Ionichev <[email protected]>
Same a for patch 1. Needs more work so there is no goto.
Quoted 29 lines
--- drivers/iio/light/us5182d.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)drivers/iio/light/us5182d.c +3
-4@@ -880,7 +880,9 @@ static int us5182d_probe(struct i2c_client *client) goto out_err; } -pm_runtime_enable (&client->dev); + ret =devm_pm_runtime_enable (&client->dev); +if (ret) + goto out_err;pm_runtime_set_autosuspend_delay (&client->dev,US5182D_SLEEP_MS );pm_runtime_use_autosuspend (&client->dev);@@ -904,9 +906,6 @@ static void us5182d_remove(struct i2c_client *client)iio_device_unregister (i2c_get_clientdata (client)); -pm_runtime_disable (&client->dev); -pm_runtime_set_suspended (&client->dev); - ret =us5182d_shutdown_en (data,US5182D_CFG0_SHUTDOWN_EN );if (ret) dev_warn(&client->dev, "Failed to shut down (%pe)\n",
PATCH 3/4 iio: light: apds9960: use devm_pm_runtime_enable() to fix probe error path
In reply to Stepan Ionichevapds9960_probe() calls pm_runtime_enable() and then several operations that may fail through goto error_power_down, ending with iio_device_register(). None of those error paths call pm_runtime_disable(), so the runtime PM enable_count leaks on probe failure and on subsequent rebind.
Switch to devm_pm_runtime_enable() so the enable (and the matching dont_use_autosuspend) are torn down automatically. The probe error path on devm_pm_runtime_enable() itself is a plain return because no hardware has been powered on at that point. The pm_runtime_disable() and pm_runtime_set_suspended() calls in apds9960_remove() are dropped; the devm action runs after .remove() and handles the teardown.
--- drivers/iio/light/apds9960.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/iio/light/apds9960.c +3 -3
@@ -1074,7 +1074,9 @@ static int apds9960_probe(struct i2c_client *client)if (ret) goto error_power_down; -pm_runtime_enable (&client->dev); + ret =devm_pm_runtime_enable (&client->dev); +if (ret) +return ret;pm_runtime_set_autosuspend_delay (&client->dev,5000 );pm_runtime_use_autosuspend (&client->dev);
@@ -1123,8 +1125,6 @@ static void apds9960_remove(struct i2c_client *client)struct apds9960_data *data =iio_priv (indio_dev);iio_device_unregister (indio_dev); -pm_runtime_disable (&client->dev); -pm_runtime_set_suspended (&client->dev);apds9960_set_powermode (data,0 ); }
Signature · 1 line
2.43.0
Jonathan Cameron
maintainerRe: [PATCH 3/4] iio: light: apds9960: use devm_pm_runtime_enable() to fix probe error path
Quoted 23 lines · On Fri, 29 May 2026 15:45:43 +0500 Stepan Ionichev <[email protected]> wrote:
apds9960_probe()callspm_runtime_enable()and then several operations that may fail through gotoerror_power_down, ending withiio_device_register(). None of those error paths callpm_runtime_disable(), so the runtime PMenable_countleaks on probe failure and on subsequent rebind.Switch to
devm_pm_runtime_enable()so the enable (and the matchingdont_use_autosuspend) are torn down automatically. The probe error path ondevm_pm_runtime_enable()itself is a plain return because no hardware has been powered on at that point. Thepm_runtime_disable()andpm_runtime_set_suspended()calls inapds9960_remove()are dropped; the devm action runs after .remove() and handles the teardown.Signed-off-by Stepan Ionichev <[email protected]>--- drivers/iio/light/apds9960.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/iio/light/apds9960.c +0
-0
drivers/iio/light/apds9960.c static int apds9960_probe(struct i2c_client *client) · line 1079
Quoted 7 lines
drivers/iio/light/apds9960.c +3
-1@@ -1074,7 +1074,9 @@ static int apds9960_probe(struct i2c_client *client)if (ret) goto error_power_down; -pm_runtime_enable (&client->dev); + ret =devm_pm_runtime_enable (&client->dev); +if (ret) +return ret;
Leaves the power on. And resolving that would have the same issue as the previous two patches with being a mix of goto and devm cleanup.
Very strong advice on this is the moment anything at all needs to be in remove() you have to stop using devm for remaining calls and unwind them by hand.
Quoted 12 lines
drivers/iio/light/apds9960.c +0
-2pm_runtime_set_autosuspend_delay (&client->dev,5000 );pm_runtime_use_autosuspend (&client->dev);@@ -1123,8 +1125,6 @@ static void apds9960_remove(struct i2c_client *client)struct apds9960_data *data =iio_priv (indio_dev);iio_device_unregister (indio_dev); -pm_runtime_disable (&client->dev); -pm_runtime_set_suspended (&client->dev);apds9960_set_powermode (data,0 ); }
PATCH 4/4 iio: accel: mma8452: use devm_pm_runtime_enable() to fix probe error path
In reply to Stepan Ionichevmma8452_probe() calls pm_runtime_enable() and then iio_device_register(). If iio_device_register() fails the function jumps to buffer_cleanup but the existing manual unwind does not call pm_runtime_disable(), leaking the runtime PM enable_count on probe failure and on subsequent rebind.
Switch to devm_pm_runtime_enable() so the enable (and the matching dont_use_autosuspend) are torn down automatically. On its new error path the probe jumps to the existing buffer_cleanup label so the triggered buffer, trigger and regulator cleanup chain stays intact. The pm_runtime_disable() and pm_runtime_set_suspended() calls in mma8452_remove() are dropped; the devm action runs after .remove() and handles the teardown.
--- drivers/iio/accel/mma8452.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/iio/accel/mma8452.c +3 -4
@@ -1693,7 +1693,9 @@ static int mma8452_probe(struct i2c_client *client)if (ret <0 ) goto buffer_cleanup; -pm_runtime_enable (&client->dev); + ret =devm_pm_runtime_enable (&client->dev); +if (ret) + goto buffer_cleanup;pm_runtime_set_autosuspend_delay (&client->dev,MMA8452_AUTO_SUSPEND_DELAY_MS );pm_runtime_use_autosuspend (&client->dev);
@@ -1733,9 +1735,6 @@ static void mma8452_remove(struct i2c_client *client)iio_device_unregister (indio_dev); -pm_runtime_disable (&client->dev); -pm_runtime_set_suspended (&client->dev); -iio_triggered_buffer_cleanup (indio_dev);mma8452_trigger_cleanup (indio_dev);mma8452_standby (iio_priv (indio_dev));
Signature · 1 line
2.43.0
Jonathan Cameron
maintainerRe: [PATCH 4/4] iio: accel: mma8452: use devm_pm_runtime_enable() to fix probe error path
Quoted 13 lines · On Fri, 29 May 2026 15:45:44 +0500 Stepan Ionichev <[email protected]> wrote:
mma8452_probe()callspm_runtime_enable()and theniio_device_register(). Ifiio_device_register()fails the function jumps tobuffer_cleanupbut the existing manual unwind does not callpm_runtime_disable(), leaking the runtime PMenable_counton probe failure and on subsequent rebind.Switch to
devm_pm_runtime_enable()so the enable (and the matchingdont_use_autosuspend) are torn down automatically. On its new error path the probe jumps to the existingbuffer_cleanuplabel so the triggered buffer, trigger and regulator cleanup chain stays intact. Thepm_runtime_disable()andpm_runtime_set_suspended()calls inmma8452_remove()are dropped; the devm action runs after .remove() and handles the teardown.
Quoted 1 line
Signed-off-by Stepan Ionichev <[email protected]>
Same again on not mixing devm with goto.
Side effect here is that the tear down order is completely different from reverse of setup.
Quoted 29 lines
--- drivers/iio/accel/mma8452.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)drivers/iio/accel/mma8452.c +3
-4@@ -1693,7 +1693,9 @@ static int mma8452_probe(struct i2c_client *client)if (ret <0 ) goto buffer_cleanup; -pm_runtime_enable (&client->dev); + ret =devm_pm_runtime_enable (&client->dev); +if (ret) + goto buffer_cleanup;pm_runtime_set_autosuspend_delay (&client->dev,MMA8452_AUTO_SUSPEND_DELAY_MS );pm_runtime_use_autosuspend (&client->dev);@@ -1733,9 +1735,6 @@ static void mma8452_remove(struct i2c_client *client)iio_device_unregister (indio_dev); -pm_runtime_disable (&client->dev); -pm_runtime_set_suspended (&client->dev); -iio_triggered_buffer_cleanup (indio_dev);mma8452_trigger_cleanup (indio_dev);mma8452_standby (iio_priv (indio_dev));
Jonathan Cameron
maintainerQuoted 8 lines · On Fri, 29 May 2026 15:45:40 +0500 Stepan Ionichev <[email protected]> wrote:
This is the goto-variant follow-up to the standalone ti-ads1015 patch and the 4-patch series for the simple drivers. In these four drivers probe calls
pm_runtime_enable()but the existing register-failure path jumps to a manual cleanup label (out_err/buffer_cleanup/error_power_down) rather than returning directly. None of those cleanup labels callpm_runtime_disable(), so the runtime PMenable_countleaks on probe failure and on subsequent rebind.
Quoted 8 lines
The conversion is the same as in the rest of the class: replace
pm_runtime_enable()withdevm_pm_runtime_enable()and drop thepm_runtime_disable()/pm_runtime_set_suspended()calls in .remove(). On the new error path fromdevm_pm_runtime_enable()each patch jumps to the same existing cleanup label thatiio_device_register()uses, so the manual unwind for the non-devm resources held earlier in probe still runs. In apds9960 nothing is powered or registered at that point so a plain return is used.
This is v2. Make sure you increment version numbers even for the sort of commit message reformat you made here. Sending as the same version confuses readers and potentially scripts.
Note this is a clarification not a request that you resend now as v2! J
Quoted 26 lines
Standalone precedent already on the list:
iio: adc: ti-ads1015 -
https://lore.kernel.org/all/[email protected]/Companion 4-patch series for the simple-return drivers (isl29028, tsl2583, mlx90614, bmi088-accel) was posted alongside this one.
Stepan Ionichev (4):
iio: light: pa12203001: usedevm_pm_runtime_enable()to fix probe
error path
iio: light: us5182d: usedevm_pm_runtime_enable()to fix probe error
path
iio: light: apds9960: usedevm_pm_runtime_enable()to fix probe error
path
iio: accel: mma8452: usedevm_pm_runtime_enable()to fix probe error
pathdrivers/iio/accel/mma8452.c | 7 +++---- drivers/iio/light/apds9960.c | 6 +++--- drivers/iio/light/pa12203001.c | 7 +++---- drivers/iio/light/us5182d.c | 7 +++---- 4 files changed, 12 insertions(+), 15 deletions(-)base-commit:
7cb1c5b32a2bfde961fff8d5204526b609bcb30a