Skip to content

Commit 00b2763

Browse files
soheilhytorvalds
authored andcommitted
epoll: replace gotos with a proper loop
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/20201106231635.3528496-8-soheil.kdev@gmail.com Signed-off-by: Soheil Hassas Yeganeh <soheil@google.com> Suggested-by: Linus Torvalds <torvalds@linux-foundation.org> Reviewed-by: Eric Dumazet <edumazet@google.com> Reviewed-by: Willem de Bruijn <willemb@google.com> Reviewed-by: Khazhismel Kumykov <khazhy@google.com> Cc: Guantao Liu <guantaol@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent e8c8532 commit 00b2763

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

fs/eventpoll.c

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1743,7 +1743,7 @@ static inline struct timespec64 ep_set_mstimeout(long ms)
17431743
static int ep_poll(struct eventpoll *ep, struct epoll_event __user *events,
17441744
int maxevents, long timeout)
17451745
{
1746-
int res, eavail, timed_out = 0;
1746+
int res, eavail = 0, timed_out = 0;
17471747
u64 slack = 0;
17481748
wait_queue_entry_t wait;
17491749
ktime_t expires, *to = NULL;
@@ -1769,18 +1769,30 @@ static int ep_poll(struct eventpoll *ep, struct epoll_event __user *events,
17691769
write_lock_irq(&ep->lock);
17701770
eavail = ep_events_available(ep);
17711771
write_unlock_irq(&ep->lock);
1772-
1773-
goto send_events;
17741772
}
17751773

1776-
fetch_events:
1777-
do {
1774+
while (1) {
1775+
if (eavail) {
1776+
/*
1777+
* Try to transfer events to user space. In case we get
1778+
* 0 events and there's still timeout left over, we go
1779+
* trying again in search of more luck.
1780+
*/
1781+
res = ep_send_events(ep, events, maxevents);
1782+
if (res)
1783+
return res;
1784+
}
1785+
1786+
if (timed_out)
1787+
return 0;
1788+
17781789
eavail = ep_events_available(ep);
1779-
if (!eavail)
1780-
eavail = ep_busy_loop(ep, timed_out);
1790+
if (eavail)
1791+
continue;
17811792

1793+
eavail = ep_busy_loop(ep, timed_out);
17821794
if (eavail)
1783-
goto send_events;
1795+
continue;
17841796

17851797
if (signal_pending(current))
17861798
return -EINTR;
@@ -1845,19 +1857,7 @@ static int ep_poll(struct eventpoll *ep, struct epoll_event __user *events,
18451857
__remove_wait_queue(&ep->wq, &wait);
18461858
write_unlock_irq(&ep->lock);
18471859
}
1848-
} while (0);
1849-
1850-
send_events:
1851-
/*
1852-
* Try to transfer events to user space. In case we get 0 events and
1853-
* there's still timeout left over, we go trying again in search of
1854-
* more luck.
1855-
*/
1856-
if (eavail &&
1857-
!(res = ep_send_events(ep, events, maxevents)) && !timed_out)
1858-
goto fetch_events;
1859-
1860-
return res;
1860+
}
18611861
}
18621862

18631863
/**

0 commit comments

Comments
 (0)