aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorGeorge G. Davis <george_davis@mentor.com>2019-09-17 14:40:22 -0400
committerShuah Khan <skhan@linuxfoundation.org>2019-10-02 15:44:04 -0400
commit8f9577eda5b74de4bd8b186c67f20736bdea6e07 (patch)
treedf13c48fa289201ac285fcec3ec8b7321f154c2e /tools
parent852c8cbf34d3b3130a05c38064dd98614f97d3a8 (diff)
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: a4864a33f56caa ("selftests: watchdog: Add optional file argument") 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> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
Diffstat (limited to 'tools')
-rw-r--r--tools/testing/selftests/watchdog/watchdog-test.c11
1 files changed, 11 insertions, 0 deletions
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[])
97 int c; 97 int c;
98 int oneshot = 0; 98 int oneshot = 0;
99 char *file = "/dev/watchdog"; 99 char *file = "/dev/watchdog";
100 struct watchdog_info info;
100 101
101 setbuf(stdout, NULL); 102 setbuf(stdout, NULL);
102 103
@@ -118,6 +119,16 @@ int main(int argc, char *argv[])
118 exit(-1); 119 exit(-1);
119 } 120 }
120 121
122 /*
123 * Validate that `file` is a watchdog device
124 */
125 ret = ioctl(fd, WDIOC_GETSUPPORT, &info);
126 if (ret) {
127 printf("WDIOC_GETSUPPORT error '%s'\n", strerror(errno));
128 close(fd);
129 exit(ret);
130 }
131
121 optind = 0; 132 optind = 0;
122 133
123 while ((c = getopt_long(argc, argv, sopts, lopts, NULL)) != -1) { 134 while ((c = getopt_long(argc, argv, sopts, lopts, NULL)) != -1) {