diff --git a/net/unix/garbage.c b/net/unix/garbage.c index 51acf795f096..3b345b7a228b 100644 --- a/net/unix/garbage.c +++ b/net/unix/garbage.c @@ -340,13 +340,18 @@ static void __unix_gc(struct work_struct *work) __skb_queue_purge(&hitlist); #if IS_ENABLED(CONFIG_AF_UNIX_OOB) - while (!list_empty(&gc_candidates)) { - u = list_entry(gc_candidates.next, struct unix_sock, link); + u = list_first_entry_or_null(&gc_candidates, struct unix_sock, link); + + while (u) { if (u->oob_skb) { struct sk_buff *skb = u->oob_skb; u->oob_skb = NULL; kfree_skb(skb); + + u = list_first_entry_or_null(&gc_candidates, struct unix_sock, link); + } else { + u = list_next_entry(u, link); } } #endif