]> Gentwo Git Trees - linux/.git/commitdiff
of/fdt: Simplify the logic of early_init_dt_scan_memory()
authorYuntao Wang <yuntao.wang@linux.dev>
Sat, 15 Nov 2025 13:47:50 +0000 (21:47 +0800)
committerRob Herring (Arm) <robh@kernel.org>
Thu, 20 Nov 2025 14:32:48 +0000 (08:32 -0600)
Use the existing helper functions to simplify the logic of
early_init_dt_scan_memory()

Signed-off-by: Yuntao Wang <yuntao.wang@linux.dev>
Link: https://patch.msgid.link/20251115134753.179931-6-yuntao.wang@linux.dev
Signed-off-by: Rob Herring (Arm) <robh@kernel.org>
drivers/of/fdt.c

index fdaee4906836f9de1bdaa4254c81cbd23b971fdb..d378d4b4109f5c2069199f14b519c18fa4fbbc85 100644 (file)
@@ -1033,8 +1033,8 @@ int __init early_init_dt_scan_memory(void)
 
        fdt_for_each_subnode(node, fdt, 0) {
                const char *type = of_get_flat_dt_prop(node, "device_type", NULL);
-               const __be32 *reg, *endp;
-               int l;
+               const __be32 *reg;
+               int i, l;
                bool hotpluggable;
 
                /* We are scanning "memory" nodes only */
@@ -1044,23 +1044,21 @@ int __init early_init_dt_scan_memory(void)
                if (!of_fdt_device_is_available(fdt, node))
                        continue;
 
-               reg = of_get_flat_dt_prop(node, "linux,usable-memory", &l);
+               reg = of_flat_dt_get_addr_size_prop(node, "linux,usable-memory", &l);
                if (reg == NULL)
-                       reg = of_get_flat_dt_prop(node, "reg", &l);
+                       reg = of_flat_dt_get_addr_size_prop(node, "reg", &l);
                if (reg == NULL)
                        continue;
 
-               endp = reg + (l / sizeof(__be32));
                hotpluggable = of_get_flat_dt_prop(node, "hotpluggable", NULL);
 
-               pr_debug("memory scan node %s, reg size %d,\n",
+               pr_debug("memory scan node %s, reg {addr,size} entries %d,\n",
                         fdt_get_name(fdt, node, NULL), l);
 
-               while ((endp - reg) >= (dt_root_addr_cells + dt_root_size_cells)) {
+               for (i = 0; i < l; i++) {
                        u64 base, size;
 
-                       base = dt_mem_next_cell(dt_root_addr_cells, &reg);
-                       size = dt_mem_next_cell(dt_root_size_cells, &reg);
+                       of_flat_dt_read_addr_size(reg, i, &base, &size);
 
                        if (size == 0)
                                continue;