All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/4] iio: fix PM-enable leak on probe error path across 4 drivers
@ 2026-05-29 10:44 Stepan Ionichev
  2026-05-29 10:44 ` [PATCH 1/4] iio: light: isl29028: use devm_pm_runtime_enable() to fix probe error path Stepan Ionichev
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Stepan Ionichev @ 2026-05-29 10:44 UTC (permalink / raw)
  To: jic23; +Cc: dlechner, nuno.sa, andy, linux-iio, linux-kernel

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/20260529101011.3030-1-sozdayvek@gmail.com/

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
-- 
2.43.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/4] iio: light: isl29028: use devm_pm_runtime_enable() to fix probe error path
  2026-05-29 10:44 [PATCH 0/4] iio: fix PM-enable leak on probe error path across 4 drivers Stepan Ionichev
@ 2026-05-29 10:44 ` Stepan Ionichev
  2026-05-29 10:44 ` [PATCH 2/4] iio: light: tsl2583: " Stepan Ionichev
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Stepan Ionichev @ 2026-05-29 10:44 UTC (permalink / raw)
  To: jic23; +Cc: dlechner, nuno.sa, andy, linux-iio, linux-kernel

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.

Signed-off-by: Stepan Ionichev <sozdayvek@gmail.com>
---
 drivers/iio/light/isl29028.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/iio/light/isl29028.c b/drivers/iio/light/isl29028.c
index 374bccad9119..4fb0262b214a 100644
--- a/drivers/iio/light/isl29028.c
+++ b/drivers/iio/light/isl29028.c
@@ -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);
 }
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/4] iio: light: tsl2583: use devm_pm_runtime_enable() to fix probe error path
  2026-05-29 10:44 [PATCH 0/4] iio: fix PM-enable leak on probe error path across 4 drivers Stepan Ionichev
  2026-05-29 10:44 ` [PATCH 1/4] iio: light: isl29028: use devm_pm_runtime_enable() to fix probe error path Stepan Ionichev
@ 2026-05-29 10:44 ` Stepan Ionichev
  2026-05-29 10:44 ` [PATCH 3/4] iio: temperature: mlx90614: " Stepan Ionichev
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Stepan Ionichev @ 2026-05-29 10:44 UTC (permalink / raw)
  To: jic23; +Cc: dlechner, nuno.sa, andy, linux-iio, linux-kernel

tsl2583_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.

Signed-off-by: Stepan Ionichev <sozdayvek@gmail.com>
---
 drivers/iio/light/tsl2583.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/iio/light/tsl2583.c b/drivers/iio/light/tsl2583.c
index 8801a491de77..62542d904b3b 100644
--- a/drivers/iio/light/tsl2583.c
+++ b/drivers/iio/light/tsl2583.c
@@ -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);
 }
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/4] iio: temperature: mlx90614: use devm_pm_runtime_enable() to fix probe error path
  2026-05-29 10:44 [PATCH 0/4] iio: fix PM-enable leak on probe error path across 4 drivers Stepan Ionichev
  2026-05-29 10:44 ` [PATCH 1/4] iio: light: isl29028: use devm_pm_runtime_enable() to fix probe error path Stepan Ionichev
  2026-05-29 10:44 ` [PATCH 2/4] iio: light: tsl2583: " Stepan Ionichev
@ 2026-05-29 10:44 ` Stepan Ionichev
  2026-05-29 10:44 ` [PATCH 4/4] iio: accel: bmi088-accel: " Stepan Ionichev
  2026-05-29 11:11 ` [PATCH 0/4] iio: fix PM-enable leak on probe error path across 4 drivers Joshua Crofts
  4 siblings, 0 replies; 6+ messages in thread
From: Stepan Ionichev @ 2026-05-29 10:44 UTC (permalink / raw)
  To: jic23; +Cc: dlechner, nuno.sa, andy, linux-iio, linux-kernel

When 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.

Signed-off-by: Stepan Ionichev <sozdayvek@gmail.com>
---
 drivers/iio/temperature/mlx90614.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/iio/temperature/mlx90614.c b/drivers/iio/temperature/mlx90614.c
index 1ad21b73e1b4..9e09597a1c31 100644
--- a/drivers/iio/temperature/mlx90614.c
+++ b/drivers/iio/temperature/mlx90614.c
@@ -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);
 	}
 }
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 4/4] iio: accel: bmi088-accel: use devm_pm_runtime_enable() to fix probe error path
  2026-05-29 10:44 [PATCH 0/4] iio: fix PM-enable leak on probe error path across 4 drivers Stepan Ionichev
                   ` (2 preceding siblings ...)
  2026-05-29 10:44 ` [PATCH 3/4] iio: temperature: mlx90614: " Stepan Ionichev
@ 2026-05-29 10:44 ` Stepan Ionichev
  2026-05-29 11:11 ` [PATCH 0/4] iio: fix PM-enable leak on probe error path across 4 drivers Joshua Crofts
  4 siblings, 0 replies; 6+ messages in thread
From: Stepan Ionichev @ 2026-05-29 10:44 UTC (permalink / raw)
  To: jic23; +Cc: dlechner, nuno.sa, andy, linux-iio, linux-kernel

The 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.

Signed-off-by: Stepan Ionichev <sozdayvek@gmail.com>
---
 drivers/iio/accel/bmi088-accel-core.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/iio/accel/bmi088-accel-core.c b/drivers/iio/accel/bmi088-accel-core.c
index c7da90af0d2d..0fd840d85a15 100644
--- a/drivers/iio/accel/bmi088-accel-core.c
+++ b/drivers/iio/accel/bmi088-accel-core.c
@@ -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");
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/4] iio: fix PM-enable leak on probe error path across 4 drivers
  2026-05-29 10:44 [PATCH 0/4] iio: fix PM-enable leak on probe error path across 4 drivers Stepan Ionichev
                   ` (3 preceding siblings ...)
  2026-05-29 10:44 ` [PATCH 4/4] iio: accel: bmi088-accel: " Stepan Ionichev
@ 2026-05-29 11:11 ` Joshua Crofts
  4 siblings, 0 replies; 6+ messages in thread
From: Joshua Crofts @ 2026-05-29 11:11 UTC (permalink / raw)
  To: Stepan Ionichev; +Cc: jic23, dlechner, nuno.sa, andy, linux-iio, linux-kernel

On Fri, 29 May 2026 at 12:51, Stepan Ionichev <sozdayvek@gmail.com> wrote:
>
> 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/20260529101011.3030-1-sozdayvek@gmail.com/
>
> 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 +++---

I guess something happened to your formatting, because all of the commit
messages exceed the 72 character column length.

-- 
Kind regards

CJD

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-05-29 11:11 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-29 10:44 [PATCH 0/4] iio: fix PM-enable leak on probe error path across 4 drivers Stepan Ionichev
2026-05-29 10:44 ` [PATCH 1/4] iio: light: isl29028: use devm_pm_runtime_enable() to fix probe error path Stepan Ionichev
2026-05-29 10:44 ` [PATCH 2/4] iio: light: tsl2583: " Stepan Ionichev
2026-05-29 10:44 ` [PATCH 3/4] iio: temperature: mlx90614: " Stepan Ionichev
2026-05-29 10:44 ` [PATCH 4/4] iio: accel: bmi088-accel: " Stepan Ionichev
2026-05-29 11:11 ` [PATCH 0/4] iio: fix PM-enable leak on probe error path across 4 drivers Joshua Crofts

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.