From e6339eac1a75a84b20c62f2f0d34a55a3d804112 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Thu, 20 Jan 2022 23:01:37 +0100 Subject: [PATCH] pm: policy: assert on unbalanced state lock get/put The state lock get/put calls should always be balanced: first call get and then put. Add an assertion in case lock counter is about to go negative, indicating a programming error. Signed-off-by: Gerard Marull-Paretas --- subsys/pm/policy.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/subsys/pm/policy.c b/subsys/pm/policy.c index 3e01fc9df24..13e218131e3 100644 --- a/subsys/pm/policy.c +++ b/subsys/pm/policy.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -51,7 +52,11 @@ void pm_policy_state_lock_get(enum pm_state state) void pm_policy_state_lock_put(enum pm_state state) { - atomic_dec(&state_lock_cnt[state]); + atomic_t cnt = atomic_dec(&state_lock_cnt[state]); + + ARG_UNUSED(cnt); + + __ASSERT(cnt >= 1, "Unbalanced state lock get/put"); } bool pm_policy_state_lock_is_active(enum pm_state state)