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 8/8] PM: runtime: Add Example Driver Patterns section
Date: Thu, 24 Sep 2026 13:32:08 -0700 [thread overview]
Message-ID: <arWIyLcKuyFvp2Ko@google.com> (raw)
In-Reply-To: <CAPx+jO843h9bOeWNATHm8D2afbniQsX7WECJzCxmfi9ZcH9+5w@mail.gmail.com>
On Thu, Sep 24, 2026 at 04:13:30PM +0200, Ulf Hansson wrote:
> On Wed, Sep 23, 2026 at 7:48 PM Brian Norris <briannorris@chromium.org> wrote:
> > +Basic Probe
> > +~~~~~~~~~~~
> > +
> > +A driver that powers on its hardware during probe and does not use autosuspend
> > +can initialize runtime PM using device-managed helpers:
> > +
> > +.. code-block:: c
> > +
> > + static int foo_probe(struct platform_device *pdev)
> > + {
> > + struct device *dev = &pdev->dev;
> > + struct foo_priv *priv;
> > + int ret;
> > +
> > + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
> > + if (!priv)
> > + return -ENOMEM;
> > +
> > + /* Power on and initialize hardware registers... */
> > +
> > + /*
> > + * The code above left hardware powered on and operational, so
> > + * tell the PM core that the device is active before enabling
> > + * runtime PM.
> > + */
> > + pm_runtime_set_active(dev);
> > +
> > + ret = devm_pm_runtime_enable(dev);
> > + if (ret)
> > + return ret;
> > +
> > + /*
> > + * Alternatively, the above two calls can be combined into:
> > + * ret = devm_pm_runtime_set_active_enabled(dev);
> > + * if (ret)
> > + * return ret;
> > + */
> > +
> > + /*
> > + * Upon successful return from ->probe(), the driver core
> > + * automatically executes pm_request_idle(dev), allowing the
> > + * device to suspend asynchronously if its usage counter is zero.
> > + */
> > + return 0;
>
> The above looks nice and simple, but what happens in the error path is
> equally important.
>
> In principle, nothing prevents the runtime PM callbacks to be invoked
> until pm_runtime_disable() has been called at some point *after* the
> probe callback has returned. This needs to be taken care of correctly.
>
> Likewise, as it's great with an example for ->probe(), it would be
> nice with a corresponding example for ->remove().
Good points. I've rewritten much of the Examples to now:
(a) largely *not* use devm_*;
(b) include a more interesting set of error handling and remove(); and
(c) only after doing (a) and (b), show an example that uses devm_*() to
replace the appropriate error handling and remove() teardown.
I hope that will also partially address your other comment about
devm_pm_runtime_enable(), and how it's difficult to use correctly.
> I will have to defer reviewing the remaining parts in the $subject
> patch, a bit limited bandwidth at the moment.
Thanks for the time you spent on it!
I'll wait a bit more in case Rafael had other feedback, before sending a
v3 that (I think) addresses your feedback.
Brian
prev parent reply other threads:[~2026-09-24 20:32 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
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 [this message]
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=arWIyLcKuyFvp2Ko@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®