From 88b509e56de7df84a636382625ada466b78ecd4c Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Thu, 22 Apr 2021 11:06:04 +0200 Subject: [PATCH] ztimer: correctly unset timer->next (fix ztimer_is_set()) ztimer's machinery depends on figuring out if a timer is currently set or not. It does that using _is_set(), which is also exposed as ztimer_is_set(). Now when a timer expired and got taken of the timer queue using _now_next(), the `next` pointer wasn't unset. This caused _is_set() to wrongly return `true` for that timer. Internally in ztimer, this didn't cause breakage, just an unnecessary iteration of the timer queue by _delete_timer_from_list(). But this also broke the public ztimer_is_set(). This commit fixes the issue by correctly NULLing the timer's `next` pointer when the timer triggers. --- sys/ztimer/core.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sys/ztimer/core.c b/sys/ztimer/core.c index 23ad22cebb9a..d0c78ee92955 100644 --- a/sys/ztimer/core.c +++ b/sys/ztimer/core.c @@ -281,6 +281,10 @@ static ztimer_t *_now_next(ztimer_clock_t *clock) } #endif } + else { + /* reset next pointer so ztimer_is_set() works */ + entry->next = NULL; + } return (ztimer_t *)entry; } else {