Merge tag 'backport/v3.14.24-ltsi-rc1/sata-rcar-to-v3.18-rc5' into backport/v3.14...
[platform/adaptation/renesas_rcar/renesas_kernel.git] / mm / nobootmem.c
index 19121ce..f73f298 100644 (file)
@@ -45,7 +45,9 @@ static void * __init __alloc_memory_core_early(int nid, u64 size, u64 align,
        if (!addr)
                return NULL;
 
-       memblock_reserve(addr, size);
+       if (memblock_reserve(addr, size))
+               return NULL;
+
        ptr = phys_to_virt(addr);
        memset(ptr, 0, size);
        /*
@@ -114,16 +116,27 @@ static unsigned long __init __free_memory_core(phys_addr_t start,
 static unsigned long __init free_low_memory_core_early(void)
 {
        unsigned long count = 0;
-       phys_addr_t start, end, size;
+       phys_addr_t start, end;
        u64 i;
 
        for_each_free_mem_range(i, NUMA_NO_NODE, &start, &end, NULL)
                count += __free_memory_core(start, end);
 
-       /* free range that is used for reserved array if we allocate it */
-       size = get_allocated_memblock_reserved_regions_info(&start);
-       if (size)
-               count += __free_memory_core(start, start + size);
+#ifdef CONFIG_ARCH_DISCARD_MEMBLOCK
+       {
+               phys_addr_t size;
+
+               /* Free memblock.reserved array if it was allocated */
+               size = get_allocated_memblock_reserved_regions_info(&start);
+               if (size)
+                       count += __free_memory_core(start, start + size);
+
+               /* Free memblock.memory array if it was allocated */
+               size = get_allocated_memblock_memory_regions_info(&start);
+               if (size)
+                       count += __free_memory_core(start, start + size);
+       }
+#endif
 
        return count;
 }