idr_alloc(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

✨ idr_alloc(9) ✨

okay so bestie, welcome to the idr_alloc page from the Kernel API Manual β€” this is the one that hands out IDs like friendship bracelets at a sleepover πŸ’…


πŸŽ€ NAME πŸŽ€

idr_alloc β€” allocate an ID, bestie. that's the whole vibe. πŸ’–


πŸ¦‹ SYNOPSIS πŸ¦‹

int idr_alloc (struct idr *idr , void *ptr , int start , int end , gfp_t gfp );

🌸 ARGUMENTS 🌸

  • idr β€” the IDR handle. literally your whole little ID kingdom πŸ‘‘
  • ptr β€” the pointer that gets associated with the brand-new ID. it's giving "these two are together now" 🫢
  • start β€” the minimum ID, and yes it's inclusive β€” so start itself is in the club πŸŽ€
  • end β€” the maximum ID, but it's exclusive β€” sorry end, you're not on the list πŸ™ˆ
  • gfp β€” memory allocation flags. the boring-but-essential paperwork ngl ⭐

πŸ’œ DESCRIPTION πŸ’œ

So what it actually does: it allocates an unused ID inside the range that start and end specify. lowkey simple, highkey useful ✨

And here's a cute little edge case for you: if end is <= 0, it gets treated as one larger than INT_MAX. that's the whole reason callers can just write start + N as the end value β€” as long as N is within integer range, you're golden πŸ’–

⚠️ okay this part matters, don't skip it: the caller should provide their own locking to make sure two concurrent modifications to the IDR can't happen at the same time. no cap, that's on you.

Read-only accesses to the IDR are fine though β€” they may be done under the RCU read lock, or they may exclude simultaneous writers. pick your lane, both are valid πŸ¦‹


πŸ”₯ RETURN πŸ”₯

  • the newly allocated ID β€” slay, you got one πŸŽ‰
  • -ENOMEM if memory allocation failed 😭
  • -ENOSPC if no free IDs could be found πŸ’€

🌈 SEE ALSO 🌈


and that's the page, bestie!! 🧚 this lil gem lives in ./lib, dated October 2026, and it's filed under idr_alloc(9) β€” go forth and allocate responsibly πŸ’œβœ¨

πŸ“¦ where this page comes from