[PATCH v2 6/7] of/reserved_mem: Simplify the logic of __reserved_mem_reserve_reg()

Yuntao Wang
2025-11-13T15:53:03Z

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

Signed-off-by: Yuntao Wang <yuntao.wang@linux.dev>
---
drivers/of/of_reserved_mem.c | 14 +++++---------
1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c
index 2e9ea751ed2d..b8527f3e335e 100644
--- a/drivers/of/of_reserved_mem.c
+++ b/drivers/of/of_reserved_mem.c
@@ -154,17 +154,16 @@ static int __init early_init_dt_reserve_memory(phys_addr_t base,
static int __init __reserved_mem_reserve_reg(unsigned long node,
const char *uname)
{
- int t_len = (dt_root_addr_cells + dt_root_size_cells) * sizeof(__be32);
phys_addr_t base, size;
int len;
const __be32 *prop;
bool nomap;

- prop = of_get_flat_dt_prop(node, "reg", &len);
- if (!prop)
+ prop = of_fdt_get_addr_size_prop(node, "reg", &len);
+ if (!len)
return -ENOENT;

- if (len && len % t_len != 0) {
+ if (len < 0) {
pr_err("Reserved memory: invalid reg property in '%s', skipping node.\n",
uname);
return -EINVAL;
@@ -172,9 +171,8 @@ static int __init __reserved_mem_reserve_reg(unsigned long node,

nomap = of_get_flat_dt_prop(node, "no-map", NULL) != NULL;

- while (len >= t_len) {
- base = dt_mem_next_cell(dt_root_addr_cells, &prop);
- size = dt_mem_next_cell(dt_root_size_cells, &prop);
+ while (len-- > 0) {
+ of_fdt_read_addr_size(prop, &base, &size);

if (size && early_init_dt_reserve_memory(base, size, nomap) == 0) {
/* Architecture specific contiguous memory fixup. */
@@ -187,8 +185,6 @@ static int __init __reserved_mem_reserve_reg(unsigned long node,
pr_err("Reserved memory: failed to reserve memory for node '%s': base %pa, size %lu MiB\n",
uname, &base, (unsigned long)(size / SZ_1M));
}
-
- len -= t_len;
}
return 0;
}
--
2.51.0