Re: [PATCH v4 2/6] PM: runtime: Add pm_runtime_if_active guard and conditional variant

From: Frank Li

Date: Fri Oct 09 2026 - 22:57:50 EST


On Fri, Oct 09, 2026 at 09:30:11AM +0530, Golla Nagendra wrote:
> Add a pm_runtime_if_active base guard and its _try conditional variant
> to pm_runtime.h for drivers that need to conditionally acquire a runtime
> PM reference only when the device is already active.
>
> The base guard must not be used directly via guard()/scoped_guard()
> because pm_runtime_get_if_active() only acquires a reference when it
> returns 1; the destructor unconditionally calls pm_runtime_put(), which
> would underflow usage_count on a suspended device. The base guard
> exists solely to back the DEFINE_GUARD_COND _try variant.
>
> The _try variant (used via PM_RUNTIME_ACQUIRE_IF_ACTIVE) satisfies the
> _try API contract that guards must not produce an error when runtime PM
> is disabled for the device. When pm_runtime_get_if_active() returns
> -EINVAL (runtime PM disabled),

If only resolve PM disabled case, I suggest define DEFINE_GUARD as no-ops

Frank