[PATCH 2/4] iio: light: tsl2583: use devm_pm_runtime_enable() to fix probe error path

From: Stepan Ionichev

Date: Fri May 29 2026 - 06:51:48 EST


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@xxxxxxxxx>
---
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