diff options
| author | Yuntao Wang <yuntao.wang@linux.dev> | 2025-11-15 21:47:53 +0800 |
|---|---|---|
| committer | Rob Herring (Arm) <robh@kernel.org> | 2025-11-20 08:32:49 -0600 |
| commit | dd3feaf657a6fdf1a050bf94e0788a03d3f73dce (patch) | |
| tree | a872f38a184e399126f2361da1617795821cac8b | |
| parent | 85a8a30c5b8e0ffaaf9f4dc51550dc71a1100df4 (diff) | |
of/reserved_mem: Simplify the logic of __reserved_mem_alloc_size()
Use the existing helper functions to simplify the logic of
__reserved_mem_alloc_size()
Signed-off-by: Yuntao Wang <yuntao.wang@linux.dev>
Link: https://patch.msgid.link/20251115134753.179931-9-yuntao.wang@linux.dev
Signed-off-by: Rob Herring (Arm) <robh@kernel.org>
| -rw-r--r-- | drivers/of/of_reserved_mem.c | 21 |
1 files changed, 7 insertions, 14 deletions
diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c index 0ceb096c17e6..5619ec917858 100644 --- a/drivers/of/of_reserved_mem.c +++ b/drivers/of/of_reserved_mem.c @@ -385,10 +385,9 @@ static int __init __reserved_mem_alloc_in_range(phys_addr_t size, */ static int __init __reserved_mem_alloc_size(unsigned long node, const char *uname) { - int t_len = (dt_root_addr_cells + dt_root_size_cells) * sizeof(__be32); phys_addr_t start = 0, end = 0; phys_addr_t base = 0, align = 0, size; - int len; + int i, len; const __be32 *prop; bool nomap; int ret; @@ -422,19 +421,15 @@ static int __init __reserved_mem_alloc_size(unsigned long node, const char *unam && !nomap) align = max_t(phys_addr_t, align, CMA_MIN_ALIGNMENT_BYTES); - prop = of_get_flat_dt_prop(node, "alloc-ranges", &len); + prop = of_flat_dt_get_addr_size_prop(node, "alloc-ranges", &len); if (prop) { + for (i = 0; i < len; i++) { + u64 b, s; - if (len % t_len != 0) { - pr_err("invalid alloc-ranges property in '%s', skipping node.\n", - uname); - return -EINVAL; - } + of_flat_dt_read_addr_size(prop, i, &b, &s); - while (len > 0) { - start = dt_mem_next_cell(dt_root_addr_cells, &prop); - end = start + dt_mem_next_cell(dt_root_size_cells, - &prop); + start = b; + end = b + s; base = 0; ret = __reserved_mem_alloc_in_range(size, align, @@ -445,9 +440,7 @@ static int __init __reserved_mem_alloc_size(unsigned long node, const char *unam (unsigned long)(size / SZ_1M)); break; } - len -= t_len; } - } else { ret = early_init_dt_alloc_reserved_memory_arch(size, align, 0, 0, nomap, &base); |
