idr_for_each(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… idr_for_each(9) β€” Kernel API Manual, bestie ✨

🌸 NAME

idr_for_each β€” Iterate through all stored pointers. no cap, that's the whole vibe πŸ’–


✨ SYNOPSIS

int idr_for_each (const struct idr *idr , int (*fn)(int id, void *p, void *data) , void *data );

πŸŽ€ ARGUMENTS

  • idr β€” IDR handle. the main character struct, lowkey πŸ¦‹
  • fn β€” Function to be called for each pointer. your callback bestie, fr fr πŸ’…
  • data β€” Data passed to callback function. it gets handed straight to fn, periodt 🫢

πŸ’œ DESCRIPTION

okay so here's the tea: the callback function fn will be called for each entry in idr, passing the ID, the entry and data. cute, iconic, efficient ✨

if fn returns anything other than 0, the iteration stops and that value is returned from this function. literally that simple, bestie πŸ’β€β™€οΈ

idr_for_each can be called concurrently with idr_alloc and idr_remove if protected by RCU. Newly added entries may not be seen and deleted entries may be seen, but adding and removing entries will not cause other entries to be skipped, nor spurious ones to be seen. πŸ’€ this RCU caveat is important β€” protect it properly, iykyk πŸ”₯


🌈 SEE ALSO

Kernel file ./lib/idr.c and the whole friend group: idr_alloc_u32(9), idr_alloc(9), idr_alloc_cyclic(9), idr_remove(9), idr_find(9), idr_get_next_ul(9), idr_get_next(9), idr_replace(9), IDA description(9), ida_alloc_range(9), ida_find_first_range(9), ida_free(9), ida_destroy(9). slay πŸŽ€


byeee 🫢 this iconic page lives under ./lib, dated October 2026, and it's literally idr_for_each(9) πŸ’–βœ¨

πŸ“¦ where this page comes from