Skip to contentSkip to conversation

iio: adc: ti-ads1015: use devm_pm_runtime_enable() to fix probe error path

PATCH Superseded Stepan Ionichev 3 participants 3 messages May 29 IIO

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iio: adc: ti-ads1015: use devm_pm_runtime_enable() to fix probe error path

ads1015_probe() calls pm_runtime_enable() and then iio_device_register(). If iio_device_register() fails the function returns directly, leaving runtime PM enabled and autosuspend in use. On subsequent probe/rebind the runtime PM tracking complains about an unbalanced enable.

Switch to devm_pm_runtime_enable() so the enable (and the matching dont_use_autosuspend) are torn down automatically on probe failure and on driver unbind. The manual pm_runtime_disable() and pm_runtime_set_suspended() calls in ads1015_remove() are no longer needed and are dropped; the devm action runs after .remove() and now handles the teardown. While here, convert the dev_err() + return to dev_err_probe() to follow current style.

---
 drivers/iio/adc/ti-ads1015.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
drivers/iio/adc/ti-ads1015.c +6 -8
index c7ffe47449e2..2331e946c519 100644
@@ -1037,13 +1037,14 @@ static int ads1015_probe(struct i2c_client *client)
 		return ret;
 	pm_runtime_set_autosuspend_delay(&client->dev, ADS1015_SLEEP_DELAY_MS);
 	pm_runtime_use_autosuspend(&client->dev);
-	pm_runtime_enable(&client->dev);
+	ret = devm_pm_runtime_enable(&client->dev);
+	if (ret)
+		return ret;
 
 	ret = iio_device_register(indio_dev);
-	if (ret < 0) {
-		dev_err(&client->dev, "Failed to register IIO device\n");
-		return ret;
-	}
+	if (ret < 0)
+		return dev_err_probe(&client->dev, ret,
+				     "Failed to register IIO device\n");
 
 	return 0;
 }
@@ -1056,9 +1057,6 @@ static void ads1015_remove(struct i2c_client *client)
 
 	iio_device_unregister(indio_dev);
 
-	pm_runtime_disable(&client->dev);
-	pm_runtime_set_suspended(&client->dev);
-
 	/* power down single shot mode */
 	ret = ads1015_set_conv_mode(data, ADS1015_SINGLESHOT);
 	if (ret)
Signature · 1 line
2.43.0
#1 lore raw
Quoted 31 lines · Stepan Ionichev

ads1015_probe() calls pm_runtime_enable() and then iio_device_register(). If iio_device_register() fails the function returns directly, leaving runtime PM enabled and autosuspend in use. On subsequent probe/rebind the runtime PM tracking complains about an unbalanced enable.

Switch to devm_pm_runtime_enable() so the enable (and the matching dont_use_autosuspend) are torn down automatically on probe failure and on driver unbind. The manual pm_runtime_disable() and pm_runtime_set_suspended() calls in ads1015_remove() are no longer needed and are dropped; the devm action runs after .remove() and now handles the teardown. While here, convert the dev_err() + return to dev_err_probe() to follow current style.

---
 drivers/iio/adc/ti-ads1015.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
drivers/iio/adc/ti-ads1015.c +3 -1
index c7ffe47449e2..2331e946c519 100644
@@ -1037,13 +1037,14 @@ static int ads1015_probe(struct i2c_client *client)
                return ret;
        pm_runtime_set_autosuspend_delay(&client->dev, ADS1015_SLEEP_DELAY_MS);
        pm_runtime_use_autosuspend(&client->dev);
-       pm_runtime_enable(&client->dev);
+       ret = devm_pm_runtime_enable(&client->dev);
+       if (ret)
+               return ret;

drivers/iio/adc/ti-ads1015.c static int ads1015_probe(struct i2c_client *client) · line 1048

Quoted 10 lines
drivers/iio/adc/ti-ads1015.c +3 -4
 
        ret = iio_device_register(indio_dev);
-       if (ret < 0) {
-               dev_err(&client->dev, "Failed to register IIO device\n");
-               return ret;
-       }
+       if (ret < 0)
+               return dev_err_probe(&client->dev, ret,
+                                    "Failed to register IIO device\n");
 

The pm_runtime stuff seems fine, however not sure why you slipped this change into the patch - there are a few more instances where dev_err() can be moved to dev_err_probe(), e.g.

https://elixir.bootlin.com/linux/v7.1-rc5/source/drivers/iio/adc/ti-ads1015.c#L981

Signature · 3 lines
Kind regards

CJD
maintainer
#2 lore raw
In reply to Stepan Ionichev
Quoted 43 lines · On Fri, 29 May 2026 15:10:11 +0500 Stepan Ionichev <[email protected]> wrote:

ads1015_probe() calls pm_runtime_enable() and then iio_device_register(). If iio_device_register() fails the function returns directly, leaving runtime PM enabled and autosuspend in use. On subsequent probe/rebind the runtime PM tracking complains about an unbalanced enable.

Switch to devm_pm_runtime_enable() so the enable (and the matching dont_use_autosuspend) are torn down automatically on probe failure and on driver unbind. The manual pm_runtime_disable() and pm_runtime_set_suspended() calls in ads1015_remove() are no longer needed and are dropped; the devm action runs after .remove() and now handles the teardown. While here, convert the dev_err() + return to dev_err_probe() to follow current style.

---
 drivers/iio/adc/ti-ads1015.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
drivers/iio/adc/ti-ads1015.c +6 -5
index c7ffe47449e2..2331e946c519 100644
@@ -1037,13 +1037,14 @@ static int ads1015_probe(struct i2c_client *client)
 		return ret;
 	pm_runtime_set_autosuspend_delay(&client->dev, ADS1015_SLEEP_DELAY_MS);
 	pm_runtime_use_autosuspend(&client->dev);
-	pm_runtime_enable(&client->dev);
+	ret = devm_pm_runtime_enable(&client->dev);
+	if (ret)
+		return ret;
 
 	ret = iio_device_register(indio_dev);
-	if (ret < 0) {
-		dev_err(&client->dev, "Failed to register IIO device\n");
-		return ret;
-	}
+	if (ret < 0)
+		return dev_err_probe(&client->dev, ret,
+				     "Failed to register IIO device\n");
 
 	return 0;
 }

drivers/iio/adc/ti-ads1015.c static void ads1015_remove(struct i2c_client *client) · line 1061

Quoted 8 lines
drivers/iio/adc/ti-ads1015.c +0 -3
@@ -1056,9 +1057,6 @@ static void ads1015_remove(struct i2c_client *client)
 
 	iio_device_unregister(indio_dev);
 
-	pm_runtime_disable(&client->dev);
-	pm_runtime_set_suspended(&client->dev);
-
 	/* power down single shot mode */
 	ret = ads1015_set_conv_mode(data, ADS1015_SINGLESHOT);

Hmm. Looks like this is undoing the setting of continuous mode just above the runtime PM stuff. That isn't done in the error path but should be. If it were then there would have been a goto for that iio_deivce_unregister() and it would have been obvious the change here would break the ordering.

Quoted 1 line
drivers/iio/adc/ti-ads1015.c +0 -0
 	if (ret)