iio: fix PM-enable leak on probe error path across 4 drivers
Subsystems (2)
cover iio: fix PM-enable leak on probe error path across 4 drivers
This series fixes a class of runtime PM enable_count leaks on probe error paths across drivers/iio/.
Each affected driver calls pm_runtime_enable() in probe and then a non-devm registration function (typically iio_device_register()). When the registration fails the probe returns directly without calling pm_runtime_disable(); on subsequent probe/rebind the runtime PM tracking complains about an unbalanced enable.
The fix is the same in each driver: replace pm_runtime_enable() with devm_pm_runtime_enable() and drop the now-redundant pm_runtime_disable() and pm_runtime_set_suspended() calls in the .remove() callback. The devm action runs after .remove() and handles the teardown.
drivers/iio/adc/ti-ads1015.c was posted as a standalone patch earlier:
https://lore.kernel.org/all/[email protected]/
A separate follow-up will cover four more drivers (apds9960, mma8452, pa12203001, us5182d) where the same leak exists but the probe error path needs a goto to the existing manual cleanup label rather than a plain return.
Stepan Ionichev (4):
iio: light: isl29028: use devm_pm_runtime_enable() to fix probe error
path
iio: light: tsl2583: use devm_pm_runtime_enable() to fix probe error
path
iio: temperature: mlx90614: use devm_pm_runtime_enable() to fix probe
error path
iio: accel: bmi088-accel: use devm_pm_runtime_enable() to fix probe
error path
drivers/iio/accel/bmi088-accel-core.c | 6 +++--- drivers/iio/light/isl29028.c | 7 +++---- drivers/iio/light/tsl2583.c | 6 +++--- drivers/iio/temperature/mlx90614.c | 6 +++--- 4 files changed, 12 insertions(+), 13 deletions(-)
base-commit: 7cb1c5b32a2bfde961fff8d5204526b609bcb30a
Signature · 1 line
2.43.0
PATCH 1/4 iio: light: isl29028: use devm_pm_runtime_enable() to fix probe error path
isl29028_probe() calls pm_runtime_enable() before iio_device_register(). If iio_device_register() fails, the probe returns directly without calling pm_runtime_disable(), leaving the runtime PM enable_count unbalanced. On the next probe attempt the kernel logs "Unbalanced pm_runtime_enable".
Switch to devm_pm_runtime_enable() so the runtime PM state is unwound automatically on probe failure and on driver detach. Propagate its return value with a direct return on error.
With runtime PM now managed by devres, isl29028_remove() no longer needs to call pm_runtime_disable() and pm_runtime_set_suspended() explicitly; drop those two calls. The remaining isl29028_clear_configure_reg() write does not depend on the runtime PM state.
--- drivers/iio/light/isl29028.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/iio/light/isl29028.c +3 -4
@@ -615,7 +615,9 @@ static int isl29028_probe(struct i2c_client *client) indio_dev->name = id->name; indio_dev->modes =INDIO_DIRECT_MODE ; -pm_runtime_enable (&client->dev); + ret =devm_pm_runtime_enable (&client->dev); +if (ret) +return ret;pm_runtime_set_autosuspend_delay (&client->dev,ISL29028_POWER_OFF_DELAY_MS );pm_runtime_use_autosuspend (&client->dev);
@@ -638,9 +640,6 @@ static void isl29028_remove(struct i2c_client *client)iio_device_unregister (indio_dev); -pm_runtime_disable (&client->dev); -pm_runtime_set_suspended (&client->dev); -isl29028_clear_configure_reg (chip); }
Signature · 1 line
2.43.0
PATCH 2/4 iio: light: tsl2583: use devm_pm_runtime_enable() to fix probe error path
In reply to Stepan Ionichevtsl2583_probe() calls pm_runtime_enable() and then invokes the non-devm iio_device_register(). If iio_device_register() fails, the function returns without calling pm_runtime_disable(), so the runtime PM enable_count is leaked. On rebind the kernel emits an "Unbalanced pm_runtime_enable" warning.
Switch to devm_pm_runtime_enable() so that the runtime PM disable is tied to device lifetime and is also performed on probe error. The pm_runtime_set_autosuspend_delay() and pm_runtime_use_autosuspend() calls do not need to be undone explicitly because both autosuspend bits are torn down together with the runtime PM state at device release.
With probe now using devres, drop the matching pm_runtime_disable() and pm_runtime_set_suspended() calls from tsl2583_remove(). The remaining tsl2583_set_power_state(TSL2583_CNTL_PWR_OFF) call only issues an i2c write and does not depend on runtime PM being disabled, so its behaviour is unchanged.
--- drivers/iio/light/tsl2583.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/iio/light/tsl2583.c +3 -3
@@ -846,7 +846,9 @@ static int tsl2583_probe(struct i2c_client *clientp) indio_dev->modes =INDIO_DIRECT_MODE ; indio_dev->name = chip->client->name; -pm_runtime_enable (&clientp->dev); + ret =devm_pm_runtime_enable (&clientp->dev); +if (ret) +return ret;pm_runtime_set_autosuspend_delay (&clientp->dev,TSL2583_POWER_OFF_DELAY_MS );pm_runtime_use_autosuspend (&clientp->dev);
@@ -873,8 +875,6 @@ static void tsl2583_remove(struct i2c_client *client)iio_device_unregister (indio_dev); -pm_runtime_disable (&client->dev); -pm_runtime_set_suspended (&client->dev);tsl2583_set_power_state (chip,TSL2583_CNTL_PWR_OFF ); }
Signature · 1 line
2.43.0
PATCH 3/4 iio: temperature: mlx90614: use devm_pm_runtime_enable() to fix probe error path
In reply to Stepan IonichevWhen data->wakeup_gpio is present, mlx90614_probe() enables runtime PM with pm_runtime_enable() and then calls the non-devm iio_device_register(). If iio_device_register() fails, probe returns without calling pm_runtime_disable(), leaving the runtime PM enable_count unbalanced. On a subsequent bind attempt the core complains with "Unbalanced pm_runtime_enable".
Switch to devm_pm_runtime_enable() so the framework disables runtime PM automatically when the device is unbound or when probe fails after this point. The corresponding pm_runtime_disable() and pm_runtime_set_suspended() calls in mlx90614_remove() become redundant and are removed; the existing pm_runtime_status_suspended() check and mlx90614_sleep() call are preserved so the part is still put to sleep on unbind when it was not already runtime-suspended.
The edits stay inside the existing if (data->wakeup_gpio) branches, so devices without a wakeup GPIO are unaffected.
--- drivers/iio/temperature/mlx90614.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/iio/temperature/mlx90614.c +3 -3
@@ -625,7 +625,9 @@ static int mlx90614_probe(struct i2c_client *client) MLX90614_AUTOSLEEP_DELAY);pm_runtime_use_autosuspend (&client->dev);pm_runtime_set_active (&client->dev); -pm_runtime_enable (&client->dev); + ret =devm_pm_runtime_enable (&client->dev); +if (ret) +return ret; }return iio_device_register (indio_dev);
@@ -639,10 +641,8 @@ static void mlx90614_remove(struct i2c_client *client)iio_device_unregister (indio_dev);if (data->wakeup_gpio) { -pm_runtime_disable (&client->dev);if (!pm_runtime_status_suspended (&client->dev))mlx90614_sleep (data); -pm_runtime_set_suspended (&client->dev); } }
Signature · 1 line
2.43.0
PATCH 4/4 iio: accel: bmi088-accel: use devm_pm_runtime_enable() to fix probe error path
In reply to Stepan IonichevThe probe path calls pm_runtime_enable() and then registers the IIO device with iio_device_register(). If registration fails, the function returns the error directly without calling pm_runtime_disable(), leaving the runtime PM enable_count unbalanced. On the next bind attempt the core warns with "Unbalanced pm_runtime_enable".
Switch to devm_pm_runtime_enable() so the enable is automatically undone when the device is unbound, regardless of whether the rest of probe (or the bus remove callback) succeeds. This makes the error path correct without adding a new goto label.
With the runtime PM teardown now handled by the devm action, the manual pm_runtime_disable() and pm_runtime_set_suspended() calls in bmi088_accel_core_remove() become redundant and are dropped. The hardware-level power_down() call is kept so the chip is placed in suspend mode before the regmap goes away.
--- drivers/iio/accel/bmi088-accel-core.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/iio/accel/bmi088-accel-core.c +3 -3
@@ -573,7 +573,9 @@ int bmi088_accel_core_probe(struct device *dev, struct regmap *regmap,/* Enable runtime PM */ pm_runtime_get_noresume (dev);pm_runtime_set_suspended (dev); -pm_runtime_enable (dev); + ret =devm_pm_runtime_enable (dev); +if (ret) +return ret;/* We need ~6ms to startup, so set the delay to 6 seconds */ pm_runtime_set_autosuspend_delay (dev,6000 );pm_runtime_use_autosuspend (dev);
@@ -595,8 +597,6 @@ void bmi088_accel_core_remove(struct device *dev)iio_device_unregister (indio_dev); -pm_runtime_disable (dev); -pm_runtime_set_suspended (dev);bmi088_accel_power_down (data); }EXPORT_SYMBOL_NS_GPL (bmi088_accel_core_remove,"IIO_BMI088" );
Signature · 1 line
2.43.0
Quoted 33 lines · Stepan Ionichev
This series fixes a class of runtime PM
enable_countleaks on probe error paths acrossdrivers/iio/.Each affected driver calls
pm_runtime_enable()in probe and then a non-devm registration function (typicallyiio_device_register()). When the registration fails the probe returns directly without callingpm_runtime_disable(); on subsequent probe/rebind the runtime PM tracking complains about an unbalanced enable.The fix is the same in each driver: replace
pm_runtime_enable()withdevm_pm_runtime_enable()and drop the now-redundantpm_runtime_disable()andpm_runtime_set_suspended()calls in the .remove() callback. The devm action runs after .remove() and handles the teardown.
drivers/iio/adc/ti-ads1015.cwas posted as a standalone patch earlier:
https://lore.kernel.org/all/[email protected]/A separate follow-up will cover four more drivers (apds9960, mma8452, pa12203001, us5182d) where the same leak exists but the probe error path needs a goto to the existing manual cleanup label rather than a plain return.
Stepan Ionichev (4):
iio: light: isl29028: usedevm_pm_runtime_enable()to fix probe error
path
iio: light: tsl2583: usedevm_pm_runtime_enable()to fix probe error
path
iio: temperature: mlx90614: usedevm_pm_runtime_enable()to fix probe
error path
iio: accel: bmi088-accel: usedevm_pm_runtime_enable()to fix probe
error path
Quoted 4 lines
drivers/iio/accel/bmi088-accel-core.c | 6 +++--- drivers/iio/light/isl29028.c | 7 +++---- drivers/iio/light/tsl2583.c | 6 +++--- drivers/iio/temperature/mlx90614.c | 6 +++---
I guess something happened to your formatting, because all of the commit messages exceed the 72 character column length.
Signature · 3 lines
Kind regards CJD