From b46c32949eed11f87090fc7e03e69b36b86b7ab1 Mon Sep 17 00:00:00 2001 From: Serhiy Katsyuba Date: Mon, 14 Jul 2025 16:26:42 +0200 Subject: [PATCH] pm: Fix to prevent incorrect forever timeout K_TICKS_FOREVER is defined as -1. Guard logic has been added for the case when `ticks - exit_latency_ticks == -1` to prevent sys_clock_set_timeout() from incorrectly setting a forever timeout. Signed-off-by: Serhiy Katsyuba --- subsys/pm/pm.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/subsys/pm/pm.c b/subsys/pm/pm.c index 261fc01ca81dd..52a203437b913 100644 --- a/subsys/pm/pm.c +++ b/subsys/pm/pm.c @@ -199,8 +199,12 @@ bool pm_system_suspend(int32_t kernel_ticks) /* * We need to set the timer to interrupt a little bit early to * accommodate the time required by the CPU to fully wake up. + * + * Since K_TICKS_FOREVER is defined as -1, ensure that -1 + * is not passed as the next timeout. + * */ - sys_clock_set_timeout(ticks - exit_latency_ticks, true); + sys_clock_set_timeout(MAX(0, ticks - exit_latency_ticks), true); } /*