diff --git a/fs/eventpoll.c b/fs/eventpoll.c index 2b01fc05c307..afd69849796c 100644 --- a/fs/eventpoll.c +++ b/fs/eventpoll.c @@ -784,7 +784,7 @@ static void ep_remove_safe(struct eventpoll *ep, static void ep_clear_and_put(struct eventpoll *ep) { - struct rb_node *rbp; + struct rb_node *rbp, *next; struct epitem *epi; bool dispose; @@ -810,7 +810,8 @@ static void ep_clear_and_put(struct eventpoll *ep) * Since we still own a reference to the eventpoll struct, the * dispose it. */ - while ((rbp = rb_first_cached(&ep->rbr)) != NULL) { + for (rbp = rb_first_cached(&ep->rbr); rbp; rbp = next) { + next = rb_next(rbp); epi = rb_entry(rbp, struct epitem, rbn); ep_remove_safe(ep, epi); cond_resched();