unflatten_and_copy_device_tree();
 }
 
-static int memory_dtb;
-
-static int __init early_init_dt_find_memory(unsigned long node,
-                               const char *uname, int depth, void *data)
-{
-       if (depth == 1 && !strcmp(uname, "memory@0"))
-               memory_dtb = 1;
-
-       return 0;
-}
-
 void __init plat_mem_setup(void)
 {
        void *dtb;
        dtb = get_fdt();
        __dt_setup_arch(dtb);
 
-       of_scan_flat_dt(early_init_dt_find_memory, NULL);
-       if (memory_dtb)
-               of_scan_flat_dt(early_init_dt_scan_memory, NULL);
-       else if (soc_info.mem_detect)
+       if (!early_init_dt_scan_memory())
+               return;
+
+       if (soc_info.mem_detect)
                soc_info.mem_detect();
        else if (soc_info.mem_size)
                memblock_add(soc_info.mem_base, soc_info.mem_size * SZ_1M);
 
 }
 #endif /* CONFIG_PPC_PSERIES */
 
-static int __init early_init_dt_scan_memory_ppc(unsigned long node,
-                                               const char *uname,
-                                               int depth, void *data)
+static int __init early_init_dt_scan_memory_ppc(void)
 {
 #ifdef CONFIG_PPC_PSERIES
-       if (depth == 1 &&
-           strcmp(uname, "ibm,dynamic-reconfiguration-memory") == 0) {
+       const void *fdt = initial_boot_params;
+       int node = fdt_path_offset(fdt, "/ibm,dynamic-reconfiguration-memory");
+
+       if (node > 0)
                walk_drmem_lmbs_early(node, NULL, early_init_drmem_lmb);
-               return 0;
-       }
+
 #endif
-       
-       return early_init_dt_scan_memory(node, uname, depth, data);
+
+       return early_init_dt_scan_memory();
 }
 
 /*
 
        /* Scan memory nodes and rebuild MEMBLOCKs */
        early_init_dt_scan_root();
-       of_scan_flat_dt(early_init_dt_scan_memory_ppc, NULL);
+       early_init_dt_scan_memory_ppc();
 
        parse_early_param();
 
         */
        add_mem_to_memblock = 0;
        early_init_dt_scan_root();
-       of_scan_flat_dt(early_init_dt_scan_memory_ppc, NULL);
+       early_init_dt_scan_memory_ppc();
        add_mem_to_memblock = 1;
 
        if (size)
 
 /*
  * early_init_dt_scan_memory - Look for and parse memory nodes
  */
-int __init early_init_dt_scan_memory(unsigned long node, const char *uname,
-                                    int depth, void *data)
+int __init early_init_dt_scan_memory(void)
 {
-       const char *type = of_get_flat_dt_prop(node, "device_type", NULL);
-       const __be32 *reg, *endp;
-       int l;
-       bool hotpluggable;
+       int node;
+       const void *fdt = initial_boot_params;
 
-       /* We are scanning "memory" nodes only */
-       if (type == NULL || strcmp(type, "memory") != 0)
-               return 0;
+       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;
+               bool hotpluggable;
 
-       reg = of_get_flat_dt_prop(node, "linux,usable-memory", &l);
-       if (reg == NULL)
-               reg = of_get_flat_dt_prop(node, "reg", &l);
-       if (reg == NULL)
-               return 0;
+               /* We are scanning "memory" nodes only */
+               if (type == NULL || strcmp(type, "memory") != 0)
+                       continue;
 
-       endp = reg + (l / sizeof(__be32));
-       hotpluggable = of_get_flat_dt_prop(node, "hotpluggable", NULL);
+               reg = of_get_flat_dt_prop(node, "linux,usable-memory", &l);
+               if (reg == NULL)
+                       reg = of_get_flat_dt_prop(node, "reg", &l);
+               if (reg == NULL)
+                       continue;
 
-       pr_debug("memory scan node %s, reg size %d,\n", uname, l);
+               endp = reg + (l / sizeof(__be32));
+               hotpluggable = of_get_flat_dt_prop(node, "hotpluggable", NULL);
 
-       while ((endp - reg) >= (dt_root_addr_cells + dt_root_size_cells)) {
-               u64 base, size;
+               pr_debug("memory scan node %s, reg size %d,\n",
+                        fdt_get_name(fdt, node, NULL), l);
 
-               base = dt_mem_next_cell(dt_root_addr_cells, ®);
-               size = dt_mem_next_cell(dt_root_size_cells, ®);
+               while ((endp - reg) >= (dt_root_addr_cells + dt_root_size_cells)) {
+                       u64 base, size;
 
-               if (size == 0)
-                       continue;
-               pr_debug(" - %llx, %llx\n", base, size);
+                       base = dt_mem_next_cell(dt_root_addr_cells, ®);
+                       size = dt_mem_next_cell(dt_root_size_cells, ®);
 
-               early_init_dt_add_memory_arch(base, size);
+                       if (size == 0)
+                               continue;
+                       pr_debug(" - %llx, %llx\n", base, size);
 
-               if (!hotpluggable)
-                       continue;
+                       early_init_dt_add_memory_arch(base, size);
 
-               if (memblock_mark_hotplug(base, size))
-                       pr_warn("failed to mark hotplug range 0x%llx - 0x%llx\n",
-                               base, base + size);
-       }
+                       if (!hotpluggable)
+                               continue;
 
+                       if (memblock_mark_hotplug(base, size))
+                               pr_warn("failed to mark hotplug range 0x%llx - 0x%llx\n",
+                                       base, base + size);
+               }
+       }
        return 0;
 }
 
                pr_warn("No chosen node found, continuing without\n");
 
        /* Setup memory, calling early_init_dt_add_memory_arch */
-       of_scan_flat_dt(early_init_dt_scan_memory, NULL);
+       early_init_dt_scan_memory();
 
        /* Handle linux,usable-memory-range property */
        memblock_cap_memory_range(cap_mem_addr, cap_mem_size);