Skip to content

Commit 42db096

Browse files
peter-mitsisfabiobaltieri
authored andcommitted
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 <[email protected]>
1 parent 69cc659 commit 42db096

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

kernel/timeout.c

+7-4
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,11 @@ void sys_clock_announce(int32_t ticks)
258258

259259
announce_remaining = ticks;
260260

261-
while (first() != NULL && first()->dticks <= announce_remaining) {
262-
struct _timeout *t = first();
261+
struct _timeout *t = first();
262+
263+
for (t = first();
264+
(t != NULL) && (t->dticks <= announce_remaining);
265+
t = first()) {
263266
int dt = t->dticks;
264267

265268
curr_tick += dt;
@@ -272,8 +275,8 @@ void sys_clock_announce(int32_t ticks)
272275
announce_remaining -= dt;
273276
}
274277

275-
if (first() != NULL) {
276-
first()->dticks -= announce_remaining;
278+
if (t != NULL) {
279+
t->dticks -= announce_remaining;
277280
}
278281

279282
curr_tick += announce_remaining;

0 commit comments

Comments
 (0)