[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251115134753.179931-4-yuntao.wang@linux.dev>
Date: Sat, 15 Nov 2025 21:47:48 +0800
From: Yuntao Wang <yuntao.wang@...ux.dev>
To: Rob Herring <robh@...nel.org>,
Saravana Kannan <saravanak@...gle.com>
Cc: Geert Uytterhoeven <geert+renesas@...der.be>,
Catalin Marinas <catalin.marinas@....com>,
James Morse <james.morse@....com>,
Baoquan He <bhe@...hat.com>,
Zhen Lei <thunder.leizhen@...wei.com>,
Ard Biesheuvel <ardb@...nel.org>,
Mark Rutland <mark.rutland@....com>,
Geoff Levand <geoff@...radead.org>,
Andrew Morton <akpm@...ux-foundation.org>,
Changyuan Lyu <changyuanl@...gle.com>,
Alexander Graf <graf@...zon.com>,
"Mike Rapoport (Microsoft)" <rppt@...nel.org>,
devicetree@...r.kernel.org,
linux-kernel@...r.kernel.org,
Yuntao Wang <yuntao.wang@...ux.dev>
Subject: [PATCH v3 3/8] of/fdt: Fix the len check in early_init_dt_check_for_usable_mem_range()
The len value is in bytes, while `dt_root_addr_cells + dt_root_size_cells`
is in cells (4 bytes per cell). Modulo calculation between them is
incorrect, the units must be converted first.
Use helper functions to simplify the code and fix this issue.
Fixes: fb319e77a0e7 ("of: fdt: Add memory for devices by DT property "linux,usable-memory-range"")
Fixes: 2af2b50acf9b9c38 ("of: fdt: Add generic support for handling usable memory range property")
Fixes: 8f579b1c4e347b23 ("arm64: limit memory regions based on DT property, usable-memory-range")
Signed-off-by: Yuntao Wang <yuntao.wang@...ux.dev>
---
drivers/of/fdt.c | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index b45f60dccd7c..ea37ba694bcd 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -884,8 +884,9 @@ static unsigned long chosen_node_offset = -FDT_ERR_NOTFOUND;
void __init early_init_dt_check_for_usable_mem_range(void)
{
struct memblock_region rgn[MAX_USABLE_RANGES] = {0};
- const __be32 *prop, *endp;
+ const __be32 *prop;
int len, i;
+ u64 base, size;
unsigned long node = chosen_node_offset;
if ((long)node < 0)
@@ -893,14 +894,17 @@ void __init early_init_dt_check_for_usable_mem_range(void)
pr_debug("Looking for usable-memory-range property... ");
- prop = of_get_flat_dt_prop(node, "linux,usable-memory-range", &len);
- if (!prop || (len % (dt_root_addr_cells + dt_root_size_cells)))
+ prop = of_flat_dt_get_addr_size_prop(node, "linux,usable-memory-range",
+ &len);
+ if (!prop)
return;
- endp = prop + (len / sizeof(__be32));
- for (i = 0; i < MAX_USABLE_RANGES && prop < endp; i++) {
- rgn[i].base = dt_mem_next_cell(dt_root_addr_cells, &prop);
- rgn[i].size = dt_mem_next_cell(dt_root_size_cells, &prop);
+ len = min(len, MAX_USABLE_RANGES);
+
+ for (i = 0; i < len; i++) {
+ of_flat_dt_read_addr_size(prop, i, &base, &size);
+ rgn[i].base = base;
+ rgn[i].size = size;
pr_debug("cap_mem_regions[%d]: base=%pa, size=%pa\n",
i, &rgn[i].base, &rgn[i].size);
--
2.51.0
Powered by blists - more mailing lists