Skip to content

Commit cabe17d

Browse files
westerirafaeljw
authored andcommitted
ACPI: watchdog: Set default timeout in probe
If the BIOS default timeout for the watchdog is too small userspace may not have enough time to configure new timeout after opening the device before the system is already reset. For this reason program default timeout of 30 seconds in the driver probe and allow userspace to change this from command line or through module parameter (wdat_wdt.timeout). Reported-by: Jean Delvare <[email protected]> Signed-off-by: Mika Westerberg <[email protected]> Reviewed-by: Jean Delvare <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 2ba33a4 commit cabe17d

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

drivers/watchdog/wdat_wdt.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ module_param(nowayout, bool, 0);
5454
MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
5555
__MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
5656

57+
#define WDAT_DEFAULT_TIMEOUT 30
58+
59+
static int timeout = WDAT_DEFAULT_TIMEOUT;
60+
module_param(timeout, int, 0);
61+
MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds (default="
62+
__MODULE_STRING(WDAT_DEFAULT_TIMEOUT) ")");
63+
5764
static int wdat_wdt_read(struct wdat_wdt *wdat,
5865
const struct wdat_instruction *instr, u32 *value)
5966
{
@@ -438,6 +445,22 @@ static int wdat_wdt_probe(struct platform_device *pdev)
438445

439446
platform_set_drvdata(pdev, wdat);
440447

448+
/*
449+
* Set initial timeout so that userspace has time to configure the
450+
* watchdog properly after it has opened the device. In some cases
451+
* the BIOS default is too short and causes immediate reboot.
452+
*/
453+
if (timeout * 1000 < wdat->wdd.min_hw_heartbeat_ms ||
454+
timeout * 1000 > wdat->wdd.max_hw_heartbeat_ms) {
455+
dev_warn(dev, "Invalid timeout %d given, using %d\n",
456+
timeout, WDAT_DEFAULT_TIMEOUT);
457+
timeout = WDAT_DEFAULT_TIMEOUT;
458+
}
459+
460+
ret = wdat_wdt_set_timeout(&wdat->wdd, timeout);
461+
if (ret)
462+
return ret;
463+
441464
watchdog_set_nowayout(&wdat->wdd, nowayout);
442465
return devm_watchdog_register_device(dev, &wdat->wdd);
443466
}

0 commit comments

Comments
 (0)