Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

watchdog: iTCO_wdt: Report error if timeout configuration fails

The driver probes with the invalid timeout value when
'iTCO_wdt_set_timeout()' fails, as its return value is not checked. In
this case, when executing "wdctl", we may get:

Device: /dev/watchdog0
Timeout: 30 seconds
Timeleft: 613 seconds

The timeout value is the value of "heartbeat" or "WATCHDOG_TIMEOUT", and
the timeleft value is calculated from the register value we actually read
(0xffff) by masking with 0x3ff and converting ticks to seconds (* 6 / 10).

Add error handling to return the failure code if 'iTCO_wdt_set_timeout()'
fails, ensuring the driver probe fails and prevents invalid operation.

Signed-off-by: Ziyan Fu <fuzy5@lenovo.com>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Link: https://lore.kernel.org/r/20250704073518.7838-1-13281011316@163.com
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@linux-watchdog.org>

authored by

Ziyan Fu and committed by
Wim Van Sebroeck
40efc43e 3b3643e1

+5 -1
+5 -1
drivers/watchdog/iTCO_wdt.c
··· 577 577 /* Check that the heartbeat value is within it's range; 578 578 if not reset to the default */ 579 579 if (iTCO_wdt_set_timeout(&p->wddev, heartbeat)) { 580 - iTCO_wdt_set_timeout(&p->wddev, WATCHDOG_TIMEOUT); 580 + ret = iTCO_wdt_set_timeout(&p->wddev, WATCHDOG_TIMEOUT); 581 + if (ret != 0) { 582 + dev_err(dev, "Failed to set watchdog timeout (%d)\n", WATCHDOG_TIMEOUT); 583 + return ret; 584 + } 581 585 dev_info(dev, "timeout value out of range, using %d\n", 582 586 WATCHDOG_TIMEOUT); 583 587 heartbeat = WATCHDOG_TIMEOUT;