Skip to contentSkip to conversation

iio: srf04: fix pm_runtime handling on probe error path

PATCH Applied Cong Nguyen 2 participants 2 messages Jul 27 – Aug 1

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iio: srf04: fix pm_runtime handling on probe error path

When pm_runtime_set_active() fails during probe, the driver logs the error and unregisters the IIO device, but then falls through and still calls pm_runtime_enable() before returning the error.

Since probe returns an error, srf04_remove() is never called, so runtime PM is left enabled without a matching pm_runtime_disable(). This leaks the enable and triggers an "Unbalanced pm_runtime_enable!" warning on a subsequent bind of the device.

Return the error right after unregistering the IIO device so that runtime PM is not enabled on the failure path.

Fixes 2251157b335b ("iio: srf04: add power management feature")
---
 drivers/iio/proximity/srf04.c | 1 +
 1 file changed, 1 insertion(+)
drivers/iio/proximity/srf04.c +1 -0
index e97f9a20ac7a..337938657449 100644
@@ -331,6 +331,7 @@ static int srf04_probe(struct platform_device *pdev)
 		if (ret) {
 			dev_err(data->dev, "pm_runtime_set_active: %d\n", ret);
 			iio_device_unregister(indio_dev);
+			return ret;
 		}
 
 		pm_runtime_enable(data->dev);
Signature · 1 line
2.25.1
maintainer Applied
#1 lore raw
Quoted 9 lines · On Mon, 27 Jul 2026 22:51:15 +0700 Cong Nguyen <[email protected]> wrote:

When pm_runtime_set_active() fails during probe, the driver logs the error and unregisters the IIO device, but then falls through and still calls pm_runtime_enable() before returning the error.

Since probe returns an error, srf04_remove() is never called, so runtime PM is left enabled without a matching pm_runtime_disable(). This leaks the enable and triggers an "Unbalanced pm_runtime_enable!" warning on a subsequent bind of the device.

Quoted 6 lines

Return the error right after unregistering the IIO device so that runtime PM is not enabled on the failure path.

Fixes 2251157b335b ("iio: srf04: add power management feature")

Applied to the fixes-togreg branch of iio.git.

Thanks,

Jonathan

Quoted 16 lines
---
 drivers/iio/proximity/srf04.c | 1 +
 1 file changed, 1 insertion(+)
drivers/iio/proximity/srf04.c +1 -0
index e97f9a20ac7a..337938657449 100644
@@ -331,6 +331,7 @@ static int srf04_probe(struct platform_device *pdev)
 		if (ret) {
 			dev_err(data->dev, "pm_runtime_set_active: %d\n", ret);
 			iio_device_unregister(indio_dev);
+			return ret;
 		}
 
 		pm_runtime_enable(data->dev);