Skip to content

Commit 8935989

Browse files
author
Al Viro
committed
do_pollfd(): convert to CLASS(fd)
lift setting ->revents into the caller, so that failure exits (including the early one) would be plain returns. We need the scope of our struct fd to end before the store to ->revents, since that's shared with the failure exits prior to the point where we can do fdget(). Reviewed-by: Christian Brauner <[email protected]> Signed-off-by: Al Viro <[email protected]>
1 parent d000e07 commit 8935989

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

fs/select.c

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -855,29 +855,22 @@ static inline __poll_t do_pollfd(struct pollfd *pollfd, poll_table *pwait,
855855
__poll_t busy_flag)
856856
{
857857
int fd = pollfd->fd;
858-
__poll_t mask = 0, filter;
859-
struct fd f;
858+
__poll_t mask, filter;
860859

861860
if (fd < 0)
862-
goto out;
863-
mask = EPOLLNVAL;
864-
f = fdget(fd);
865-
if (!fd_file(f))
866-
goto out;
861+
return 0;
862+
863+
CLASS(fd, f)(fd);
864+
if (fd_empty(f))
865+
return EPOLLNVAL;
867866

868867
/* userland u16 ->events contains POLL... bitmap */
869868
filter = demangle_poll(pollfd->events) | EPOLLERR | EPOLLHUP;
870869
pwait->_key = filter | busy_flag;
871870
mask = vfs_poll(fd_file(f), pwait);
872871
if (mask & busy_flag)
873872
*can_busy_poll = true;
874-
mask &= filter; /* Mask out unneeded events. */
875-
fdput(f);
876-
877-
out:
878-
/* ... and so does ->revents */
879-
pollfd->revents = mangle_poll(mask);
880-
return mask;
873+
return mask & filter; /* Mask out unneeded events. */
881874
}
882875

883876
static int do_poll(struct poll_list *list, struct poll_wqueues *wait,
@@ -909,15 +902,17 @@ static int do_poll(struct poll_list *list, struct poll_wqueues *wait,
909902
pfd = walk->entries;
910903
pfd_end = pfd + walk->len;
911904
for (; pfd != pfd_end; pfd++) {
905+
__poll_t mask;
912906
/*
913907
* Fish for events. If we found one, record it
914908
* and kill poll_table->_qproc, so we don't
915909
* needlessly register any other waiters after
916910
* this. They'll get immediately deregistered
917911
* when we break out and return.
918912
*/
919-
if (do_pollfd(pfd, pt, &can_busy_loop,
920-
busy_flag)) {
913+
mask = do_pollfd(pfd, pt, &can_busy_loop, busy_flag);
914+
pfd->revents = mangle_poll(mask);
915+
if (mask) {
921916
count++;
922917
pt->_qproc = NULL;
923918
/* found something, stop busy polling */

0 commit comments

Comments
 (0)