llist_for_each_entry_safe(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’– llist_for_each_entry_safe πŸ’–

okay so bestie, welcome to the llist_for_each_entry_safe(9) page 🌸 this is from the kernel API manual and it's genuinely iconic, no cap. lowkey the whole point is looping over deleted entries of a lockless list of a given type, and it's safe against removal of the list entry β€” like, nothing's gonna get yanked out from under you mid-loop πŸ’…


✨ NAME ✨

llist_for_each_entry_safe β€” iterate over some deleted entries of lockless list of given type, safe against removal of the list entry πŸ¦‹

✨ SYNOPSIS ✨

llist_for_each_entry_safe (pos , n , node , member );

πŸŽ€ ARGUMENTS πŸŽ€

  • pos β€” the type * you're using as your loop cursor 🎯 think of it as the main character of each iteration, fr fr
  • n β€” another type *, but this one's just temporary storage πŸ‘‘ a little sidekick that holds the next thing so you don't trip
  • node β€” the first entry of the deleted list entries 🌟 this is where the party starts
  • member β€” the name of the llist_node sitting inside the struct πŸ™ˆ iykyk, it's how we get from the node to the big struct

πŸ’œ DESCRIPTION πŸ’œ

so here's the vibe check: in general, some entries of the lockless list can only be traversed safely after they've been removed from the list 😭 that's just how it is. so the move is to start with an entry instead of the list head β€” like, don't come in through the front door, come in through the entry itself πŸ’…

and if you're using this on entries that got deleted straight out of the lockless list, the traverse order goes from the newest to the oldest added entry ⭐ that's the default direction, periodt. but bestie, if you want the opposite β€” oldest to newest β€” then you have to reverse the order yourself before traversing πŸ”₯ nobody's doing that for you, sorry not sorry πŸ’€

ok tiny warning-ish note from the page: there's no reversing built in β€” you flip the order by yourself first, or you're getting newest-to-oldest whether you like it or not πŸ™ˆ

🌈 SEE ALSO 🌈

kernel file ./include/linux/llist.h and honestly the whole llist friend group showed up for this one 🫢:


okay that's the whole page and you ate it up πŸ’– this gem lives in ./include/linux, dated October 2026, and it's brought to you by the one and only llist_for_each_entry_safe(9) β€” slay, go write your safe loops bestie πŸŽ€βœ¨

πŸ“¦ where this page comes from