struct rb_node *rbp;
        struct epitem *epi;
 
-       if (!ep_push_nested(cookie)) /* limits recursion */
-               return -1;
-
        mutex_lock_nested(&ep->mtx, depth + 1);
        ep->gen = loop_check_gen;
        for (rbp = rb_first_cached(&ep->rbr); rbp; rbp = rb_next(rbp)) {
                        ep_tovisit = epi->ffd.file->private_data;
                        if (ep_tovisit->gen == loop_check_gen)
                                continue;
-                       error = ep_loop_check_proc(epi->ffd.file, ep_tovisit,
+                       if (!ep_push_nested(ep_tovisit)) {
+                               error = -1;
+                       } else {
+                               error = ep_loop_check_proc(epi->ffd.file, ep_tovisit,
                                                   depth + 1);
+                               nesting--;
+                       }
                        if (error != 0)
                                break;
                } else {
                }
        }
        mutex_unlock(&ep->mtx);
-       nesting--; /* pop */
 
        return error;
 }
  */
 static int ep_loop_check(struct eventpoll *ep, struct file *file)
 {
-       return ep_loop_check_proc(file, ep, 0);
+       int err;
+
+       ep_push_nested(ep); // can't fail
+       err = ep_loop_check_proc(file, ep, 0);
+       nesting--;
+       return err;
 }
 
 static void clear_tfile_check_list(void)