Skip to content

Commit 40efc43

Browse files
Ziyan FuWim Van Sebroeck
authored andcommitted
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 <[email protected]> Reviewed-by: Guenter Roeck <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Guenter Roeck <[email protected]> Signed-off-by: Wim Van Sebroeck <[email protected]>
1 parent 3b3643e commit 40efc43

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

drivers/watchdog/iTCO_wdt.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,11 @@ static int iTCO_wdt_probe(struct platform_device *pdev)
577577
/* Check that the heartbeat value is within it's range;
578578
if not reset to the default */
579579
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+
}
581585
dev_info(dev, "timeout value out of range, using %d\n",
582586
WATCHDOG_TIMEOUT);
583587
heartbeat = WATCHDOG_TIMEOUT;

0 commit comments

Comments
 (0)