Skip to content

Commit 8ded2bb

Browse files
jwboyertorvalds
authored andcommitted
posix_types.h: Cleanup stale __NFDBITS and related definitions
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 8b3d1cd ("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> CC: <stable@vger.kernel.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>
1 parent 4cb3875 commit 8ded2bb

7 files changed

Lines changed: 12 additions & 32 deletions

File tree

‎arch/mips/kernel/kspd.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ static void sp_cleanup(void)
323323
fdt = files_fdtable(files);
324324
for (;;) {
325325
unsigned long set;
326-
i = j * __NFDBITS;
326+
i = j * BITS_PER_LONG;
327327
if (i >= fdt->max_fds)
328328
break;
329329
set = fdt->open_fds[j++];

‎fs/exec.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1020,7 +1020,7 @@ static void flush_old_files(struct files_struct * files)
10201020
unsigned long set, i;
10211021

10221022
j++;
1023-
i = j * __NFDBITS;
1023+
i = j * BITS_PER_LONG;
10241024
fdt = files_fdtable(files);
10251025
if (i >= fdt->max_fds)
10261026
break;

‎fs/select.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,8 @@ static int max_select_fd(unsigned long n, fd_set_bits *fds)
345345
struct fdtable *fdt;
346346

347347
/* handle last in-complete long-word first */
348-
set = ~(~0UL << (n & (__NFDBITS-1)));
349-
n /= __NFDBITS;
348+
set = ~(~0UL << (n & (BITS_PER_LONG-1)));
349+
n /= BITS_PER_LONG;
350350
fdt = files_fdtable(current->files);
351351
open_fds = fdt->open_fds + n;
352352
max = 0;
@@ -373,7 +373,7 @@ static int max_select_fd(unsigned long n, fd_set_bits *fds)
373373
max++;
374374
set >>= 1;
375375
} while (set);
376-
max += n * __NFDBITS;
376+
max += n * BITS_PER_LONG;
377377
}
378378

379379
return max;
@@ -435,11 +435,11 @@ int do_select(int n, fd_set_bits *fds, struct timespec *end_time)
435435
in = *inp++; out = *outp++; ex = *exp++;
436436
all_bits = in | out | ex;
437437
if (all_bits == 0) {
438-
i += __NFDBITS;
438+
i += BITS_PER_LONG;
439439
continue;
440440
}
441441

442-
for (j = 0; j < __NFDBITS; ++j, ++i, bit <<= 1) {
442+
for (j = 0; j < BITS_PER_LONG; ++j, ++i, bit <<= 1) {
443443
int fput_needed;
444444
if (i >= n)
445445
break;

‎include/linux/posix_types.h‎

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,14 @@
1515
*/
1616

1717
/*
18-
* Those macros may have been defined in <gnu/types.h>. But we always
19-
* use the ones here.
18+
* This macro may have been defined in <gnu/types.h>. But we always
19+
* use the one here.
2020
*/
21-
#undef __NFDBITS
22-
#define __NFDBITS (8 * sizeof(unsigned long))
23-
2421
#undef __FD_SETSIZE
2522
#define __FD_SETSIZE 1024
2623

27-
#undef __FDSET_LONGS
28-
#define __FDSET_LONGS (__FD_SETSIZE/__NFDBITS)
29-
30-
#undef __FDELT
31-
#define __FDELT(d) ((d) / __NFDBITS)
32-
33-
#undef __FDMASK
34-
#define __FDMASK(d) (1UL << ((d) % __NFDBITS))
35-
3624
typedef struct {
37-
unsigned long fds_bits [__FDSET_LONGS];
25+
unsigned long fds_bits[__FD_SETSIZE / (8 * sizeof(long))];
3826
} __kernel_fd_set;
3927

4028
/* Type of a signal handler. */

‎include/linux/time.h‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -257,14 +257,6 @@ static __always_inline void timespec_add_ns(struct timespec *a, u64 ns)
257257

258258
#endif /* __KERNEL__ */
259259

260-
#define NFDBITS __NFDBITS
261-
262-
#define FD_SETSIZE __FD_SETSIZE
263-
#define FD_SET(fd,fdsetp) __FD_SET(fd,fdsetp)
264-
#define FD_CLR(fd,fdsetp) __FD_CLR(fd,fdsetp)
265-
#define FD_ISSET(fd,fdsetp) __FD_ISSET(fd,fdsetp)
266-
#define FD_ZERO(fdsetp) __FD_ZERO(fdsetp)
267-
268260
/*
269261
* Names of the interval timers, and structure
270262
* defining a timer setting:

‎kernel/exit.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ static void close_files(struct files_struct * files)
483483
rcu_read_unlock();
484484
for (;;) {
485485
unsigned long set;
486-
i = j * __NFDBITS;
486+
i = j * BITS_PER_LONG;
487487
if (i >= fdt->max_fds)
488488
break;
489489
set = fdt->open_fds[j++];

‎security/selinux/hooks.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2129,7 +2129,7 @@ static inline void flush_unauthorized_files(const struct cred *cred,
21292129
int fd;
21302130

21312131
j++;
2132-
i = j * __NFDBITS;
2132+
i = j * BITS_PER_LONG;
21332133
fdt = files_fdtable(files);
21342134
if (i >= fdt->max_fds)
21352135
break;

0 commit comments

Comments
 (0)