Skip to content

Commit d000e07

Browse files
author
Al Viro
committed
convert do_select()
take the logics from fdget() to fdput() into an inlined helper - with existing wait_key_set() subsumed into that. Reviewed-by: Christian Brauner <[email protected]> Signed-off-by: Al Viro <[email protected]>
1 parent 6b1a5ae commit d000e07

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

fs/select.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -462,15 +462,22 @@ static int max_select_fd(unsigned long n, fd_set_bits *fds)
462462
EPOLLNVAL)
463463
#define POLLEX_SET (EPOLLPRI | EPOLLNVAL)
464464

465-
static inline void wait_key_set(poll_table *wait, unsigned long in,
465+
static inline __poll_t select_poll_one(int fd, poll_table *wait, unsigned long in,
466466
unsigned long out, unsigned long bit,
467467
__poll_t ll_flag)
468468
{
469+
CLASS(fd, f)(fd);
470+
471+
if (fd_empty(f))
472+
return EPOLLNVAL;
473+
469474
wait->_key = POLLEX_SET | ll_flag;
470475
if (in & bit)
471476
wait->_key |= POLLIN_SET;
472477
if (out & bit)
473478
wait->_key |= POLLOUT_SET;
479+
480+
return vfs_poll(fd_file(f), wait);
474481
}
475482

476483
static noinline_for_stack int do_select(int n, fd_set_bits *fds, struct timespec64 *end_time)
@@ -522,20 +529,12 @@ static noinline_for_stack int do_select(int n, fd_set_bits *fds, struct timespec
522529
}
523530

524531
for (j = 0; j < BITS_PER_LONG; ++j, ++i, bit <<= 1) {
525-
struct fd f;
526532
if (i >= n)
527533
break;
528534
if (!(bit & all_bits))
529535
continue;
530-
mask = EPOLLNVAL;
531-
f = fdget(i);
532-
if (fd_file(f)) {
533-
wait_key_set(wait, in, out, bit,
534-
busy_flag);
535-
mask = vfs_poll(fd_file(f), wait);
536-
537-
fdput(f);
538-
}
536+
mask = select_poll_one(i, wait, in, out, bit,
537+
busy_flag);
539538
if ((mask & POLLIN_SET) && (in & bit)) {
540539
res_in |= bit;
541540
retval++;

0 commit comments

Comments
 (0)