[PATCH] watchdog: airoha: validate heartbeat module parameter

Wayen Yan <[email protected]> Wed, 8 Jul 2026 13:24:37 +0800
Newsgroups org.kernel.vger.linux-watchdog,org.kernel.vger.linux-kernel
Message-ID <[email protected]>
The probe function directly assigns the heartbeat module parameter to
wdog_dev->timeout without any validation. If heartbeat exceeds
max_timeout, the product timeout * wdt_freq (computed in
airoha_wdt_start()) can overflow the 32-bit WDT_TIMER_LOAD_VALUE
register, causing the watchdog to expire immediately and reboot the
system.

Fix by using watchdog_init_timeout() which validates the timeout
against [min_timeout, max_timeout] range, and falls back to the
device tree "timeout-sec" property if the module parameter is invalid.

Fixes: 3cf67f3769b8 ("watchdog: Add support for Airoha EN7851 watchdog")
Signed-off-by: Wayen Yan <[email protected]>
---
 drivers/watchdog/airoha_wdt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/watchdog/airoha_wdt.c b/drivers/watchdog/airoha_wdt.c
index dc8ca11c14d8..67160d760d84 100644
--- a/drivers/watchdog/airoha_wdt.c
+++ b/drivers/watchdog/airoha_wdt.c
@@ -150,13 +150,13 @@ static int airoha_wdt_probe(struct platform_device *pdev)
 
 	/* Initialize struct watchdog device */
 	wdog_dev = &airoha_wdt->wdog_dev;
-	wdog_dev->timeout = heartbeat;
 	wdog_dev->info = &airoha_wdt_info;
 	wdog_dev->ops = &airoha_wdt_ops;
 	/* Bus 300MHz, watchdog 150MHz, 28 seconds */
 	wdog_dev->max_timeout = FIELD_MAX(WDT_TIMER_VAL) / airoha_wdt->wdt_freq;
 	wdog_dev->parent = dev;
 
+	watchdog_init_timeout(wdog_dev, heartbeat, dev);
 	watchdog_set_drvdata(wdog_dev, airoha_wdt);
 	watchdog_set_nowayout(wdog_dev, nowayout);
 	watchdog_stop_on_unregister(wdog_dev);
-- 
2.51.0