[PATCH 6.18 048/122] of/reserved_mem: Simplify the logic of fdt_scan_reserved_mem_reg_nodes()

Greg Kroah-Hartman
2026-02-04T15:30:37Z

From: Yuntao Wang <yuntao.wang@linux.dev>

[ Upstream commit 85a8a30c5b8e0ffaaf9f4dc51550dc71a1100df4 ]

Use the existing helper functions to simplify the logic of
fdt_scan_reserved_mem_reg_nodes()

Signed-off-by: Yuntao Wang <yuntao.wang@linux.dev>
Link: https://patch.msgid.link/20251115134753.179931-8-yuntao.wang@linux.dev
Signed-off-by: Rob Herring (Arm) <robh@kernel.org>
Stable-dep-of: 0fd17e598333 ("of: reserved_mem: Allow reserved_mem framework detect "cma=" kernel param")
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
drivers/of/of_reserved_mem.c | 25 +++++++------------------
1 file changed, 7 insertions(+), 18 deletions(-)

diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c
index 2e9ea751ed2df..e5ea4f1e5eff7 100644
--- a/drivers/of/of_reserved_mem.c
+++ b/drivers/of/of_reserved_mem.c
@@ -230,12 +230,9 @@ static void __init __rmem_check_for_overlap(void);
*/
void __init fdt_scan_reserved_mem_reg_nodes(void)
{
- int t_len = (dt_root_addr_cells + dt_root_size_cells) * sizeof(__be32);
const void *fdt = initial_boot_params;
phys_addr_t base, size;
- const __be32 *prop;
int node, child;
- int len;

if (!fdt)
return;
@@ -256,29 +253,21 @@ void __init fdt_scan_reserved_mem_reg_nodes(void)

fdt_for_each_subnode(child, fdt, node) {
const char *uname;
+ u64 b, s;

- prop = of_get_flat_dt_prop(child, "reg", &len);
- if (!prop)
- continue;
if (!of_fdt_device_is_available(fdt, child))
continue;

- uname = fdt_get_name(fdt, child, NULL);
- if (len && len % t_len != 0) {
- pr_err("Reserved memory: invalid reg property in '%s', skipping node.\n",
- uname);
+ if (!of_flat_dt_get_addr_size(child, "reg", &b, &s))
continue;
- }

- if (len > t_len)
- pr_warn("%s() ignores %d regions in node '%s'\n",
- __func__, len / t_len - 1, uname);
+ base = b;
+ size = s;

- base = dt_mem_next_cell(dt_root_addr_cells, &prop);
- size = dt_mem_next_cell(dt_root_size_cells, &prop);
-
- if (size)
+ if (size) {
+ uname = fdt_get_name(fdt, child, NULL);
fdt_reserved_mem_save_node(child, uname, base, size);
+ }
}

/* check for overlapping reserved regions */
--
2.51.0