From 4a25772faab09f62d92da094f9d57824a1c2e82f Mon Sep 17 00:00:00 2001 From: Dong Wang Date: Thu, 2 Jan 2025 13:48:40 +0800 Subject: [PATCH] [nrf fromtree] kernel: timeout: ensure next timeout is set when aborting the first timeout Ref: NCSDK-31290 This ensures that the system clock is correctly updated when the first timeout is aborted, preventing unexpected early wake-up by the system clock programmed previously. Signed-off-by: Dong Wang (cherry picked from commit dd5f11cb04b834584a6d851fe55a9673e25a5356) --- kernel/timeout.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/kernel/timeout.c b/kernel/timeout.c index f751c2f20a5..c18f2e41d06 100644 --- a/kernel/timeout.c +++ b/kernel/timeout.c @@ -147,8 +147,13 @@ int z_abort_timeout(struct _timeout *to) K_SPINLOCK(&timeout_lock) { if (sys_dnode_is_linked(&to->node)) { + bool is_first = (to == first()); + remove_timeout(to); ret = 0; + if (is_first) { + sys_clock_set_timeout(next_timeout(), false); + } } }