idr_for_each_entry(9)
π 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:
IDR_INIT(9)DEFINE_IDR(9)idr_get_cursor(9)idr_set_cursor(9)idr sync(9)idr_init_base(9)idr_init(9)idr_is_empty(9)idr_preload_end(9)idr_for_each_entry_ul(9)idr_for_each_entry_continue(9)idr_for_each_entry_continue_ul(9)ida_alloc(9)ida_alloc_min(9)ida_alloc_max(9)
and that's the whole page, bestie, we ate and left no crumbs π
π source file:./include/linuxΒ· dated October 2026 Β· yes it'sidr_for_each_entry(9), mwah, bye π§β¨πΈ
π¦ 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