[PATCH] devres: update node debug info on in-place devm_krealloc()
From: Eric Yun Lin Chiang
Date: Wed Dec 02 2026 - 19:57:51 EST
When the new size still fits in the existing allocation,
devm_krealloc() returns the old pointer without touching the node's
debug info, so the node keeps the size of the original request.
devres_log() and the devres_log tracepoint then report a stale size
for the resource: a buffer grown in place from 1000 to 1500 bytes, or
shrunk to 600 bytes, is still reported as 1000 bytes.
Commit f813ec9e84b4 ("devres: fix missing node debug info in
devm_krealloc()") added the debug info for nodes newly allocated by
devm_krealloc(); do the same on the in-place path, so the recorded
size always matches the size the caller asked for.
Fixes: f82485722e5d ("devres: provide devm_krealloc()")
Signed-off-by: Eric Yun Lin Chiang <ericyunlinchiang@xxxxxxxxx>
---
Notes (not for the changelog):
- Tool use: the problem was found, and this change and its test
drafted, with the help of an AI coding assistant (Claude).
- Reproducer and test (UML, KUnit test written for this purpose and not
part of this patch; base commit below):
devm_kzalloc(dev, 1000) -> devm_krealloc(1500) in place
-> devm_krealloc(600) in place -> devm_krealloc(3000) new node
node size read back after each step:
without this patch: 1000, 1000, 3000 (test fails)
with this patch: 1500, 600, 3000 (test passes)
Data in [0, 600) is preserved across the final copy in both cases.
W=1 build of drivers/base/devres.o: no new warnings.
Not tested on real hardware.
- Locking: the node's debug info is updated without taking
dev->devres_lock and without find_dr(), matching how this path
already trusts @ptr for the ksize() call above. If preferred, the
update can be done under devres_lock after find_dr(), like the
new-node path does.
- Stable: before v7.1 the helper is still called set_node_dbginfo()
(renamed by ba424bc2c7bb ("devres: rename and export
set_node_dbginfo()")). On 6.18.66 the change applies cleanly but
needs that rename to build; with it, the same KUnit test gives node
sizes 1000, 1000, 3000 without the change and 1500, 600, 3000 with
it (UML). Older trees not checked. Happy to send the backport.
drivers/base/devres.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/drivers/base/devres.c b/drivers/base/devres.c
index 9d9842fc5a19..d1baf7c44435 100644
--- a/drivers/base/devres.c
+++ b/drivers/base/devres.c
@@ -1010,10 +1010,14 @@ void *devm_krealloc(struct device *dev, void *ptr, size_t new_size, gfp_t gfp)
/*
* If new size is smaller or equal to the actual number of bytes
- * allocated previously - just return the same pointer.
+ * allocated previously - just update the node's debug info and
+ * return the same pointer.
*/
- if (total_new_size <= total_old_size)
+ if (total_new_size <= total_old_size) {
+ devres_set_node_dbginfo(&container_of(ptr, struct devres, data)->node,
+ "devm_krealloc_release", new_size);
return ptr;
+ }
/*
* Otherwise: allocate new, larger chunk. We need to allocate before
base-commit: 19cc08c1a6a650f8e54c0461ff198be6448f425d
--
2.43.0