Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

George G. Davis and committed by
Shuah Khan
8f9577ed 852c8cbf

+11
+11
tools/testing/selftests/watchdog/watchdog-test.c
··· 97 97 int c; 98 98 int oneshot = 0; 99 99 char *file = "/dev/watchdog"; 100 + struct watchdog_info info; 100 101 101 102 setbuf(stdout, NULL); 102 103 ··· 117 116 printf("Watchdog device open failed %s\n", 118 117 strerror(errno)); 119 118 exit(-1); 119 + } 120 + 121 + /* 122 + * Validate that `file` is a watchdog device 123 + */ 124 + ret = ioctl(fd, WDIOC_GETSUPPORT, &info); 125 + if (ret) { 126 + printf("WDIOC_GETSUPPORT error '%s'\n", strerror(errno)); 127 + close(fd); 128 + exit(ret); 120 129 } 121 130 122 131 optind = 0;