Skip to content

Commit c884e32

Browse files
zijun-hugregkh
authored andcommitted
devres: Fix devm_krealloc() wasting memory
Driver API devm_krealloc() calls alloc_dr() with wrong argument @total_new_size, so causes more memory to be allocated than required fix this memory waste by using @new_size as the argument for alloc_dr(). Fixes: f824857 ("devres: provide devm_krealloc()") Cc: [email protected] Signed-off-by: Zijun Hu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 23c6859 commit c884e32

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

drivers/base/devres.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -896,9 +896,12 @@ void *devm_krealloc(struct device *dev, void *ptr, size_t new_size, gfp_t gfp)
896896
/*
897897
* Otherwise: allocate new, larger chunk. We need to allocate before
898898
* taking the lock as most probably the caller uses GFP_KERNEL.
899+
* alloc_dr() will call check_dr_size() to reserve extra memory
900+
* for struct devres automatically, so size @new_size user request
901+
* is delivered to it directly as devm_kmalloc() does.
899902
*/
900903
new_dr = alloc_dr(devm_kmalloc_release,
901-
total_new_size, gfp, dev_to_node(dev));
904+
new_size, gfp, dev_to_node(dev));
902905
if (!new_dr)
903906
return NULL;
904907

0 commit comments

Comments
 (0)