list_for_each_prev_safe(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… 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 β€” the struct list_head to use as a loop cursor. This is your little pointer bestie that tells you where you are in the walk 🫢
  • n β€” another struct list_head to 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, the head of the whole operation πŸ’–

πŸ’œ SEE ALSO πŸ’œ

Kernel file ./tools/include/linux/list.h β€” and like, the entire list gang, fr fr:


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