* [PATCH] iio: pressure: mpl115: Fix runtime PM cleanup on probe failure
@ 2026-07-18 6:19 Can Peng
2026-07-18 22:14 ` Jonathan Cameron
0 siblings, 1 reply; 2+ messages in thread
From: Can Peng @ 2026-07-18 6:19 UTC (permalink / raw)
To: jic23, dlechner, nuno.sa, andy, rajat.khandelwal
Cc: linux-iio, linux-kernel, Can Peng, stable
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. Also unwind the initial
pm_runtime_get_noresume() reference if setting up runtime PM fails
before the matching put.
Fixes: 0c3a333524a3 ("iio: pressure: mpl115: Implementing low power mode by shutdown gpio")
Cc: stable@vger.kernel.org
Signed-off-by: Can Peng <pengcan@kylinos.cn>
---
drivers/iio/pressure/mpl115.c | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/drivers/iio/pressure/mpl115.c b/drivers/iio/pressure/mpl115.c
index 16e112b796ba..9e77b76bd1fa 100644
--- a/drivers/iio/pressure/mpl115.c
+++ b/drivers/iio/pressure/mpl115.c
@@ -204,8 +204,17 @@ 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) {
+ pm_runtime_put_noidle(dev);
+ return ret;
+ }
+
+ ret = devm_pm_runtime_enable(dev);
+ if (ret) {
+ pm_runtime_put_noidle(dev);
+ return ret;
+ }
/*
* As the device takes 3 ms to come up with a fresh
--
2.53.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] iio: pressure: mpl115: Fix runtime PM cleanup on probe failure
2026-07-18 6:19 [PATCH] iio: pressure: mpl115: Fix runtime PM cleanup on probe failure Can Peng
@ 2026-07-18 22:14 ` Jonathan Cameron
0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Cameron @ 2026-07-18 22:14 UTC (permalink / raw)
To: Can Peng
Cc: dlechner, nuno.sa, andy, rajat.khandelwal, linux-iio,
linux-kernel, stable
On Sat, 18 Jul 2026 14:19:09 +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. Also unwind the initial
> pm_runtime_get_noresume() reference if setting up runtime PM fails
> before the matching put.
>
> Fixes: 0c3a333524a3 ("iio: pressure: mpl115: Implementing low power mode by shutdown gpio")
> Cc: stable@vger.kernel.org
> Signed-off-by: Can Peng <pengcan@kylinos.cn>
Hi Can Peng,
A similar code pattern came up recently based as bold claim from sashiko
that autosuspend won't kick in if we don't do a get / put pair.
Turned out not to be true. If no one touches the runtime pm counts
and turns runtime pm on, then this line:
https://elixir.bootlin.com/linux/v7.1.3/source/drivers/base/dd.c#L872
becomes relevant. That ends up calling auto suspend.
Please chase through this call sequence just in case we got it wrong!
Hence I believe this is a simplification change that can be made here.
> ---
> drivers/iio/pressure/mpl115.c | 13 +++++++++++--
> 1 file changed, 11 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/iio/pressure/mpl115.c b/drivers/iio/pressure/mpl115.c
> index 16e112b796ba..9e77b76bd1fa 100644
> --- a/drivers/iio/pressure/mpl115.c
> +++ b/drivers/iio/pressure/mpl115.c
> @@ -204,8 +204,17 @@ int mpl115_probe(struct device *dev, const char *name,
> if (data->shutdown) {
> /* Enable runtime PM */
> pm_runtime_get_noresume(dev);
Drop this get_noresume()
> - pm_runtime_set_active(dev);
> - pm_runtime_enable(dev);
> + ret = pm_runtime_set_active(dev);
> + if (ret) {
> + pm_runtime_put_noidle(dev);
No need for the put here
> + return ret;
> + }
> +
> + ret = devm_pm_runtime_enable(dev);
> + if (ret) {
> + pm_runtime_put_noidle(dev);
or here.
The switch to devm_pm_runtime_enable() and error checks all look good
to me.
> + return ret;
> + }
>
> /*
> * As the device takes 3 ms to come up with a fresh
and the pm_runtime_put() at end of this block
We don't mind if auto runtime suspend happens a tiny bit later.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-07-18 22:14 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-18 6:19 [PATCH] iio: pressure: mpl115: Fix runtime PM cleanup on probe failure Can Peng
2026-07-18 22:14 ` Jonathan Cameron
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox