__devm_add_action(9)
πΈ __devm_add_action(9) πΈ
okay so bestie, we're in the Kernel API Manual today β yes, that manual, the big serious one β and the star of the show is __devm_add_action. lowkey a little legend. let's get into it π
β¨ NAME β¨
__devm_add_action β add a custom action to the list of managed resources π
like, you're literally registering a little side-quest that the kernel will handle for you later. no cap.
π¦ SYNOPSIS π¦
int __devm_add_action (struct device *dev , void (*action)(void *) ,
void *data , const char *name );
she returns an int, she takes four args, she's booked and busy β¨
π ARGUMENTS π
devβ the Device that owns the action π like, whose responsibility is this? hers.actionβ the Function that should be called. this is the function. it gets called. that's the whole vibe π₯dataβ Pointer to data passed to theactionimplementation π handed straight to your callback, no detours.nameβ Name of the resource (for debugging purposes) π so when things go sideways at 3am you know which resource ghosted you. iykyk.
π DESCRIPTION π
so what does she actually do? This adds a custom action to the list of managed resources so that it gets executed as part of standard resource unwinding. π§
translation for the group chat: you hand over your little cleanup function, the device takes custody of it, and when the standard unwinding happens, your action gets run β automatically. no manual cleanup arc, no forgotten free() trauma. main character energy, honestly. π
β SEE ALSO β
okay this list is long long, but every single one of these is invited to the party β not me listing them all and skipping zero of them π
Kernel file ./drivers/base/devres.c:
__devres_alloc_node(9)devres_for_each_res(9)devres_free(9)devres_add(9)devres_find(9)devres_get(9)devres_remove(9)devres_destroy(9)devres_release(9)devres_release_all(9)devres_open_group(9)devres_close_group(9)devres_remove_group(9)devres_release_group(9)devm_remove_action_nowarn(9)devm_release_action(9)devm_kmalloc(9)devm_krealloc(9)devm_kstrdup(9)devm_kstrdup_const(9)devm_kvasprintf(9)devm_kasprintf(9)devm_kfree(9)devm_kmemdup(9)devm_kmemdup_const(9)devm_get_free_pages(9)devm_free_pages(9)__devm_alloc_percpu(9)
bestie bestie bestie β that SEE ALSO list is 28 entries long and i love her for it. go read a couple. or all of them. be the main character of your own devres journey π
okay and finally the cute little sign-off because we do NOT skip the footer in this house π«Ά: this page lives under ./drivers/base, and it's dated October 2026 β and yes, the title on the door is __devm_add_action(9), same as the one up top. slay, consistent queen πβ¨
π¦ 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