]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
util: fix warning of equal values on logical OR
authorLucas De Marchi <lucas.demarchi@intel.com>
Wed, 10 Aug 2016 15:42:12 +0000 (12:42 -0300)
committerLucas De Marchi <lucas.demarchi@intel.com>
Wed, 10 Aug 2016 15:45:36 +0000 (12:45 -0300)
shared/util.c: In function ‘read_str_safe’:
shared/util.c:211:24: warning: logical ‘or’ of equal expressions [-Wlogical-op]
    if (errno == EAGAIN || errno == EWOULDBLOCK ||
                        ^~
shared/util.c: In function ‘write_str_safe’:
shared/util.c:237:24: warning: logical ‘or’ of equal expressions [-Wlogical-op]
    if (errno == EAGAIN || errno == EWOULDBLOCK ||
                        ^~

This is because EAGAIN and EWOULDBLOCK have the same value. Prefer
EAGAIN, but add a static assert to catch if it's not the same in another
architecture.

shared/util.c
testsuite/test-testsuite.c

index 1a2b17cc6db9f1d0de2298f8def84761b2ec0834..9de080aabb18db3fd46dccc84f3e0e61e10df47c 100644 (file)
@@ -49,6 +49,8 @@ static const struct kmod_ext {
        { }
 };
 
+assert_cc(EAGAIN == EWOULDBLOCK);
+
 /* string handling functions and memory allocations                         */
 /* ************************************************************************ */
 
@@ -208,8 +210,7 @@ ssize_t read_str_safe(int fd, char *buf, size_t buflen)
                        todo -= r;
                        done += r;
                } else {
-                       if (errno == EAGAIN || errno == EWOULDBLOCK ||
-                                                               errno == EINTR)
+                       if (errno == EAGAIN || errno == EINTR)
                                continue;
                        else
                                return -errno;
@@ -234,8 +235,7 @@ ssize_t write_str_safe(int fd, const char *buf, size_t buflen)
                        todo -= r;
                        done += r;
                } else {
-                       if (errno == EAGAIN || errno == EWOULDBLOCK ||
-                                                               errno == EINTR)
+                       if (errno == EAGAIN || errno == EINTR)
                                continue;
                        else
                                return -errno;
index e6867b5047d39f1d0f965f17dbf5b2b9ffae8b5e..56e73609f2048e158d9ba84ba8b1aa748d4c2483 100644 (file)
@@ -97,7 +97,7 @@ static int testsuite_rootfs_open(const struct test *t)
                int r = read(fd, buf + done, sizeof(buf) - 1 - done);
                if (r == 0)
                        break;
-               if (r == -EWOULDBLOCK || r == -EAGAIN)
+               if (r == -EAGAIN)
                        continue;
 
                done += r;