devres_get(9)
π devres_get β the kernel API manual, but make it make sense
okay so bestie, welcome to devres_get(9), from the Kernel API Manual. This is the "find it or make it, and do it atomically" girlie of the devres world. Let's get into it β¨
πΈ SYNOPSIS πΈ
void * devres_get (struct device *dev , void *new_res , dr_match_t match
, void *match_data );
that's the whole signature, no cap. four args, one void * coming back at you π«Ά
π ARGUMENTS π
devβ the device you're looking up devres for (or adding one to, bestie, it's giving both)new_resβ pointer to a new, already-initialized devres that gets added if nothing matches πmatchβ the match function. it's optional, so you can absolutely pass nothing here if that's your vibematch_dataβ the data you hand off to that match function
π¦ DESCRIPTION π¦
so what does it actually do? it goes looking for the latest devres of dev that has the same release function as new_res and for which match returns 1. that's the vibe check, okay? both boxes gotta be ticked.
and then the drama:
- if it finds one β
new_resgets freed π bye bestie - if it doesn't β
new_resgets added, and it's done atomically, which is the iconic part ngl
so it's find-or-add, and you never have to worry about a race sneaking in between the find and the add. main character energy fr fr π
π₯ RETURN π₯
pointer to the found-or-added devres. that's it. that's the whole return value. β¨
π SEE ALSO π
okay this list is long and honestly kind of iconic, so let's give it the respect it deserves β go read the kernel file ./drivers/base/devres.c and also:
__devres_alloc_node(9)devres_for_each_res(9)devres_free(9)devres_add(9)devres_find(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 I said. a list. but every single one of them is a baddie in her own right π
mwah π that's the page! this one comes to you straight out of ./drivers/base, dated October 2026 β so go forth, find your devres, add your devres, and do it atomically 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