From e8cea8fe67bd1f087dcc28dd882afb8eef7bc70b Mon Sep 17 00:00:00 2001 From: Simon Xue Date: Wed, 15 Nov 2023 17:34:21 +0800 Subject: [PATCH] watchdog: dw_wdt: fix array out-of-bounds in theory Change-Id: Ie11b60cf79b4c988af1ca7939334cbb742582247 Signed-off-by: Simon Xue --- drivers/watchdog/dw_wdt.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/watchdog/dw_wdt.c b/drivers/watchdog/dw_wdt.c index 3cd118281980..2d261b5518c9 100644 --- a/drivers/watchdog/dw_wdt.c +++ b/drivers/watchdog/dw_wdt.c @@ -156,6 +156,10 @@ static unsigned int dw_wdt_get_min_timeout(struct dw_wdt *dw_wdt) break; } + /* For Coverity check */ + if (idx == DW_WDT_NUM_TOPS) + idx = 0; + return dw_wdt->timeouts[idx].sec; } @@ -179,6 +183,9 @@ static unsigned int dw_wdt_get_timeout(struct dw_wdt *dw_wdt) break; } + if (idx == DW_WDT_NUM_TOPS) + idx = 0; + /* * In IRQ mode due to the two stages counter, the actual timeout is * twice greater than the TOP setting.