linux-kselftest.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] selftests: watchdog: Validate optional file argument
@ 2019-09-07  8:58 Eugeniu Rosca
  2019-09-07  8:58 ` [PATCH 2/2] selftests: watchdog: Add command line option to show watchdog_info Eugeniu Rosca
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Eugeniu Rosca @ 2019-09-07  8:58 UTC (permalink / raw)
  To: Shuah Khan, George G. Davis, Jerry Hoemann, Colin Ian King,
	linux-kselftest, linux-kernel
  Cc: Eugeniu Rosca, Eugeniu Rosca

From: "George G. Davis" <george_davis@mentor.com>

As reported by Eugeniu Rosca, the newly added optional file
argument does not validate if the file is indeed a watchdog, e.g.:

./watchdog-test  -f /dev/zero
Watchdog Ticking Away!

Fix it by confirming that the WDIOC_GETSUPPORT ioctl succeeds.

Reported-by: Eugeniu Rosca <erosca@de.adit-jv.com>
Signed-off-by: George G. Davis <george_davis@mentor.com>
Signed-off-by: Eugeniu Rosca <erosca@de.adit-jv.com>
---
v1: Applied/tested on commit ce54eab71e210f ("kunit: fix failure to build without printk") of
    https://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest.git/log/?h=next

 tools/testing/selftests/watchdog/watchdog-test.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/tools/testing/selftests/watchdog/watchdog-test.c b/tools/testing/selftests/watchdog/watchdog-test.c
index afff120c7be6..6ed822dc2222 100644
--- a/tools/testing/selftests/watchdog/watchdog-test.c
+++ b/tools/testing/selftests/watchdog/watchdog-test.c
@@ -97,6 +97,7 @@ int main(int argc, char *argv[])
 	int c;
 	int oneshot = 0;
 	char *file = "/dev/watchdog";
+	struct watchdog_info info;
 
 	setbuf(stdout, NULL);
 
@@ -118,6 +119,16 @@ int main(int argc, char *argv[])
 		exit(-1);
 	}
 
+	/*
+	 * Validate that `file` is a watchdog device
+	 */
+	ret = ioctl(fd, WDIOC_GETSUPPORT, &info);
+	if (ret) {
+		printf("WDIOC_GETSUPPORT error '%s'\n", strerror(errno));
+		close(fd);
+		exit(ret);
+	}
+
 	optind = 0;
 
 	while ((c = getopt_long(argc, argv, sopts, lopts, NULL)) != -1) {
-- 
2.23.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2019-09-17 18:55 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-07  8:58 [PATCH 1/2] selftests: watchdog: Validate optional file argument Eugeniu Rosca
2019-09-07  8:58 ` [PATCH 2/2] selftests: watchdog: Add command line option to show watchdog_info Eugeniu Rosca
2019-09-16 13:26   ` shuah
2019-09-16 13:55     ` George G. Davis
2019-09-16 13:57     ` Eugeniu Rosca
2019-09-16 16:05       ` shuah
2019-09-16 16:15         ` George G. Davis
2019-09-17 18:53           ` Eugeniu Rosca
2019-09-16 12:08 ` [PATCH 1/2] selftests: watchdog: Validate optional file argument Eugeniu Rosca
2019-09-16 13:29   ` shuah
2019-09-17 18:55     ` Eugeniu Rosca
2019-09-16 13:25 ` shuah

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).