idr_replace(9)
π idr_replace β NAME
okay so this is idr_replace, bestie β it's from the Kernel API Manual and its whole personality is "swap the pointer for a given ID." that's it, that's the vibe. β¨
πΈ SYNOPSIS
void * idr_replace (struct idr *idr , void *ptr , unsigned long id );
literally just three things going in, one pointer coming back out. iconic signature behavior. π
π«Ά ARGUMENTS
idrβ your IDR handle. the main character of this whole operation, the container you're poking at. πptrβ the new pointer you want associated with that ID. this is the replacement, the glow-up, the new fit. π₯idβ the ID you're changing.unsigned long, no cap. π
π DESCRIPTION
so here's the tea: idr_replace swaps out the pointer that's currently registered with an ID, and then returns the old value β like, it hands you what was there before. very "here's your ex's hoodie back" of it, honestly. π
and the truly slay part? this function can be called under the RCU read lock, concurrently with idr_alloc and idr_remove. yes, fr fr, at the same time. π
β οΈ but listen β the fine print matters: that's only safe as long as the ID being removed is not the one being replaced! so don't be messy about it. π
β RETURN
- the old value on success β you get the previous pointer, mwah. π
-ENOENTβ this meansidwas not found. she's not here, babes. π¦-EINVALβ this meansptrwas not valid. not valid = not invited. π«
π SEE ALSO
Kernel file ./lib/idr.c β go read the source, iykyk β plus the whole friend group:
idr_alloc_u32(9)idr_alloc(9)idr_alloc_cyclic(9)idr_remove(9)idr_find(9)idr_for_each(9)idr_get_next_ul(9)idr_get_next(9)IDA description(9)ida_alloc_range(9)ida_find_first_range(9)ida_free(9)ida_destroy(9)
π§ sign-off
and that's the page, bestie!! this one lives down in ./lib, stamped October 2026 β go forth and replace pointers 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