idr_alloc(9)
β¨ 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 β sostartitself is in the club πendβ the maximum ID, but it's exclusive β sorryend, 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 π
-ENOMEMif memory allocation failed π-ENOSPCif no free IDs could be found π
π SEE ALSO π
- Kernel file
./lib/idr.c idr_alloc_u32(9)idr_alloc_cyclic(9)idr_remove(9)idr_find(9)idr_for_each(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)
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
- 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