devm_alloc_percpu(9)
π 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
- 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