From: Brian Norris <briannorris@chromium.org>
To: Ulf Hansson <ulf.hansson@oss.qualcomm.com>
Cc: "Rafael J . Wysocki" <rafael@kernel.org>,
linux-doc@vger.kernel.org, linux-pm@vger.kernel.org,
Ulf Hansson <ulfh@kernel.org>, Len Brown <lenb@kernel.org>,
Pavel Machek <pavel@kernel.org>,
Doug Anderson <dianders@chromium.org>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 3/8] PM: runtime: Misc improvements to runtime_pm.rst
Date: Thu, 24 Sep 2026 09:56:52 -0700 [thread overview]
Message-ID: <arVWVA3lks7SopQH@google.com> (raw)
In-Reply-To: <CAPx+jO_1qYnN37diVN1=PA0xGa0iSBfXD_uqgSdFpTn4t0zJiw@mail.gmail.com>
On Thu, Sep 24, 2026 at 04:01:00PM +0200, Ulf Hansson wrote:
> On Wed, Sep 23, 2026 at 7:47 PM Brian Norris <briannorris@chromium.org> wrote:
> > diff --git a/Documentation/power/runtime_pm.rst b/Documentation/power/runtime_pm.rst
> > index 39fdeeda7a1e..352cdaf0650d 100644
> > --- a/Documentation/power/runtime_pm.rst
> > +++ b/Documentation/power/runtime_pm.rst
> > @@ -315,7 +319,10 @@ removal of their drivers.
> >
> > Drivers in ->remove() callback should undo the runtime PM changes done
> > in ->probe(). Usually this means calling pm_runtime_disable(),
> > -pm_runtime_dont_use_autosuspend() etc.
> > +pm_runtime_dont_use_autosuspend() etc. Alternatively, drivers can use
> > +devm_pm_runtime_enable() during probe, which automatically takes care of
> > +calling pm_runtime_disable() and pm_runtime_dont_use_autosuspend() upon driver
> > +detachment.
>
> As I have stated in earlier discussions at LKML, the
> devm_pm_runtime_enable() API is not entirely easy to use correctly by
> drivers. It means that pm_runtime_disable() gets called at some point
> *after* the ->remove() callback has been invoked, which can cause
> problems, unless the driver's ->remove() callback has managed things
> correctly.
Yeah. And I think it's rare for drivers to have done a thorough job. A
rare exception: I found commit 2d90ecdfa326 ("ASoC: rockchip: i2s: Use
managed hclk and runtime PM cleanup") an interesting outlier -- it adds
an additional devres teardown to power things off afterward.
OTOH, between v1 and v2, I chose to tweak one of the Examples to avoid
devm, precisely because it was committing (or hinting at) these kinds of
mistakes.
> My point is, the above makes it sounds like it's easy to switch to the
> devm managed version, while it certainly isn't that straight forward.
Right, I said as much in the cover letter too:
(possible future work)
<quote>
* Adjust the way devm_pm_runtime_enable() works, specifically for
remove()/teardown. Currently, this is very hard to use correctly --
some common driver patterns may assume that a device will tear down
while RPM_SUSPENDED; but that's not actually guaranteed. Notably,
this makes some of the "Examples" section fairly tricky/subtle.
</quote>
Would this be a good moment to pass this possibility by you? What if we
taught the teardown to force a device back to RPM_SUSPENDED? Something
like:
static void pm_runtime_disable_action(void *data)
{
pm_runtime_dont_use_autosuspend(data);
pm_runtime_disable(data);
// New code:
if (pm_runtime_status_suspended(data)) {
int (*callback)(struct device *);
int ret;
callback = GET_CALLBACK(data, runtime_suspend);
ret = callback ? callback(data) : 0;
if (ret)
return;
pm_runtime_set_suspended(data);
}
}
> Not sure what that means for the documentation though. :-)
Well, I don't feel like the part you quoted is a problem. IMO, it's
totally fair to mention relevant APIs even if they're hard to use --
there is no part of the runtime PM that is easy to use!
But I'm definitely trying to make things easier too. Ideally, we can do
something like the above to make it easier to use. But if we
can't...well, I guess I can try to document pitfalls better -- possibly
in the Examples section, or maybe an extra note in the above quoted
area.
Thanks for looking,
Brian
next prev parent reply other threads:[~2026-09-24 16:56 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-23 17:40 [PATCH v2 0/8] PM: runtime: Overhaul kerneldoc, runtime_pm.rst docs Brian Norris
2026-09-23 17:40 ` [PATCH v2 1/8] PM: runtime: Correct pm_runtime_autosuspend_expiration() doc Brian Norris
2026-09-23 17:40 ` [PATCH v2 2/8] PM: runtime: More kerneldoc formatting Brian Norris
2026-09-23 17:40 ` [PATCH v2 3/8] PM: runtime: Misc improvements to runtime_pm.rst Brian Norris
2026-09-24 14:01 ` Ulf Hansson
2026-09-24 16:56 ` Brian Norris [this message]
2026-09-23 17:40 ` [PATCH v2 4/8] PM: runtime: Add "Section" hyperlinks Brian Norris
2026-09-23 17:40 ` [PATCH v2 5/8] PM: runtime: Clarify ->runtime_idle() callback return value handling Brian Norris
2026-09-23 17:40 ` [PATCH v2 6/8] PM: runtime: Clarify driver callback expectations and structure Section 2 Brian Norris
2026-09-23 17:40 ` [PATCH v2 7/8] PM: runtime: Expand introduction with core concepts and structure Brian Norris
2026-09-23 17:40 ` [PATCH v2 8/8] PM: runtime: Add Example Driver Patterns section Brian Norris
2026-09-24 14:13 ` Ulf Hansson
2026-09-24 20:32 ` Brian Norris
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=arVWVA3lks7SopQH@google.com \
--to=briannorris@chromium.org \
--cc=dianders@chromium.org \
--cc=lenb@kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=pavel@kernel.org \
--cc=rafael@kernel.org \
--cc=ulf.hansson@oss.qualcomm.com \
--cc=ulfh@kernel.org \
/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®