Re: [PATCH 1/3] PM: runtime: Define class helpers for automatic PM runtime cleanup
From: Rafael J. Wysocki
Date: Fri Sep 19 2025 - 13:04:22 EST
On Fri, Sep 19, 2025 at 6:32 PM Takashi Iwai <tiwai@xxxxxxx> wrote:
>
> From: "Rafael J. Wysocki" <rafael@xxxxxxxxxx>
>
> This patch adds two CLASS macros for the easier use of the
> auto-cleanup feature to manage the runtime PM get/put pairs.
> With the CLASS macro, pm_runtime_put() (or *_autosuspend) is called
> automatically at its scope exit, so you can remove the explicit
> pm_runtime_put() call.
The part of the changelog below is actually really nice.
> Simply put, a code like below
>
> ret = pm_runtime_resume_and_get(dev);
> if (ret < 0)
> return ret;
> .....
> pm_runtime_put(dev);
> return 0;
>
> can be simplified with CLASS() like:
>
> CLASS(pm_runtime_resume_and_get, pm)(dev);
> if (IS_ERR(pm))
> return PTR_ERR(pm);
> .....
> return 0;
>
> (see pm_runtime_put() call is gone).
>
> When the original code calls pm_runtime_put_autosuspend(), use
> CLASS(pm_runtime_resume_and_get_auto) variant, instead.
> e.g. a code like:
>
> ret = pm_runtime_resume_and_get(dev);
> if (ret < 0)
> return ret;
> .....
> pm_runtime_put_autosuspend(dev);
> return 0;
>
> will be like:
>
> CLASS(pm_runtime_resume_and_get_auto, pm)(dev);
> if (IS_ERR(pm))
> return PTR_ERR(pm);
> .....
> return 0;
>
> Note that there is no CLASS macro defined for pm_runtime_get_sync().
> With the auto-cleanup, we can unify both usages.
> You can use CLASS(pm_runtime_resume_and_get) but simply skip the error
> check; so a code like below:
>
> pm_runtime_get_sync(dev);
> .....
> pm_runtime_put(dev);
> return 0;
>
> will become like:
>
> CLASS(pm_runtime_resume_and_get, pm)(dev);
> .....
> return 0;
>
> Link: https://lore.kernel.org/878qimv24u.wl-tiwai@xxxxxxx
> Signed-off-by: Takashi Iwai <tiwai@xxxxxxx>
So I'm going to include it into the first patch and add a
Co-developed-by: tag for you to it.
I'll send a v2, but I'll wait some time in case someone else has any
comments. Probably tomorrow.