From 42db096d284016b9352965ddabe82148e5d614e2 Mon Sep 17 00:00:00 2001 From: Peter Mitsis Date: Wed, 14 Dec 2022 11:53:58 -0500 Subject: [PATCH] kernel: resolve static analysis false positives At least one static analysis tool is flagging a potential NULL derefence in sys_clock_announce()'s tick processing loop where the routine 'first()' is concerned. In practice, this does not occur as ... 1. The code in question is protected by a spinlock. 2. 'first()' does not change the contents of anything. The code has consequently been tweaked to prevent similar such false positives in the future. Signed-off-by: Peter Mitsis --- kernel/timeout.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/kernel/timeout.c b/kernel/timeout.c index 7e0daee0641..85244a3df66 100644 --- a/kernel/timeout.c +++ b/kernel/timeout.c @@ -258,8 +258,11 @@ void sys_clock_announce(int32_t ticks) announce_remaining = ticks; - while (first() != NULL && first()->dticks <= announce_remaining) { - struct _timeout *t = first(); + struct _timeout *t = first(); + + for (t = first(); + (t != NULL) && (t->dticks <= announce_remaining); + t = first()) { int dt = t->dticks; curr_tick += dt; @@ -272,8 +275,8 @@ void sys_clock_announce(int32_t ticks) announce_remaining -= dt; } - if (first() != NULL) { - first()->dticks -= announce_remaining; + if (t != NULL) { + t->dticks -= announce_remaining; } curr_tick += announce_remaining;