Skip to content

Commit

Permalink
epoll: replace gotos with a proper loop
Browse files Browse the repository at this point in the history
The existing loop is pointless, and the labels make it really hard to
follow the structure.

Replace that control structure with a simple loop that returns when there
are new events, there is a signal, or the thread has timed out.

Link: https://lkml.kernel.org/r/[email protected]
Signed-off-by: Soheil Hassas Yeganeh <[email protected]>
Suggested-by: Linus Torvalds <[email protected]>
Reviewed-by: Eric Dumazet <[email protected]>
Reviewed-by: Willem de Bruijn <[email protected]>
Reviewed-by: Khazhismel Kumykov <[email protected]>
Cc: Guantao Liu <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
soheilhy authored and torvalds committed Dec 19, 2020
1 parent e8c8532 commit 00b2763
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions fs/eventpoll.c
Original file line number Diff line number Diff line change
Expand Up @@ -1743,7 +1743,7 @@ static inline struct timespec64 ep_set_mstimeout(long ms)
static int ep_poll(struct eventpoll *ep, struct epoll_event __user *events,
int maxevents, long timeout)
{
int res, eavail, timed_out = 0;
int res, eavail = 0, timed_out = 0;
u64 slack = 0;
wait_queue_entry_t wait;
ktime_t expires, *to = NULL;
Expand All @@ -1769,18 +1769,30 @@ static int ep_poll(struct eventpoll *ep, struct epoll_event __user *events,
write_lock_irq(&ep->lock);
eavail = ep_events_available(ep);
write_unlock_irq(&ep->lock);

goto send_events;
}

fetch_events:
do {
while (1) {
if (eavail) {
/*
* Try to transfer events to user space. In case we get
* 0 events and there's still timeout left over, we go
* trying again in search of more luck.
*/
res = ep_send_events(ep, events, maxevents);
if (res)
return res;
}

if (timed_out)
return 0;

eavail = ep_events_available(ep);
if (!eavail)
eavail = ep_busy_loop(ep, timed_out);
if (eavail)
continue;

eavail = ep_busy_loop(ep, timed_out);
if (eavail)
goto send_events;
continue;

if (signal_pending(current))
return -EINTR;
Expand Down Expand Up @@ -1845,19 +1857,7 @@ static int ep_poll(struct eventpoll *ep, struct epoll_event __user *events,
__remove_wait_queue(&ep->wq, &wait);
write_unlock_irq(&ep->lock);
}
} while (0);

send_events:
/*
* Try to transfer events to user space. In case we get 0 events and
* there's still timeout left over, we go trying again in search of
* more luck.
*/
if (eavail &&
!(res = ep_send_events(ep, events, maxevents)) && !timed_out)
goto fetch_events;

return res;
}
}

/**
Expand Down

0 comments on commit 00b2763

Please sign in to comment.