Commit 8f9577ed authored by George G. Davis's avatar George G. Davis Committed by Shuah Khan

selftests: watchdog: Validate optional file argument

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.

Fixes: a4864a33 ("selftests: watchdog: Add optional file argument")
Reported-by: default avatarEugeniu Rosca <erosca@de.adit-jv.com>
Signed-off-by: default avatarGeorge G. Davis <george_davis@mentor.com>
Signed-off-by: default avatarEugeniu Rosca <erosca@de.adit-jv.com>
Signed-off-by: default avatarShuah Khan <skhan@linuxfoundation.org>
parent 852c8cbf
...@@ -97,6 +97,7 @@ int main(int argc, char *argv[]) ...@@ -97,6 +97,7 @@ int main(int argc, char *argv[])
int c; int c;
int oneshot = 0; int oneshot = 0;
char *file = "/dev/watchdog"; char *file = "/dev/watchdog";
struct watchdog_info info;
setbuf(stdout, NULL); setbuf(stdout, NULL);
...@@ -118,6 +119,16 @@ int main(int argc, char *argv[]) ...@@ -118,6 +119,16 @@ int main(int argc, char *argv[])
exit(-1); 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; optind = 0;
while ((c = getopt_long(argc, argv, sopts, lopts, NULL)) != -1) { while ((c = getopt_long(argc, argv, sopts, lopts, NULL)) != -1) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment