[PATCH v2] iio: pressure: mpl115: Fix runtime PM cleanup

Can Peng posted 1 patch 5 days ago
drivers/iio/pressure/mpl115.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
[PATCH v2] iio: pressure: mpl115: Fix runtime PM cleanup
Posted by Can Peng 5 days ago
mpl115_probe() enables runtime PM when a shutdown GPIO is present and
then returns the result of devm_iio_device_register(). If registration
fails, runtime PM remains enabled and autosuspend remains selected.

The same unmanaged runtime PM state is also left behind on driver
unbind, as the IIO device registration is managed but the runtime PM
setup is not.

Use devm_pm_runtime_enable() so runtime PM is disabled automatically on
probe failure and driver unbind, and check pm_runtime_set_active() so
setup errors are reported.

Set the autosuspend parameters before enabling runtime PM. Once probe
has completed, the driver core queues an idle request for the device, so
an explicit pm_runtime_get_noresume()/pm_runtime_put() pair is not
needed to start autosuspend.

Fixes: 0c3a333524a3 ("iio: pressure: mpl115: Implementing low power mode by shutdown gpio")
Cc: stable@vger.kernel.org
Suggested-by: jonathan.cameron@oss.qualcomm.com
Signed-off-by: Can Peng <pengcan@kylinos.cn>
---
Changes in v2:
- Drop the explicit pm_runtime_get_noresume()/pm_runtime_put() pair and
  rely on the driver core idle request after probe.
- Set autosuspend parameters before enabling runtime PM.
- Update the commit message accordingly.
- Link to v1: https://lore.kernel.org/all/20260718061909.428476-1-pengcan@kylinos.cn/

 drivers/iio/pressure/mpl115.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/drivers/iio/pressure/mpl115.c b/drivers/iio/pressure/mpl115.c
index 16e112b796ba..2929ea8e4e01 100644
--- a/drivers/iio/pressure/mpl115.c
+++ b/drivers/iio/pressure/mpl115.c
@@ -203,9 +203,9 @@ int mpl115_probe(struct device *dev, const char *name,
 
 	if (data->shutdown) {
 		/* Enable runtime PM */
-		pm_runtime_get_noresume(dev);
-		pm_runtime_set_active(dev);
-		pm_runtime_enable(dev);
+		ret = pm_runtime_set_active(dev);
+		if (ret)
+			return ret;
 
 		/*
 		 * As the device takes 3 ms to come up with a fresh
@@ -215,7 +215,10 @@ int mpl115_probe(struct device *dev, const char *name,
 		 */
 		pm_runtime_set_autosuspend_delay(dev, 2000);
 		pm_runtime_use_autosuspend(dev);
-		pm_runtime_put(dev);
+
+		ret = devm_pm_runtime_enable(dev);
+		if (ret)
+			return ret;
 
 		dev_dbg(dev, "low-power mode enabled");
 	} else
-- 
2.53.0
Re: [PATCH v2] iio: pressure: mpl115: Fix runtime PM cleanup
Posted by Jonathan Cameron 1 day, 2 hours ago
On Mon, 20 Jul 2026 10:43:12 +0800
Can Peng <pengcan@kylinos.cn> wrote:

> mpl115_probe() enables runtime PM when a shutdown GPIO is present and
> then returns the result of devm_iio_device_register(). If registration
> fails, runtime PM remains enabled and autosuspend remains selected.
> 
> The same unmanaged runtime PM state is also left behind on driver
> unbind, as the IIO device registration is managed but the runtime PM
> setup is not.
> 
> Use devm_pm_runtime_enable() so runtime PM is disabled automatically on
> probe failure and driver unbind, and check pm_runtime_set_active() so
> setup errors are reported.
> 
> Set the autosuspend parameters before enabling runtime PM. Once probe
> has completed, the driver core queues an idle request for the device, so
> an explicit pm_runtime_get_noresume()/pm_runtime_put() pair is not
> needed to start autosuspend.
> 
> Fixes: 0c3a333524a3 ("iio: pressure: mpl115: Implementing low power mode by shutdown gpio")
> Cc: stable@vger.kernel.org
> Suggested-by: jonathan.cameron@oss.qualcomm.com
> Signed-off-by: Can Peng <pengcan@kylinos.cn>
Hi,

Looks good to me. I'm going to take it the slow path via the next
merge window as it is a fairly low impact bug.

Applied to the testing branch of iio.git

Thanks,

Jonathan

> ---
> Changes in v2:
> - Drop the explicit pm_runtime_get_noresume()/pm_runtime_put() pair and
>   rely on the driver core idle request after probe.
> - Set autosuspend parameters before enabling runtime PM.
> - Update the commit message accordingly.
> - Link to v1: https://lore.kernel.org/all/20260718061909.428476-1-pengcan@kylinos.cn/
> 
>  drivers/iio/pressure/mpl115.c | 11 +++++++----
>  1 file changed, 7 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/iio/pressure/mpl115.c b/drivers/iio/pressure/mpl115.c
> index 16e112b796ba..2929ea8e4e01 100644
> --- a/drivers/iio/pressure/mpl115.c
> +++ b/drivers/iio/pressure/mpl115.c
> @@ -203,9 +203,9 @@ int mpl115_probe(struct device *dev, const char *name,
>  
>  	if (data->shutdown) {
>  		/* Enable runtime PM */
> -		pm_runtime_get_noresume(dev);
> -		pm_runtime_set_active(dev);
> -		pm_runtime_enable(dev);
> +		ret = pm_runtime_set_active(dev);
> +		if (ret)
> +			return ret;
>  
>  		/*
>  		 * As the device takes 3 ms to come up with a fresh
> @@ -215,7 +215,10 @@ int mpl115_probe(struct device *dev, const char *name,
>  		 */
>  		pm_runtime_set_autosuspend_delay(dev, 2000);
>  		pm_runtime_use_autosuspend(dev);
> -		pm_runtime_put(dev);
> +
> +		ret = devm_pm_runtime_enable(dev);
> +		if (ret)
> +			return ret;
>  
>  		dev_dbg(dev, "low-power mode enabled");
>  	} else