Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

fs/epoll: simplify ep_send_events_proc() ready-list loop

The current logic is a bit convoluted. Lets simplify this with a
standard list_for_each_entry_safe() loop instead and just break out
after maxevents is reached.

While at it, remove an unnecessary indentation level in the loop when
there are in fact ready events.

Link: http://lkml.kernel.org/r/20181108051006.18751-3-dave@stgolabs.net
Signed-off-by: Davidlohr Bueso <dbueso@suse.de>
Reviewed-by: Andrew Morton <akpm@linux-foundation.org>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Jason Baron <jbaron@akamai.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Davidlohr Bueso and committed by
Linus Torvalds
4e0982a0 74bdc129

+37 -36
+37 -36
fs/eventpoll.c
··· 1624 1624 { 1625 1625 struct ep_send_events_data *esed = priv; 1626 1626 __poll_t revents; 1627 - struct epitem *epi; 1628 - struct epoll_event __user *uevent; 1627 + struct epitem *epi, *tmp; 1628 + struct epoll_event __user *uevent = esed->events; 1629 1629 struct wakeup_source *ws; 1630 1630 poll_table pt; 1631 1631 1632 1632 init_poll_funcptr(&pt, NULL); 1633 + esed->res = 0; 1633 1634 1634 1635 /* 1635 1636 * We can loop without lock because we are passed a task private list. 1636 1637 * Items cannot vanish during the loop because ep_scan_ready_list() is 1637 1638 * holding "mtx" during this call. 1638 1639 */ 1639 - for (esed->res = 0, uevent = esed->events; 1640 - !list_empty(head) && esed->res < esed->maxevents;) { 1641 - epi = list_first_entry(head, struct epitem, rdllink); 1640 + list_for_each_entry_safe(epi, tmp, head, rdllink) { 1641 + if (esed->res >= esed->maxevents) 1642 + break; 1642 1643 1643 1644 /* 1644 1645 * Activate ep->ws before deactivating epi->ws to prevent ··· 1659 1658 1660 1659 list_del_init(&epi->rdllink); 1661 1660 1662 - revents = ep_item_poll(epi, &pt, 1); 1663 - 1664 1661 /* 1665 1662 * If the event mask intersect the caller-requested one, 1666 1663 * deliver the event to userspace. Again, ep_scan_ready_list() 1667 - * is holding "mtx", so no operations coming from userspace 1664 + * is holding ep->mtx, so no operations coming from userspace 1668 1665 * can change the item. 1669 1666 */ 1670 - if (revents) { 1671 - if (__put_user(revents, &uevent->events) || 1672 - __put_user(epi->event.data, &uevent->data)) { 1673 - list_add(&epi->rdllink, head); 1674 - ep_pm_stay_awake(epi); 1675 - if (!esed->res) 1676 - esed->res = -EFAULT; 1677 - return 0; 1678 - } 1679 - esed->res++; 1680 - uevent++; 1681 - if (epi->event.events & EPOLLONESHOT) 1682 - epi->event.events &= EP_PRIVATE_BITS; 1683 - else if (!(epi->event.events & EPOLLET)) { 1684 - /* 1685 - * If this file has been added with Level 1686 - * Trigger mode, we need to insert back inside 1687 - * the ready list, so that the next call to 1688 - * epoll_wait() will check again the events 1689 - * availability. At this point, no one can insert 1690 - * into ep->rdllist besides us. The epoll_ctl() 1691 - * callers are locked out by 1692 - * ep_scan_ready_list() holding "mtx" and the 1693 - * poll callback will queue them in ep->ovflist. 1694 - */ 1695 - list_add_tail(&epi->rdllink, &ep->rdllist); 1696 - ep_pm_stay_awake(epi); 1697 - } 1667 + revents = ep_item_poll(epi, &pt, 1); 1668 + if (!revents) 1669 + continue; 1670 + 1671 + if (__put_user(revents, &uevent->events) || 1672 + __put_user(epi->event.data, &uevent->data)) { 1673 + list_add(&epi->rdllink, head); 1674 + ep_pm_stay_awake(epi); 1675 + if (!esed->res) 1676 + esed->res = -EFAULT; 1677 + return 0; 1678 + } 1679 + esed->res++; 1680 + uevent++; 1681 + if (epi->event.events & EPOLLONESHOT) 1682 + epi->event.events &= EP_PRIVATE_BITS; 1683 + else if (!(epi->event.events & EPOLLET)) { 1684 + /* 1685 + * If this file has been added with Level 1686 + * Trigger mode, we need to insert back inside 1687 + * the ready list, so that the next call to 1688 + * epoll_wait() will check again the events 1689 + * availability. At this point, no one can insert 1690 + * into ep->rdllist besides us. The epoll_ctl() 1691 + * callers are locked out by 1692 + * ep_scan_ready_list() holding "mtx" and the 1693 + * poll callback will queue them in ep->ovflist. 1694 + */ 1695 + list_add_tail(&epi->rdllink, &ep->rdllist); 1696 + ep_pm_stay_awake(epi); 1698 1697 } 1699 1698 } 1700 1699