posix_types.h: Cleanup stale __NFDBITS and related definitions
authorJosh Boyer <jwboyer@redhat.com>
Wed, 25 Jul 2012 14:40:34 +0000 (10:40 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 9 Aug 2012 15:31:39 +0000 (08:31 -0700)
commit 8ded2bbc1845e19c771eb55209aab166ef011243 upstream.

Recently, glibc made a change to suppress sign-conversion warnings in
FD_SET (glibc commit ceb9e56b3d1).  This uncovered an issue with the
kernel's definition of __NFDBITS if applications #include
<linux/types.h> after including <sys/select.h>.  A build failure would
be seen when passing the -Werror=sign-compare and -D_FORTIFY_SOURCE=2
flags to gcc.

It was suggested that the kernel should either match the glibc
definition of __NFDBITS or remove that entirely.  The current in-kernel
uses of __NFDBITS can be replaced with BITS_PER_LONG, and there are no
uses of the related __FDELT and __FDMASK defines.  Given that, we'll
continue the cleanup that was started with commit 8b3d1cda4f5f
("posix_types: Remove fd_set macros") and drop the remaining unused
macros.

Additionally, linux/time.h has similar macros defined that expand to
nothing so we'll remove those at the same time.

Reported-by: Jeff Law <law@redhat.com>
Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Josh Boyer <jwboyer@redhat.com>
[ .. and fix up whitespace as per akpm ]
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
arch/mips/kernel/kspd.c
fs/exec.c
fs/select.c
include/linux/posix_types.h
include/linux/time.h
kernel/exit.c
security/selinux/hooks.c

index 84d0639e4580230c78fc93207943700bc35ac007..b77f56bbb477eca591052bf87d5fe8bf6bc62f5a 100644 (file)
@@ -323,7 +323,7 @@ static void sp_cleanup(void)
        fdt = files_fdtable(files);
        for (;;) {
                unsigned long set;
-               i = j * __NFDBITS;
+               i = j * BITS_PER_LONG;
                if (i >= fdt->max_fds)
                        break;
                set = fdt->open_fds[j++];
index 29e5f840544fb2b0311a4bea3059788c8f4c15f4..126e01cb24345faaa3f448a45cce4b3a8a6c1bdc 100644 (file)
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -1024,7 +1024,7 @@ static void flush_old_files(struct files_struct * files)
                unsigned long set, i;
 
                j++;
-               i = j * __NFDBITS;
+               i = j * BITS_PER_LONG;
                fdt = files_fdtable(files);
                if (i >= fdt->max_fds)
                        break;
index 17d33d09fc16f4843c72f9c7444dfdb3fb738952..0baa0a351a1cf53d5d5b2b6b34eaafefd457cf51 100644 (file)
@@ -345,8 +345,8 @@ static int max_select_fd(unsigned long n, fd_set_bits *fds)
        struct fdtable *fdt;
 
        /* handle last in-complete long-word first */
-       set = ~(~0UL << (n & (__NFDBITS-1)));
-       n /= __NFDBITS;
+       set = ~(~0UL << (n & (BITS_PER_LONG-1)));
+       n /= BITS_PER_LONG;
        fdt = files_fdtable(current->files);
        open_fds = fdt->open_fds + n;
        max = 0;
@@ -373,7 +373,7 @@ get_max:
                        max++;
                        set >>= 1;
                } while (set);
-               max += n * __NFDBITS;
+               max += n * BITS_PER_LONG;
        }
 
        return max;
@@ -435,11 +435,11 @@ int do_select(int n, fd_set_bits *fds, struct timespec *end_time)
                        in = *inp++; out = *outp++; ex = *exp++;
                        all_bits = in | out | ex;
                        if (all_bits == 0) {
-                               i += __NFDBITS;
+                               i += BITS_PER_LONG;
                                continue;
                        }
 
-                       for (j = 0; j < __NFDBITS; ++j, ++i, bit <<= 1) {
+                       for (j = 0; j < BITS_PER_LONG; ++j, ++i, bit <<= 1) {
                                int fput_needed;
                                if (i >= n)
                                        break;
index f04c98cf44f36376321d507d1fcd3352b26c4852..988f76e636e36912052b4d951173b304a07f476a 100644 (file)
  */
 
 /*
- * Those macros may have been defined in <gnu/types.h>. But we always
- * use the ones here. 
+ * This macro may have been defined in <gnu/types.h>. But we always
+ * use the one here.
  */
-#undef __NFDBITS
-#define __NFDBITS      (8 * sizeof(unsigned long))
-
 #undef __FD_SETSIZE
 #define __FD_SETSIZE   1024
 
-#undef __FDSET_LONGS
-#define __FDSET_LONGS  (__FD_SETSIZE/__NFDBITS)
-
-#undef __FDELT
-#define        __FDELT(d)      ((d) / __NFDBITS)
-
-#undef __FDMASK
-#define        __FDMASK(d)     (1UL << ((d) % __NFDBITS))
-
 typedef struct {
-       unsigned long fds_bits [__FDSET_LONGS];
+       unsigned long fds_bits[__FD_SETSIZE / (8 * sizeof(long))];
 } __kernel_fd_set;
 
 /* Type of a signal handler.  */
index 33a92ead4d88163fce7b12d236c56dfd1772d379..8da51299a7d5ad5b31ae85b347a24725a1341952 100644 (file)
@@ -258,14 +258,6 @@ static __always_inline void timespec_add_ns(struct timespec *a, u64 ns)
 
 #endif /* __KERNEL__ */
 
-#define NFDBITS                        __NFDBITS
-
-#define FD_SETSIZE             __FD_SETSIZE
-#define FD_SET(fd,fdsetp)      __FD_SET(fd,fdsetp)
-#define FD_CLR(fd,fdsetp)      __FD_CLR(fd,fdsetp)
-#define FD_ISSET(fd,fdsetp)    __FD_ISSET(fd,fdsetp)
-#define FD_ZERO(fdsetp)                __FD_ZERO(fdsetp)
-
 /*
  * Names of the interval timers, and structure
  * defining a timer setting:
index 9d81012290e3e6692f1b6a03fd16ea550307d62e..bfbd856696941f170304b3e0bba34abe72a1dbe6 100644 (file)
@@ -471,7 +471,7 @@ static void close_files(struct files_struct * files)
        rcu_read_unlock();
        for (;;) {
                unsigned long set;
-               i = j * __NFDBITS;
+               i = j * BITS_PER_LONG;
                if (i >= fdt->max_fds)
                        break;
                set = fdt->open_fds[j++];
index d85b793c9321c5866a2f6bd2ce60cb5aaff42e17..56262223190df128ffe5711d4d21bdcc27cad3e3 100644 (file)
@@ -2162,7 +2162,7 @@ static inline void flush_unauthorized_files(const struct cred *cred,
                int fd;
 
                j++;
-               i = j * __NFDBITS;
+               i = j * BITS_PER_LONG;
                fdt = files_fdtable(files);
                if (i >= fdt->max_fds)
                        break;