@@ -1522,6 +1522,22 @@ static int ep_insert(struct eventpoll *ep, const struct epoll_event *event,
15221522 RCU_INIT_POINTER (epi -> ws , NULL );
15231523 }
15241524
1525+ /* Add the current item to the list of active epoll hook for this file */
1526+ spin_lock (& tfile -> f_lock );
1527+ list_add_tail_rcu (& epi -> fllink , & tfile -> f_ep_links );
1528+ spin_unlock (& tfile -> f_lock );
1529+
1530+ /*
1531+ * Add the current item to the RB tree. All RB tree operations are
1532+ * protected by "mtx", and ep_insert() is called with "mtx" held.
1533+ */
1534+ ep_rbtree_insert (ep , epi );
1535+
1536+ /* now check if we've created too many backpaths */
1537+ error = - EINVAL ;
1538+ if (full_check && reverse_path_check ())
1539+ goto error_remove_epi ;
1540+
15251541 /* Initialize the poll table using the queue callback */
15261542 epq .epi = epi ;
15271543 init_poll_funcptr (& epq .pt , ep_ptable_queue_proc );
@@ -1544,22 +1560,6 @@ static int ep_insert(struct eventpoll *ep, const struct epoll_event *event,
15441560 if (epi -> nwait < 0 )
15451561 goto error_unregister ;
15461562
1547- /* Add the current item to the list of active epoll hook for this file */
1548- spin_lock (& tfile -> f_lock );
1549- list_add_tail_rcu (& epi -> fllink , & tfile -> f_ep_links );
1550- spin_unlock (& tfile -> f_lock );
1551-
1552- /*
1553- * Add the current item to the RB tree. All RB tree operations are
1554- * protected by "mtx", and ep_insert() is called with "mtx" held.
1555- */
1556- ep_rbtree_insert (ep , epi );
1557-
1558- /* now check if we've created too many backpaths */
1559- error = - EINVAL ;
1560- if (full_check && reverse_path_check ())
1561- goto error_remove_epi ;
1562-
15631563 /* We have to drop the new item inside our item list to keep track of it */
15641564 write_lock_irq (& ep -> lock );
15651565
@@ -1588,16 +1588,15 @@ static int ep_insert(struct eventpoll *ep, const struct epoll_event *event,
15881588
15891589 return 0 ;
15901590
1591+ error_unregister :
1592+ ep_unregister_pollwait (ep , epi );
15911593error_remove_epi :
15921594 spin_lock (& tfile -> f_lock );
15931595 list_del_rcu (& epi -> fllink );
15941596 spin_unlock (& tfile -> f_lock );
15951597
15961598 rb_erase_cached (& epi -> rbn , & ep -> rbr );
15971599
1598- error_unregister :
1599- ep_unregister_pollwait (ep , epi );
1600-
16011600 /*
16021601 * We need to do this because an event could have been arrived on some
16031602 * allocated wait queue. Note that we don't care about the ep->ovflist
0 commit comments