This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 635de19a7b8026271c7c0bc72657acac5891510d Author: ouyangxiangzhen <[email protected]> AuthorDate: Thu Feb 26 10:43:26 2026 +0800 sched/wdog: Avoid the multiplication overflow. This commit avoided the multiplication overflow in wdog when CONFIG_HRTIMER is enabled. Assisted-By: mimo-v2.6-pro Signed-off-by: ouyangxiangzhen <[email protected]> --- sched/wdog/wdog.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/sched/wdog/wdog.h b/sched/wdog/wdog.h index c7139105c9e..78ce793ecfc 100644 --- a/sched/wdog/wdog.h +++ b/sched/wdog/wdog.h @@ -124,11 +124,14 @@ uint64_t wd_timer(const hrtimer_t *timer, uint64_t expired); #ifdef CONFIG_HRTIMER static inline_function void wd_timer_start(clock_t tick, bool in_expiration) { - DEBUGASSERT(tick <= INT64_MAX / NSEC_PER_TICK); if (!in_expiration) { - hrtimer_start(&g_wdtimer, wd_timer, - TICK2NSEC(tick), HRTIMER_MODE_ABS); + clock_t interval = clock_compare(g_wdexpired, tick) ? + tick - g_wdexpired : 0; + uint64_t nsec = interval <= HRTIMER_MAX_DELAY / NSEC_PER_TICK ? + TICK2NSEC(g_wdexpired + interval) : + TICK2NSEC(g_wdexpired) + HRTIMER_MAX_DELAY; + hrtimer_start(&g_wdtimer, wd_timer, nsec, HRTIMER_MODE_ABS); } }
