devm_krealloc(9)
π devm_krealloc(9) β from the Kernel API Manual, bestie
okay so picture this: it's giving krealloc() but make it managed β¨ this one lives in the Kernel API Manual and honestly? she's iconic.
π NAME π
devm_krealloc β the resource-managed krealloc(), fr fr. like regular krealloc but the kernel cleans up after you so you don't have to π«Ά
β¨ SYNOPSIS β¨
void * devm_krealloc (struct device *dev , void *ptr , size_t new_size ,
gfp_t gfp );
that's the whole vibe check right there π
πΈ ARGUMENTS πΈ
devβ the device you're re-allocating memory for πptrβ pointer to the memory chunk you wanna re-allocate, bestienew_sizeβ the new allocation size, yes we're resizing πgfpβ the allocationgfpflags β
π¦ DESCRIPTION π¦
Managed krealloc. she resizes the memory chunk that was allocated with devm_kmalloc. π
Behaves similarly to regular krealloc β and here's the breakdown so you're never confused, iykyk:
- if
ptrisNULLorZERO_SIZE_PTR, it's the equivalent ofdevm_kmallocπ - if
new_sizeis zero, it frees the previously allocated memory and returnsZERO_SIZE_PTRπ - this function doesn't change the order in which the release callback for the re-alloc'ed devres will be called β except when it's falling back to
devm_kmallocor when it's freeing resources whennew_sizeis zero π - the contents of the memory are preserved up to the lesser of new and old sizes π§ no cap, that part's important
bestie pls note: the release-callback-ordering thing is a real caveat, not just me being dramatic β the order stays the same except in those two fallback/free cases. periodt.
π SEE ALSO π
kernel file ./drivers/base/devres.c and honestly the whole devres friend group π
__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_add_action(9)devm_remove_action_nowarn(9)devm_release_action(9)devm_kmalloc(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)
and that's the page, bestie π coming at you from ./drivers/base, dated October 2026 β slay, go free your memory responsibly πβ¨
π¦ 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