* [PATCH 1/6] of: reserved_mem: Don't report a freed region as allocated
@ 2026-12-01 9:41 Gopikrishna Garmidi
2026-12-04 22:46 ` Rob Herring
0 siblings, 1 reply; 2+ messages in thread
From: Gopikrishna Garmidi @ 2026-12-01 9:41 UTC (permalink / raw)
To: robh, saravanak, andersson, konrad.dybcio, dmitry.baryshkov
Cc: aisheng.dong, qperret, sibi.sankar, devicetree,
Gopikrishna Garmidi
early_init_dt_alloc_reserved_memory_arch() stores the allocated base in
*res_base before it marks the block nomap. If memblock_mark_nomap()
fails, the block is returned to memblock and an error is returned, but
*res_base still holds the freed address.
__reserved_mem_alloc_size() only treats base == 0 as failure, so for a
dynamically allocated no-map region (and for the last range of an
alloc-ranges list) it goes on to register memory that memblock may hand
out to someone else.
Only set *res_base once the allocation has fully succeeded.
Fixes: 7b25995f5319 ("of: of_reserved_mem: mark nomap memory instead of removing")
Signed-off-by: Gopikrishna Garmidi <gopikrishna.garmidi@oss.qualcomm.com>
---
Found by reading the code with the help of an LLM.
drivers/of/of_reserved_mem.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c
index a5cd8c2fffc3..d2aeb2c0a1e6 100644
--- a/drivers/of/of_reserved_mem.c
+++ b/drivers/of/of_reserved_mem.c
@@ -45,15 +45,16 @@ static int __init early_init_dt_alloc_reserved_memory_arch(phys_addr_t size,
if (!base)
return -ENOMEM;
- *res_base = base;
if (nomap) {
err = memblock_mark_nomap(base, size);
- if (err)
+ if (err) {
memblock_phys_free(base, size);
+ return err;
+ }
}
- if (!err)
- kmemleak_ignore_phys(base);
+ *res_base = base;
+ kmemleak_ignore_phys(base);
return err;
}
--
2.34.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH 1/6] of: reserved_mem: Don't report a freed region as allocated
2026-12-01 9:41 [PATCH 1/6] of: reserved_mem: Don't report a freed region as allocated Gopikrishna Garmidi
@ 2026-12-04 22:46 ` Rob Herring
0 siblings, 0 replies; 2+ messages in thread
From: Rob Herring @ 2026-12-04 22:46 UTC (permalink / raw)
To: Gopikrishna Garmidi
Cc: saravanak, andersson, konrad.dybcio, dmitry.baryshkov,
aisheng.dong, qperret, sibi.sankar, devicetree
On Tue, Dec 01, 2026 at 01:41:02AM -0800, Gopikrishna Garmidi wrote:
> early_init_dt_alloc_reserved_memory_arch() stores the allocated base in
> *res_base before it marks the block nomap. If memblock_mark_nomap()
> fails, the block is returned to memblock and an error is returned, but
> *res_base still holds the freed address.
>
> __reserved_mem_alloc_size() only treats base == 0 as failure, so for a
> dynamically allocated no-map region (and for the last range of an
> alloc-ranges list) it goes on to register memory that memblock may hand
> out to someone else.
>
> Only set *res_base once the allocation has fully succeeded.
>
> Fixes: 7b25995f5319 ("of: of_reserved_mem: mark nomap memory instead of removing")
> Signed-off-by: Gopikrishna Garmidi <gopikrishna.garmidi@oss.qualcomm.com>
> ---
> Found by reading the code with the help of an LLM.
Your email threading is broken and I don't have the rest of the series.
Please fix and re-send. Please Cc Marek Szyprowski on this as well.
Rob
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-04 22:47 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01 9:41 [PATCH 1/6] of: reserved_mem: Don't report a freed region as allocated Gopikrishna Garmidi
2026-12-04 22:46 ` Rob Herring
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox