Skip to content

Commit

Permalink
kernel: resolve static analysis false positives
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
peter-mitsis authored and fabiobaltieri committed Jan 5, 2023
1 parent 69cc659 commit 42db096
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions kernel/timeout.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 42db096

Please sign in to comment.