PM: runtime: Fix conditional guard definitions
Subsystems (2)
Rafael J. Wysocki
maintainerPATCH 1/1 PM: runtime: Fix conditional guard definitions
From: Rafael J. Wysocki <[email protected]>
Since pm_runtime_get_active() returns 0 on success, all of the DEFINE_GUARD_COND() macros in pm_runtime.h need the "_RET == 0" condition at the end of the argument list or they would not work correctly.
--- include/linux/pm_runtime.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
include/linux/pm_runtime.h +4 -4
@@ -629,13 +629,13 @@ DEFINE_GUARD(pm_runtime_active_auto, str* device. */ DEFINE_GUARD_COND (pm_runtime_active, _try, - pm_runtime_get_active(_T, RPM_TRANSPARENT)) + pm_runtime_get_active(_T, RPM_TRANSPARENT), _RET == 0)DEFINE_GUARD_COND (pm_runtime_active, _try_enabled, - pm_runtime_resume_and_get(_T)) + pm_runtime_resume_and_get(_T), _RET == 0)DEFINE_GUARD_COND (pm_runtime_active_auto, _try, - pm_runtime_get_active(_T, RPM_TRANSPARENT)) + pm_runtime_get_active(_T, RPM_TRANSPARENT), _RET == 0)DEFINE_GUARD_COND (pm_runtime_active_auto, _try_enabled, -pm_runtime_resume_and_get (_T)) +pm_runtime_resume_and_get (_T), _RET ==0 )/** * pm_runtime_put_sync - Drop device usage counter and run "idle check" if 0.
Quoted 11 lines · On Mon, 20 Oct 2025 17:03:28 +0200 "Rafael J. Wysocki" <[email protected]>…
From: Rafael J. Wysocki <[email protected]>
Since
pm_runtime_get_active()returns 0 on success, all of theDEFINE_GUARD_COND()macros inpm_runtime.hneed the "_RET== 0" condition at the end of the argument list or they would not work correctly.Fixes 9a0abc39450a ("PM: runtime: Add auto-cleanup macros for "resume and get" operations")Reported-by kernel test robot <[email protected]>Signed-off-by Rafael J. Wysocki <[email protected]>
Makes sense.
These macros are a bit awkward to get right - I'd forgotten the oddity that conditional locks use != 0 to mean the lock was taken.
Quoted 27 lines
--- include/linux/pm_runtime.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)include/linux/pm_runtime.h +4
-4@@ -629,13 +629,13 @@ DEFINE_GUARD(pm_runtime_active_auto, str* device. */ DEFINE_GUARD_COND (pm_runtime_active, _try, - pm_runtime_get_active(_T, RPM_TRANSPARENT)) + pm_runtime_get_active(_T, RPM_TRANSPARENT), _RET == 0)DEFINE_GUARD_COND (pm_runtime_active, _try_enabled, - pm_runtime_resume_and_get(_T)) + pm_runtime_resume_and_get(_T), _RET == 0)DEFINE_GUARD_COND (pm_runtime_active_auto, _try, - pm_runtime_get_active(_T, RPM_TRANSPARENT)) + pm_runtime_get_active(_T, RPM_TRANSPARENT), _RET == 0)DEFINE_GUARD_COND (pm_runtime_active_auto, _try_enabled, -pm_runtime_resume_and_get (_T)) +pm_runtime_resume_and_get (_T), _RET ==0 )/** * pm_runtime_put_sync - Drop device usage counter and run "idle check" if 0.
Quoted 22 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
Since
pm_runtime_get_active()returns 0 on success, all of theDEFINE_GUARD_COND()macros inpm_runtime.hneed the "_RET== 0" condition at the end of the argument list or they would not work correctly.Fixes 9a0abc39450a ("PM: runtime: Add auto-cleanup macros for "resume and get" operations")Reported-by kernel test robot <[email protected]>Signed-off-by Rafael J. Wysocki <[email protected]>--- include/linux/pm_runtime.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)include/linux/pm_runtime.h +0
-1@@ -629,13 +629,13 @@ DEFINE_GUARD(pm_runtime_active_auto, str* device. */ DEFINE_GUARD_COND(pm_runtime_active, _try, -pm_runtime_get_active (_T,RPM_TRANSPARENT ))
include/linux/pm_runtime.h DEFINE_GUARD(pm_runtime_active_auto, str · line 638
Quoted 10 lines
include/linux/pm_runtime.h +4
-3+ pm_runtime_get_active(_T, RPM_TRANSPARENT), _RET == 0) DEFINE_GUARD_COND(pm_runtime_active, _try_enabled, - pm_runtime_resume_and_get(_T)) + pm_runtime_resume_and_get(_T), _RET == 0) DEFINE_GUARD_COND(pm_runtime_active_auto, _try, - pm_runtime_get_active(_T, RPM_TRANSPARENT)) + pm_runtime_get_active(_T, RPM_TRANSPARENT), _RET == 0)DEFINE_GUARD_COND (pm_runtime_active_auto, _try_enabled, -pm_runtime_resume_and_get (_T)) +pm_runtime_resume_and_get (_T), _RET ==0 )
I missed the detail that these are named "try" guards, but return "-error" on failure. In all the existing cases of "try" vs "conditional" acquire the polarity is different, e.g.:
DEFINE_GUARD_COND(rwsem_read, _try, down_read_trylock(_T)) DEFINE_GUARD_COND(rwsem_read, _intr, down_read_interruptible(_T), _RET == 0)
So, while this fix is correct, I wonder if a follow-on patch should change the naming..., but I cannot think of sufficient replacement.
Reminder for me to be vigilant about this detail moving forward:
Quoted 27 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
Since
pm_runtime_get_active()returns 0 on success, all of theDEFINE_GUARD_COND()macros inpm_runtime.hneed the "_RET== 0" condition at the end of the argument list or they would not work correctly.Fixes 9a0abc39450a ("PM: runtime: Add auto-cleanup macros for "resume and get" operations")Reported-by kernel test robot <[email protected]>Signed-off-by Rafael J. Wysocki <[email protected]>--- include/linux/pm_runtime.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)include/linux/pm_runtime.h +1
-2@@ -629,13 +629,13 @@ DEFINE_GUARD(pm_runtime_active_auto, str* device. */ DEFINE_GUARD_COND (pm_runtime_active, _try, - pm_runtime_get_active(_T, RPM_TRANSPARENT)) + pm_runtime_get_active(_T, RPM_TRANSPARENT), _RET == 0) DEFINE_GUARD_COND(pm_runtime_active, _try_enabled, -pm_runtime_resume_and_get (_T))
include/linux/pm_runtime.h DEFINE_GUARD(pm_runtime_active_auto, str · line 641
Quoted 10 lines
include/linux/pm_runtime.h +3
-2+ pm_runtime_resume_and_get(_T), _RET == 0) DEFINE_GUARD_COND(pm_runtime_active_auto, _try, - pm_runtime_get_active(_T, RPM_TRANSPARENT)) + pm_runtime_get_active(_T, RPM_TRANSPARENT), _RET == 0)DEFINE_GUARD_COND (pm_runtime_active_auto, _try_enabled, -pm_runtime_resume_and_get (_T)) +pm_runtime_resume_and_get (_T), _RET ==0 )/** * pm_runtime_put_sync - Drop device usage counter and run "idle check" if 0.
This does fix the issue for me mentioned here https://lore.kernel.org/all/[email protected]/
Feel free to add
Quoted 22 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
Since
pm_runtime_get_active()returns 0 on success, all of theDEFINE_GUARD_COND()macros inpm_runtime.hneed the "_RET== 0" condition at the end of the argument list or they would not work correctly.Fixes 9a0abc39450a ("PM: runtime: Add auto-cleanup macros for "resume and get" operations")Reported-by kernel test robot <[email protected]>Signed-off-by Rafael J. Wysocki <[email protected]>--- include/linux/pm_runtime.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)include/linux/pm_runtime.h +0
-1@@ -629,13 +629,13 @@ DEFINE_GUARD(pm_runtime_active_auto, str* device. */ DEFINE_GUARD_COND(pm_runtime_active, _try, -pm_runtime_get_active (_T,RPM_TRANSPARENT ))
include/linux/pm_runtime.h DEFINE_GUARD(pm_runtime_active_auto, str · line 638
Quoted 10 lines
include/linux/pm_runtime.h +4
-3+ pm_runtime_get_active(_T, RPM_TRANSPARENT), _RET == 0) DEFINE_GUARD_COND(pm_runtime_active, _try_enabled, - pm_runtime_resume_and_get(_T)) + pm_runtime_resume_and_get(_T), _RET == 0) DEFINE_GUARD_COND(pm_runtime_active_auto, _try, - pm_runtime_get_active(_T, RPM_TRANSPARENT)) + pm_runtime_get_active(_T, RPM_TRANSPARENT), _RET == 0)DEFINE_GUARD_COND (pm_runtime_active_auto, _try_enabled, -pm_runtime_resume_and_get (_T)) +pm_runtime_resume_and_get (_T), _RET ==0 )
The 3-argument form automatically assumes success, so we were essentially ignoring RET val. This seems correct now.
Best regards,
Dhruva Gole
Texas Instruments Incorporated