devm_alloc_percpu(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… devm_alloc_percpu(9) β€” kernel API manual, but make it make sense πŸŽ€

okay bestie, welcome to the Kernel API Manual ✨ this one's about devm_alloc_percpu, and it's genuinely one of the good ones β€” the kind of function that has your back so you don't have to write cleanup code at 3am. no cap. 🫢


🌸 NAME 🌸

devm_alloc_percpu β€” the resource-managed version of alloc_percpu. that's it, that's the vibe: allocate per-cpu memory, but managed, so the kernel handles the boring part for you. πŸ’œ


✨ SYNOPSIS ✨

devm_alloc_percpu (dev , type );

two arguments, comma between them, keep the space, character for character. iconic, honestly. πŸŽ€


πŸ¦‹ ARGUMENTS πŸ¦‹

  • dev β€” the device you're allocating this per-cpu memory for. your main character device, basically. πŸ‘‘
  • type β€” the type you're allocating that per-cpu memory for. yes, the actual type, that's the whole label. πŸ“

πŸ’– DESCRIPTION πŸ’–

so it's a managed alloc_percpu. and here's the slay part: per-cpu memory that you allocate with this function is automatically freed on driver detach. 😭✨

read that again. you don't have to remember to free it. you don't have to write the cleanup path. the devres machinery literally does it for you. no leaks, no sad dmesg, no "why is my driver still holding memory" spiraling. it's giving responsible adult energy and honestly? obsessed. 🧚


πŸ”₯ RETURN πŸ”₯

  • on success β†’ a pointer to the allocated memory πŸŽ‰
  • on failure β†’ NULL πŸ’€

so like, vibe check that return value before you dereference it, bestie. NULL is not a personality trait, don't befriend it. πŸ™ˆ


🌈 SEE ALSO 🌈

  • kernel file ./include/linux/device/devres.h β€” go read it, it's where the devres magic lives πŸ¦‹
  • devm_remove_action(9) β€” the related function, iykyk πŸ‘‘

and that's the whole page, fr fr. πŸ’…

source: ./include/linux/device Β· October 2026 β€” mwah, go free your per-cpu memory the managed way, bestie 🌸✨🫢

πŸ“¦ where this page comes from