devm_krealloc(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… 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, bestie
  • new_size β€” the new allocation size, yes we're resizing πŸ’…
  • gfp β€” the allocation gfp flags ⭐

πŸ¦‹ 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 ptr is NULL or ZERO_SIZE_PTR, it's the equivalent of devm_kmalloc πŸ’–
  • if new_size is zero, it frees the previously allocated memory and returns ZERO_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_kmalloc or when it's freeing resources when new_size is 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 πŸ‘‘


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