Ensure that total memory size is page-aligned, because otherwise
mark_bootmem() gets upset.
This error case was triggered by using 64 KiB pages in the kernel
while arch/powerpc/boot/4xx.c arbitrarily reduced the amount of memory
by 4096 (to work around a chip bug that affects the last 256 bytes of
physical memory).
Signed-off-by: Hollis Blanchard <hollisb@us.ibm.com>
Signed-off-by: Paul Mackerras <paulus@samba.org>
 
 void __init early_init_devtree(void *params)
 {
+       unsigned long limit;
+
        DBG(" -> early_init_devtree(%p)\n", params);
 
        /* Setup flat device-tree pointer */
        early_reserve_mem();
        phyp_dump_reserve_mem();
 
-       lmb_enforce_memory_limit(memory_limit);
+       limit = memory_limit;
+       if (! limit) {
+               unsigned long memsize;
+
+               /* Ensure that total memory size is page-aligned, because
+                * otherwise mark_bootmem() gets upset. */
+               lmb_analyze();
+               memsize = lmb_phys_mem_size();
+               if ((memsize & PAGE_MASK) != memsize)
+                       limit = memsize & PAGE_MASK;
+       }
+       lmb_enforce_memory_limit(limit);
+
        lmb_analyze();
 
        DBG("Phys. mem: %lx\n", lmb_phys_mem_size());