list_for_each_prev_safe(9)
π list_for_each_prev_safe(9) β Kernel API Manual, bestie edition π
Okay so picture this: you're in the kernel, you're walking a linked list, and you're going backwards β main character energy, honestly β but plot twist, someone might delete the entry you're standing on mid-walk π. This macro is the friend who holds your bag while you do it. It's from the Kernel API Manual, and this page is literally just the entry for list_for_each_prev_safe. Let's get into it β¨
πΈ NAME πΈ
list_for_each_prev_safe β iterate over a list backwards, safe against removal of list entry π¦
Like, you loop in reverse and you're allowed to yeet the current node without the whole thing imploding. Slay.
β¨ SYNOPSIS β¨
list_for_each_prev_safe (pos , n , head );
That's the whole shape of it β three little arguments and you're off π
π ARGUMENTS π
posβ thestruct list_headto use as a loop cursor. This is your little pointer bestie that tells you where you are in the walk π«Άnβ anotherstruct list_headto use as temporary storage. Lowkey just scratch space so you don't lose your place when things get deleted πheadβ the head for your list. The starting-off point, the home base, theheadof the whole operation π
π SEE ALSO π
Kernel file ./tools/include/linux/list.h β and like, the entire list gang, fr fr:
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_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)hlist_for_each_entry_safe(9)list_del_range(9)list_for_each_from(9)
ngl, that's a lot of list macros β but every single one of them is a baddie in its own right π
Okay that's the page!! It lives in ./tools/include/linux, dated October 2026, and it's filed under list_for_each_prev_safe(9) in the Kernel API Manual. Go backwards, stay safe, and don't forget your temporary storage 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