idr_for_each_entry(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… idr_for_each_entry(9) β€” the Kernel API Manual page you didn't know you needed πŸŽ€

okay so bestie, this is a page straight out of the Kernel API Manual and honestly it's giving "tiny function, big main character energy" ✨ it's idr_for_each_entry, and it's literally just a little loop-machine for walking an IDR. that's it. that's the vibe. let's get into it πŸ¦‹


✨ NAME ✨

idr_for_each_entry β€” iterate over an IDR's elements of a given type. periodt πŸ’…


🌸 SYNOPSIS 🌸

idr_for_each_entry (idr , entry , id );

yes, the spacing is exactly like that, don't come for me, it's the kernel's house style not mine 😭


πŸŽ€ ARGUMENTS πŸŽ€

  • idr β€” the IDR handle. your whole little ID-party lives in here πŸͺ©
  • entry β€” the type * to use as the cursor. this is the pointer that walks the loop with you, like your bestie holding your hand 🫢
  • id β€” the entry ID. the number, the label, the ~identity~ of the thing πŸ”₯

πŸ’– DESCRIPTION πŸ’–

okay so here's the tea: entry and id do not need to be initialized before the loop. not even a little. don't touch them, don't zero them, don't be extra about it πŸ™ˆ the macro handles all of that for you, no cap.

and after normal termination, entry is left with the value NULL. which is honestly so convenient if you need a "not found" value β€” it's basically the function handing you a little "nope, nothing here babe" flag for free πŸ‘‘

⚠️ note the wording: it's normal termination that leaves you at NULL. that's the case the page promises, so don't go assuming anything spicy about the other ways out πŸ’€

πŸ¦‹ SEE ALSO πŸ¦‹

this is the part where the kernel introduces you to its whole friend group. the header lives in the kernel file ./include/linux/idr.h and the squad is:


and that's the whole page, bestie, we ate and left no crumbs πŸ“

πŸ’œ source file: ./include/linux Β· dated October 2026 Β· yes it's idr_for_each_entry(9), mwah, bye 🧚✨🌸
πŸ“¦ where this page comes from