devres_add(9)
β¨ devres_add(9) β¨
okay so we're in the Kernel API Manual today bestie, and this one is a little baby function that does SO much behind the scenes π
πΈ NAME πΈ
devres_add β register device resource, periodt π
π SYNOPSIS π
void devres_add (struct device *dev , void *res );
that's it. that's the whole vibe. one call, no return value, no cap β¨
π¦ ARGUMENTS π¦
devβ the device you're adding the resource to π like, the main character device in this whole situationresβ the resource you're registering π the little guy you want the kernel to babysit for you
π DESCRIPTION π
okay so here's the tea π: you call devres_add to register the devres res to dev. simple!
BUT β and this is the important part, don't skip it β res should have been allocated using devres_alloc. like, that's not a suggestion, that's the rule fr fr π
and then the actual slay happens on driver detach: the associated release function gets invoked and the devres gets freed automatically π₯ no manual cleanup, no memory leaks, no 3am debugging session. the kernel literally handles it for you. iconic behaviour honestly π
π« SEE ALSO π«
the whole friend group (kernel file ./drivers/base/devres.c):
__devres_alloc_node(9)devres_for_each_res(9)devres_free(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_add_action(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)
like, that's the whole group chat, go say hi π«Ά
ngl bestie, if you're registering a devres that you did NOT get from devres_alloc, justβ¦ don't. that's the one thing this page is yelling at you about π
mwah π that's the page! it lives in ./drivers/base, the date on it is October 2026, and it was brought to you by the Kernel API Manual β go forth and register your resources responsibly, 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