Skip to content

Commit 1c52cff

Browse files
committed
kernel: Add assert to detect negative timeouts
Add assert when negative (except K_FOREVER) is passed as timeout. Add negative timeout correction to 0. Signed-off-by: Krzysztof Chruscinski <[email protected]>
1 parent af96694 commit 1c52cff

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

kernel/sched.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,16 @@ static void pend(struct k_thread *thread, _wait_q_t *wait_q, s32_t timeout)
368368
}
369369

370370
if (timeout != K_FOREVER) {
371-
s32_t ticks = _TICK_ALIGN + k_ms_to_ticks_ceil32(timeout);
371+
s32_t ticks;
372+
373+
__ASSERT(timeout >= 0,
374+
"Only non-negative values are accepted.");
375+
376+
if (timeout < 0) {
377+
timeout = 0;
378+
}
379+
380+
ticks = _TICK_ALIGN + k_ms_to_ticks_ceil32(timeout);
372381

373382
z_add_thread_timeout(thread, ticks);
374383
}

0 commit comments

Comments
 (0)