kref_put(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… kref_put β€” the kref_put(9) glow-up πŸŽ€

okay bestie, gather round, because we're talking about the Kernel API Manual entry for kref_put and honestly? she's kind of a big deal. this is the function that says "yeah I'm done with this object, one less person is holding on" β€” and when the count hits zero, she lets the release function do its little cleanup dance. iconic behavior. ✨


🌸 NAME 🌸

kref_put β€” decrement refcount for object πŸ’–

(that's it. that's the whole vibe. decrement the refcount, bestie.)


πŸ¦‹ SYNOPSIS πŸ¦‹

int kref_put (struct kref *kref , void (*release)(struct kref *kref) );

literally right there. two arguments, one int coming back at you. no cap. 🫢


πŸŽ€ ARGUMENTS πŸŽ€

  • kref β€” Object. yeah, that's the thing you're holding a reference to. the object. the main character. πŸ‘‘
  • release β€” Pointer to the function that will clean up the object when the last reference to the object is released. so like, when everyone's finally gone home and the party's over, this is the function that turns off the lights and locks the door. πŸ”₯

πŸ’œ DESCRIPTION πŸ’œ

Decrement the refcount, and if 0, call release. simple as. the count goes down by one, and if it lands on zero, boom β€” release gets called to handle the cleanup. πŸŽ‰

⚠️ okay so this is the important part, do NOT skip it: the caller may not pass NULL or kfree as the release function. that's a hard no. not NULL, not kfree. periodt. πŸ’€

like… just don't. the kernel is trusting you and you don't want to be the one who broke it, fr fr. πŸ™ˆ


⭐ RETURN ⭐

  • Returns 1 if this call removed the object. congrats, you did it, the object is gone, slay. πŸ’…
  • Otherwise it returns 0. ✨
😭 big caveat time bestie: beware, if this function returns 0, another caller may have removed the object by the time this function returns. so that 0 is not a promise, it's more of a vibe. the return value is only certain if you want to see if the object is definitely released β€” like, that's the one thing you can actually trust it for. 🫢

🌈 SEE ALSO 🌈

Kernel file: ./include/linux/kref.h

and her friends, who are also in ./include/linux/kref.h and are all absolutely worth a read:

iykyk β€” go read them, they're all in the same little header file family and they all eat. πŸ“


🧚 and that's the page!! this little beauty lives under ./include/linux, dated October 2026, and yes the kref_put(9) title card at the bottom is still serving exactly the same energy as the one at the top. consistent queen. πŸ’–βœ¨

πŸ“¦ where this page comes from