list_safe_reset_next(9)
π list_safe_reset_next β Kernel API Manual π
okay bestie, this one's short but it's important, so pay attention. It's <pink>list_safe_reset_next</pink>, from the Kernel API Manual (section 9), and it's the little function that hits the reset button on a stale list_for_each_entry_safe loop. icon behavior only. π¦
β¨ SYNOPSIS β¨
list_safe_reset_next (pos , n , member );
yeah that's literally the whole call, no cap π₯
πΈ ARGUMENTS πΈ
posβ the loop cursor from yourlist_for_each_entry_safeloop. it's the main character of the loop, lowkey πnβ the temporary storage buddy thatlist_for_each_entry_safeuses. think of it as the loop's emotional support variable π«Άmemberβ the name of thelist_headinside the struct. that's the field name, exactly, no guessing π
π DESCRIPTION π
okay so here's the tea: list_safe_reset_next is not safe to use in general if the list might get modified concurrently β like, say, the lock is dropped somewhere in the loop body. π¨ that's a real "not me getting a use-after-free" moment, so like, be careful.
BUT β and this is the iconic exception β it is chill if both of these are true: the cursor element (pos) is pinned in the list, and you call list_safe_reset_next after re-taking the lock and before completing the current iteration of the loop body. that exact ordering, bestie. don't freestyle it. β¨
π¦ SEE ALSO π¦
Kernel file ./tools/include/linux/list.h, plus literally the entire list family reunion:
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)hlist_for_each_entry(9),hlist_for_each_entry_continue(9),hlist_for_each_entry_from(9),hlist_for_each_entry_safe(9)list_del_range(9),list_for_each_from(9)
like, go read the whole squad, iykyk π
bestie warning, one more time: concurrent modification + no lock = bad vibes. pin that cursor, re-take the lock, then reset. periodt. π
and that's the whole page, bestie!! this lil gem came from ./tools/include/linux, dated October 2026 β slay, see you in the group chat πππ
π¦ 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