idr_replace(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… 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 means id was not found. she's not here, babes. πŸ¦‹
  • -EINVAL β€” this means ptr was not valid. not valid = not invited. 🚫

🌈 SEE ALSO

Kernel file ./lib/idr.c β€” go read the source, iykyk β€” plus the whole friend group:


🧚 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