llist_for_each_entry_safe(9)
π 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β thetype *you're using as your loop cursor π― think of it as the main character of each iteration, fr frnβ anothertype *, but this one's just temporary storage π a little sidekick that holds the next thing so you don't tripnodeβ the first entry of the deleted list entries π this is where the party startsmemberβ the name of thellist_nodesitting 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 π«Ά:
init_llist_head(9)init_llist_node(9)llist_on_list(9)llist_entry(9)member_address_is_nonnull(9)llist_for_each(9)llist_for_each_safe(9)llist_for_each_entry(9)llist_empty(9)llist_add_batch(9)llist_add(9)llist_del_all(9)llist_del_first_init(9)
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
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms