Re: [PATCH v2 1/3] PM: runtime: Add auto-cleanup macros for "resume and get" operations

From: Takashi Iwai

Date: Mon Sep 22 2025 - 04:38:54 EST


On Sat, 20 Sep 2025 12:54:58 +0200,
Rafael J. Wysocki wrote:
>
> From: Rafael J. Wysocki <rafael.j.wysocki@xxxxxxxxx>
>
> It is generally useful to be able to automatically drop a device's
> runtime PM usage counter incremented by runtime PM operations that
> resume a device and bump up its usage counter [1].
>
> To that end, add DEFINE_CLASS() macros allowing pm_runtime_put()
> and pm_runtime_put_autosuspend() to be used for the auto-cleanup in
> those cases.
>
> Simply put, a piece of code like below:
>
> pm_runtime_get_sync(dev);
> .....
> pm_runtime_put(dev);
> return 0;
>
> can be transformed with CLASS() like:
>
> CLASS(pm_runtime_get_active, pm)(dev);
> if (IS_ERR(pm))
> return PTR_ERR(pm);
> .....
> return 0;
>
> (note the new resume error handling).

Do we still allow the code without the error check even using CLASS()?
Although the error check should be handled, it's not mandatory for
now. That said, the above example could be still in a form like:

CLASS(pm_runtime_get_active, pm)(dev);
.....
return 0;

while adding the proper error check is recommended?


thanks,

Takashi