mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Guangshuo Li <lgs201920130244@gmail.com>
Cc: "Andreas Klinger" <ak@it-klinger.de>,
	"David Lechner" <dlechner@baylibre.com>,
	"Nuno Sá" <nuno.sa@analog.com>,
	"Andy Shevchenko" <andy@kernel.org>,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] iio: proximity: srf04: fix runtime PM autosuspend cleanup
Date: Sat, 8 Aug 2026 00:41:29 +0100	[thread overview]
Message-ID: <20260808004129.53eafdd9@jic23-huawei> (raw)
In-Reply-To: <20260807141938.2491195-1-lgs201920130244@gmail.com>

On Fri,  7 Aug 2026 22:19:37 +0800
Guangshuo Li <lgs201920130244@gmail.com> wrote:

> srf04_probe() calls pm_runtime_use_autosuspend() when the optional
> power GPIO is present, but srf04_remove() does not call the matching
> pm_runtime_dont_use_autosuspend() before disabling runtime PM.
> 
> The runtime PM documentation requires pm_runtime_use_autosuspend() to
> be balanced with pm_runtime_dont_use_autosuspend() when the driver is
> removed. Failing to do so can leave the autosuspend usage state
> unbalanced and may result in a usage_count leak when the autosuspend
> delay is negative.
> 
> Add the missing pm_runtime_dont_use_autosuspend() call in the remove
> path before disabling runtime PM.
> 
> This issue was found by manual code inspection.

A cleaner solution may be to move to devm_pm_runtime_set_active_enabled()
though I am slightly concerned by the ordering here where in probe
we do iio_device_register() then runtime pm setup.
Remove would generally be the reverse order but instead it
does iio_device_unregister() the the runtime pm teardown.

That complicates matters and I can't see why we need to do that.
Do take a close look to see if you can see any reason this might be done.

I think easiest is move runtime pm registration before iio_device_register(),
using devm_pm_runtime_set_active_enabled() and ripping out all the calls
that effectively replaces.

Then a follow up patch to move to devm_iio_device_register() and drop
remove() entirely.

Looks like I missed this odd ordering when reviewing back in 2020.
oops.

Thanks,

Jonathan


> 
> Fixes: 2251157b335b4 ("iio: srf04: add power management feature")
> Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
> ---
>  drivers/iio/proximity/srf04.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/iio/proximity/srf04.c b/drivers/iio/proximity/srf04.c
> index 7be50bdebfcb..5f270f506803 100644
> --- a/drivers/iio/proximity/srf04.c
> +++ b/drivers/iio/proximity/srf04.c
> @@ -347,6 +347,7 @@ static void srf04_remove(struct platform_device *pdev)
>  	iio_device_unregister(indio_dev);
>  
>  	if (data->gpiod_power) {
> +		pm_runtime_dont_use_autosuspend(data->dev);
>  		pm_runtime_disable(data->dev);
>  		pm_runtime_set_suspended(data->dev);
>  	}


  parent reply	other threads:[~2026-08-07 23:41 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-07 14:19 Guangshuo Li
2026-08-07 15:02 ` Joshua Crofts
2026-08-18  7:07   ` Johan Hovold
2026-08-07 23:41 ` Jonathan Cameron [this message]
2026-08-18  7:14 ` Johan Hovold
2026-08-22  0:08   ` Jonathan Cameron
2026-08-24 12:32     ` Johan Hovold

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260808004129.53eafdd9@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=ak@it-klinger.de \
    --cc=andy@kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=lgs201920130244@gmail.com \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nuno.sa@analog.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®