linux-modules.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Joel Stanley <joel@jms.id.au>
To: linux-modules@vger.kernel.org
Cc: Stewart Smith <stewart@linux.vnet.ibm.com>
Subject: [PATCH kmod] util: fix non-static assert_cc use
Date: Wed,  7 Jun 2017 15:48:11 +0930	[thread overview]
Message-ID: <20170607061811.4016-1-joel@jms.id.au> (raw)

In commit a6ede6c7ad46 (util: fix warning of equal values on logical OR)
the runtime check for EAGAIN and EWOULDBLOCK being equal was converted
into an assert.

For the case where the compiler supports _Static_assert, this is can be
called staticly. However the fallback for older compilers uses a
non-static test that needs to be called from a function context.

Move the assert into the functions that used to have the runtime check.
The test does not add any runtime overhead, so it is fine to duplicate
it.

Tested with and without HAVE_STATIC_ASSERT defined using GCC 6.3.

Signed-off-by: Joel Stanley <joel@jms.id.au>
---
 shared/util.c              | 4 ++--
 testsuite/test-testsuite.c | 1 +
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/shared/util.c b/shared/util.c
index 9de080aabb18..c402953b4699 100644
--- a/shared/util.c
+++ b/shared/util.c
@@ -49,8 +49,6 @@ static const struct kmod_ext {
 	{ }
 };
 
-assert_cc(EAGAIN == EWOULDBLOCK);
-
 /* string handling functions and memory allocations                         */
 /* ************************************************************************ */
 
@@ -200,6 +198,7 @@ ssize_t read_str_safe(int fd, char *buf, size_t buflen)
 {
 	size_t todo = buflen - 1;
 	size_t done = 0;
+	assert_cc(EAGAIN == EWOULDBLOCK);
 
 	do {
 		ssize_t r = read(fd, buf + done, todo);
@@ -225,6 +224,7 @@ ssize_t write_str_safe(int fd, const char *buf, size_t buflen)
 {
 	size_t todo = buflen;
 	size_t done = 0;
+	assert_cc(EAGAIN == EWOULDBLOCK);
 
 	do {
 		ssize_t r = write(fd, buf + done, todo);
diff --git a/testsuite/test-testsuite.c b/testsuite/test-testsuite.c
index 56e73609f204..5bafc6551a23 100644
--- a/testsuite/test-testsuite.c
+++ b/testsuite/test-testsuite.c
@@ -88,6 +88,7 @@ static int testsuite_rootfs_open(const struct test *t)
 {
 	char buf[100];
 	int fd, done;
+	assert_cc(EAGAIN == EWOULDBLOCK);
 
 	fd = open("/lib/modules/a", O_RDONLY);
 	if (fd < 0)
-- 
2.11.0


             reply	other threads:[~2017-06-07  6:18 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-07  6:18 Joel Stanley [this message]
2017-06-07 12:00 ` [PATCH kmod] util: fix non-static assert_cc use Joel Stanley
2017-06-08 23:08   ` Lucas De Marchi
2017-06-09  5:10     ` Joel Stanley

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=20170607061811.4016-1-joel@jms.id.au \
    --to=joel@jms.id.au \
    --cc=linux-modules@vger.kernel.org \
    --cc=stewart@linux.vnet.ibm.com \
    /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).