[PATCH 4/4] iio: accel: mma8452: use devm_pm_runtime_enable() to fix probe error path

From: Stepan Ionichev

Date: Fri May 29 2026 - 06:50:12 EST


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

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

diff --git a/drivers/iio/accel/mma8452.c b/drivers/iio/accel/mma8452.c
index 15172ba2972c..88ed47d33e03 100644
--- a/drivers/iio/accel/mma8452.c
+++ b/drivers/iio/accel/mma8452.c
@@ -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));
--
2.43.0