of: ignore sub-page memory regions
authorMike Rapoport <rppt@linux.vnet.ibm.com>
Fri, 26 Oct 2018 22:04:48 +0000 (15:04 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 26 Oct 2018 23:25:20 +0000 (16:25 -0700)
Memory region size is rounded down to page boundary and with sub-page
region it becomes 0 and there is no point to add an empty region.
Moreover, when the base is less than PAGE_SIZE we get a bogus size as
(base + size - 1) evaluates to -1.

8cccffc52694 ("of: check for size < 0 after rounding in
early_init_dt_add_memory_arch") introduced a test for wrap around for the
case when base is not page aligned, the same test can be used to ignore
sub-page region sizes.

Link: http://lkml.kernel.org/r/1533326330-31677-3-git-send-email-rppt@linux.vnet.ibm.com
Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>
Reviewed-by: Rob Herring <robh@kernel.org>
Cc: Guan Xuetao <gxt@pku.edu.cn>
Cc: Ley Foon Tan <ley.foon.tan@intel.com>
Cc: Richard Kuo <rkuo@codeaurora.org>
Cc: Richard Weinberger <richard@nod.at>
Cc: Michal Hocko <mhocko@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
drivers/of/fdt.c

index 800ad252cf9c635935f1a0ab75b14ae0b16bc003..76c83c1ffeda9368c4d464e486d3a1d529fbf15b 100644 (file)
@@ -1127,12 +1127,13 @@ void __init __weak early_init_dt_add_memory_arch(u64 base, u64 size)
 {
        const u64 phys_offset = MIN_MEMBLOCK_ADDR;
 
 {
        const u64 phys_offset = MIN_MEMBLOCK_ADDR;
 
+       if (size < PAGE_SIZE - (base & ~PAGE_MASK)) {
+               pr_warn("Ignoring memory block 0x%llx - 0x%llx\n",
+                       base, base + size);
+               return;
+       }
+
        if (!PAGE_ALIGNED(base)) {
        if (!PAGE_ALIGNED(base)) {
-               if (size < PAGE_SIZE - (base & ~PAGE_MASK)) {
-                       pr_warn("Ignoring memory block 0x%llx - 0x%llx\n",
-                               base, base + size);
-                       return;
-               }
                size -= PAGE_SIZE - (base & ~PAGE_MASK);
                base = PAGE_ALIGN(base);
        }
                size -= PAGE_SIZE - (base & ~PAGE_MASK);
                base = PAGE_ALIGN(base);
        }