From: Eugeniu Rosca <erosca@de.adit-jv.com>
To: Shuah Khan <shuah@kernel.org>,
"George G. Davis" <george_davis@mentor.com>,
Jerry Hoemann <jerry.hoemann@hpe.com>,
Colin Ian King <colin.king@canonical.com>,
<linux-kselftest@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Cc: Eugeniu Rosca <erosca@de.adit-jv.com>,
Eugeniu Rosca <roscaeugeniu@gmail.com>
Subject: [PATCH v3 1/2] selftests: watchdog: Validate optional file argument
Date: Tue, 17 Sep 2019 20:40:22 +0200 [thread overview]
Message-ID: <20190917184023.16701-1-erosca@de.adit-jv.com> (raw)
From: "George G. Davis" <george_davis@mentor.com>
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: c3f2490d6e9257 ("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>
---
v3:
- Used v1 as starting point and simplified commit description
- Added Fixes tag (WARNING: commit id is from linux-next!)
- No change in the contents
- Applied cleanly to the same base as used in [v1]
v2:
- https://patchwork.kernel.org/patch/11147663/
v1:
- https://patchwork.kernel.org/patch/11136283/
- 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
next reply other threads:[~2019-09-17 18:40 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-17 18:40 Eugeniu Rosca [this message]
2019-09-17 18:40 ` [PATCH v3 2/2] selftests: watchdog: Add command line option to show watchdog_info Eugeniu Rosca
2019-09-18 11:33 ` [PATCH v3 1/2] selftests: watchdog: Validate optional file argument Eugeniu Rosca
2019-09-18 21:05 ` shuah
2019-09-19 9:50 ` Eugeniu Rosca
[not found] ` <156996250317.31379.1299334144215961607.git-patchwork-notify@kernel.org>
2019-10-02 10:41 ` Eugeniu Rosca
2019-10-02 19:48 ` shuah
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190917184023.16701-1-erosca@de.adit-jv.com \
--to=erosca@de.adit-jv.com \
--cc=colin.king@canonical.com \
--cc=george_davis@mentor.com \
--cc=jerry.hoemann@hpe.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=roscaeugeniu@gmail.com \
--cc=shuah@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).