devm_kmalloc(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’– devm_kmalloc(9) β€” Resource-managed kmalloc πŸ’–

okay bestie, so we're in the Kernel API Manual today and this one is genuinely such a glow-up. it's devm_kmalloc, and the "devm" is doing the heavy lifting here β€” think of it as kmalloc but with a built-in cleanup crew. no cap, it's iconic.


✨ NAME ✨

devm_kmalloc β€” Resource-managed kmalloc πŸŽ€


🌸 SYNOPSIS 🌸

void * devm_kmalloc (struct device *dev , size_t size , gfp_t gfp );

πŸ¦‹ ARGUMENTS πŸ¦‹

  • dev β€” the Device you're allocating memory for 🫢
  • size β€” how big the Allocation is, aka the Allocation size
  • gfp β€” the Allocation gfp flags, yes queen, tell the allocator your vibe

πŸ’… DESCRIPTION πŸ’…

Managed kmalloc. the whole point, the main character energy: memory allocated with this function is automatically freed on driver detach. you literally don't have to remember to clean up. she handles it. periodt.

And like all the other devres resources, guaranteed alignment is unsigned long long. that's the flex. πŸ’ͺ


⭐ RETURN ⭐

Pointer to allocated memory on success β€” and NULL on failure 😭 (check it, bestie, always check it).


🌈 SEE ALSO 🌈

Kernel file ./drivers/base/devres.c β€” and the whole devres friend group, fr fr:


lowkey a whole squad. read them, love them, link against them πŸ’œ

and that's the page, bestie!! this lil drop came from ./drivers/base, dated October 2026, in the Kernel API Manual. mwah πŸ’‹ go free your memory automatically, you deserve it πŸ§šβ€β™€οΈβœ¨

πŸ“¦ where this page comes from