From: Corey Minyard <cminyard@xxxxxxxxxx> If the watchdog device wants to set it's pretimeout (say from module parameters), this lets them do that. Signed-off-by: Corey Minyard <cminyard@xxxxxxxxxx> --- drivers/watchdog/watchdog_dev.c | 54 +++++++++++++++++++++++++++++---- include/linux/watchdog.h | 4 +++ 2 files changed, 52 insertions(+), 6 deletions(-) diff --git a/drivers/watchdog/watchdog_dev.c b/drivers/watchdog/watchdog_dev.c index 45a0a4fe731d..6c423aed3f3c 100644 --- a/drivers/watchdog/watchdog_dev.c +++ b/drivers/watchdog/watchdog_dev.c @@ -364,14 +364,14 @@ static unsigned int watchdog_get_status(struct watchdog_device *wdd) } /* - * watchdog_set_timeout: set the watchdog timer timeout + * _watchdog_set_timeout: set the watchdog timer timeout * @wdd: the watchdog device to set the timeout for * @timeout: timeout to set in seconds * * The caller must hold wd_data->lock. */ -static int watchdog_set_timeout(struct watchdog_device *wdd, +static int _watchdog_set_timeout(struct watchdog_device *wdd, unsigned int timeout) { int err = 0; @@ -396,14 +396,35 @@ static int watchdog_set_timeout(struct watchdog_device *wdd, return err; } +/* + * watchdog_set_timeout: set the watchdog timer timeout + * @wdd: the watchdog device to set the timeout for + * @timeout: timeout to set in seconds + */ + +int watchdog_set_timeout(struct watchdog_device *wdd, unsigned int timeout) +{ + int err = 0; + + if (!wdd->wd_data) + return -ENODEV; + + mutex_lock(&wdd->wd_data->lock); + err = _watchdog_set_timeout(wdd, timeout); + mutex_unlock(&wdd->wd_data->lock); + + return err; +} +EXPORT_SYMBOL_GPL(watchdog_set_timeout); + /* * watchdog_set_pretimeout: set the watchdog timer pretimeout * @wdd: the watchdog device to set the timeout for * @timeout: pretimeout to set in seconds */ -static int watchdog_set_pretimeout(struct watchdog_device *wdd, - unsigned int timeout) +static int _watchdog_set_pretimeout(struct watchdog_device *wdd, + unsigned int timeout) { int err = 0; @@ -421,6 +442,27 @@ static int watchdog_set_pretimeout(struct watchdog_device *wdd, return err; } +/* + * watchdog_set_pretimeout: set the watchdog timer pretimeout + * @wdd: the watchdog device to set the timeout for + * @timeout: pretimeout to set in seconds + */ + +int watchdog_set_pretimeout(struct watchdog_device *wdd, unsigned int timeout) +{ + int err = 0; + + if (!wdd->wd_data) + return -ENODEV; + + mutex_lock(&wdd->wd_data->lock); + err = _watchdog_set_pretimeout(wdd, timeout); + mutex_unlock(&wdd->wd_data->lock); + + return err; +} +EXPORT_SYMBOL_GPL(watchdog_set_pretimeout); + /* * watchdog_get_timeleft: wrapper to get the time left before a reboot * @wdd: the watchdog device to get the remaining time from @@ -809,7 +851,7 @@ static long watchdog_ioctl(struct file *file, unsigned int cmd, err = -EFAULT; break; } - err = watchdog_set_timeout(wdd, val); + err = _watchdog_set_timeout(wdd, val); if (err < 0) break; /* If the watchdog is active then we send a keepalive ping @@ -838,7 +880,7 @@ static long watchdog_ioctl(struct file *file, unsigned int cmd, err = -EFAULT; break; } - err = watchdog_set_pretimeout(wdd, val); + err = _watchdog_set_pretimeout(wdd, val); break; case WDIOC_GETPRETIMEOUT: err = put_user(wdd->pretimeout, p); diff --git a/include/linux/watchdog.h b/include/linux/watchdog.h index 36f99c8c973e..95396b644a9b 100644 --- a/include/linux/watchdog.h +++ b/include/linux/watchdog.h @@ -201,6 +201,10 @@ static inline void *watchdog_get_drvdata(struct watchdog_device *wdd) return wdd->driver_data; } +/* Allow the driver to set the timeout and pretimeout. */ +int watchdog_set_timeout(struct watchdog_device *wdd, unsigned int timeout); +int watchdog_set_pretimeout(struct watchdog_device *wdd, unsigned int timeout); + /* Use the following functions to report watchdog pretimeout event */ #if IS_ENABLED(CONFIG_WATCHDOG_PRETIMEOUT_GOV) void watchdog_notify_pretimeout(struct watchdog_device *wdd); -- 2.17.1