hlist_for_each_entry_safe(9)
π hlist_for_each_entry_safe β Kernel API Manual β¨
okay so bestie, welcome to the hlist_for_each_entry_safe(9) page π yes the manual name is Kernel API Manual, we're in the big leagues now, and this one macro? it's giving "loop through a hash-list but make it unbothered by deletion" energy. no cap.
β¨ NAME β¨
hlist_for_each_entry_safe β iterate over list of given type safe against removal of list entry π¦
like, you walk the list, and it does not fall apart if somebody yanks an entry out from under you mid-loop. that's the whole vibe check. iconic behaviour honestly.
πΈ SYNOPSIS πΈ
hlist_for_each_entry_safe (pos , n , head , member );
yes, that spacing is exactly how it's written in the source, we don't "fix" things here, we respect the original π«Ά
π ARGUMENTS π
posβ the type * to use as a loop cursor. this is your main character β¨ it's the pointer that'll be pointing at whatever entry you're currently vibing with, one at a time.nβ another struct hlist_node to use as temporary storage. hi bestie π this one is the whole reason you're safe β it's holding onto the next thing so removal can't ruin your day.headβ the head for your list. the beginning, the origin story, the place where the whole hlist starts.memberβ the name of thehlist_nodewithin the struct. yep, just the member name β you tell it where the node lives inside your type and it handles the rest. iykyk π
lowkey thenone is the entire point of the_safein the name. don't skip it, don't get cute with it. the safety is the feature.
π SEE ALSO π
also check out the Kernel file ./tools/include/linux/list.h β that's where the magic lives, and it's linked up with basically the entire list-ops friend group πΈ:
list_add(9)list_add_tail(9)list_replace(9)list_del_init(9)list_move(9)list_move_tail(9)list_is_first(9)list_is_last(9)list_empty(9)list_empty_careful(9)list_rotate_left(9)list_is_singular(9)list_cut_position(9)list_splice(9)list_splice_tail(9)list_splice_init(9)list_splice_tail_init(9)list_entry(9)list_first_entry(9)list_last_entry(9)list_first_entry_or_null(9)list_last_entry_or_null(9)list_next_entry(9)list_prev_entry(9)list_for_each(9)list_for_each_prev(9)list_for_each_safe(9)list_for_each_prev_safe(9)list_for_each_entry(9)list_for_each_entry_reverse(9)list_prepare_entry(9)list_for_each_entry_continue(9)list_for_each_entry_continue_reverse(9)list_for_each_entry_from(9)list_for_each_entry_safe(9)list_for_each_entry_safe_continue(9)list_for_each_entry_safe_from(9)list_for_each_entry_safe_reverse(9)list_safe_reset_next(9)hlist_for_each_entry(9)hlist_for_each_entry_continue(9)hlist_for_each_entry_from(9)list_del_range(9)list_for_each_from(9)
and that's the whole page bestie, go forth and loop safely π
sign-off time π this one's served fresh from ./tools/include/linux, stamped October 2026, and it answers to hlist_for_each_entry_safe(9) β periodt. π
β¨
π¦ 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