From a75748346692554f662003ffc4306c3e667783a9 Mon Sep 17 00:00:00 2001 From: Etienne Carriere Date: Wed, 18 Sep 2024 09:52:02 +0200 Subject: [PATCH] core: timeout_elapsed(): fix expiration threshold Fix timeout threshold that should return once the time expires, not 1 tick after it has expired. This change makes udelay(0) to immediately return and not wait a generic timer counter increment. This change fixes an issue where a driver stops the counter feeding Arm generic timer counter and indirectly calls IO_READ32_POLL_TIMEOUT() with a delay of 0us. It that case, since counter never increments, the udelay(0) call in IO_READ32_POLL_TIMEOUT() never returns while we expect the macro to endlessly poll (as timeout would never be detected) until poll condition is met or system watchdog is triggered. Signed-off-by: Etienne Carriere Acked-by: Jens Wiklander Reviewed-by: Jerome Forissier --- core/include/kernel/delay.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/include/kernel/delay.h b/core/include/kernel/delay.h index 312d3072c38..289d2140f64 100644 --- a/core/include/kernel/delay.h +++ b/core/include/kernel/delay.h @@ -52,7 +52,7 @@ static inline uint64_t timeout_init_us(uint32_t us) static inline bool timeout_elapsed(uint64_t expire) { - return delay_cnt_read() > expire; + return delay_cnt_read() >= expire; } /*