Skip to contentSkip to conversation

Generic Watchdog Timer Driver

PATCH Superseded Wim Van Sebroeck 2 participants 2 messages Jun 18, 2011

Subsystems (2)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 10/10 Generic Watchdog Timer Driver

watchdog: WatchDog Timer Driver Core - Part 10

Add min_timeout (minimum timeout) and max_timeout values so that the framework can check if the new timeout value is between the minimum and maximum timeout values. If both values are 0, then the framework will leave the check for the watchdog device driver itself.

Documentation/watchdog/watchdog-kernel-api.txt +4 -0
diff -urN linux-2.6.38-generic-part9/Documentation/watchdog/watchdog-kernel-api.txt linux-2.6.38-generic-partA/Documentation/watchdog/watchdog-kernel-api.txt
@@ -44,6 +44,8 @@
 	const struct watchdog_ops *ops;
 	struct device *parent;
 	int timeout;
+	int min_timeout;
+	int max_timeout;
 	int bootstatus;
 	long status;
 };
@@ -56,6 +58,8 @@
 * parent: a pointer to the parent device of the watchdog. This will be set
   as the parent of the misc device.
 * timeout: the watchdog timer's timeout value (in seconds).
+* min_timeout: the watchdog timer's minimum timeout value (in seconds).
+* max_timeout: the watchdog timer's maximum timeout value (in seconds).
 * bootstatus: status of the device after booting (reported with watchdog
   WDIOF_* status bits).
 * status: this field contains a number of status bits that give extra
drivers/watchdog/core/watchdog_core.c +7 -0
diff -urN linux-2.6.38-generic-part9/drivers/watchdog/core/watchdog_core.c linux-2.6.38-generic-partA/drivers/watchdog/core/watchdog_core.c
@@ -66,6 +66,13 @@
 	if (wdd->ops->start == NULL || wdd->ops->stop == NULL)
 		return -ENODATA;
 
+	/* Check that we have valid min and max timeout values, if
+	 * not reset them both to 0 (=not used or unknown) */
+	if (wdd->min_timeout > wdd->max_timeout) {
+		wdd->min_timeout = 0;
+		wdd->max_timeout = 0;
+	}
+
 	/* Note: now that all watchdog_device data has been verified, we
 	 * will not check this anymore in other functions. If data get's
 	 * corrupted in a later stage then we expect a kernel panic! */
drivers/watchdog/core/watchdog_dev.c +3 -0
diff -urN linux-2.6.38-generic-part9/drivers/watchdog/core/watchdog_dev.c linux-2.6.38-generic-partA/drivers/watchdog/core/watchdog_dev.c
@@ -250,6 +250,9 @@
 			return -EOPNOTSUPP;
 		if (get_user(val, p))
 			return -EFAULT;
+		if ((wdd->max_timeout != 0) &&
+		    (val < wdd->min_timeout || val > wdd->max_timeout))
+				return -EINVAL;
 		err = wdd->ops->set_timeout(wdd, val);
 		if (err < 0)
 			return err;
include/linux/watchdog.h +2 -0
diff -urN linux-2.6.38-generic-part9/include/linux/watchdog.h linux-2.6.38-generic-partA/include/linux/watchdog.h
@@ -83,6 +83,8 @@
 	struct device *parent;
 	int bootstatus;
 	int timeout;
+	int min_timeout;
+	int max_timeout;
 	long status;
 #define WDOG_ACTIVE		0	/* is the watchdog running/active */
 #define WDOG_DEV_OPEN		1	/* is the watchdog opened via
Acked-by on v2 10/10
#1 lore raw
Quoted 10 lines · On Saturday 18 June 2011 19:28:32 Wim Van Sebroeck wrote:

watchdog: WatchDog Timer Driver Core - Part 10

Add min_timeout (minimum timeout) and max_timeout values so that the framework can check if the new timeout value is between the minimum and maximum timeout values. If both values are 0, then the framework will leave the check for the watchdog device driver itself.

Quoted 2 lines