if (ret < 0)
                        break;
+
 #ifdef CONFIG_DEBUG_PAGEALLOC
-               if ((paddr >> PAGE_SHIFT) < linear_map_hash_count)
+               if (debug_pagealloc_enabled() &&
+                       (paddr >> PAGE_SHIFT) < linear_map_hash_count)
                        linear_map_hash_slots[paddr >> PAGE_SHIFT] = ret | 0x80;
 #endif /* CONFIG_DEBUG_PAGEALLOC */
        }
        if (mmu_has_feature(MMU_FTR_16M_PAGE))
                memcpy(mmu_psize_defs, mmu_psize_defaults_gp,
                       sizeof(mmu_psize_defaults_gp));
- found:
-#ifndef CONFIG_DEBUG_PAGEALLOC
-       /*
-        * Pick a size for the linear mapping. Currently, we only support
-        * 16M, 1M and 4K which is the default
-        */
-       if (mmu_psize_defs[MMU_PAGE_16M].shift)
-               mmu_linear_psize = MMU_PAGE_16M;
-       else if (mmu_psize_defs[MMU_PAGE_1M].shift)
-               mmu_linear_psize = MMU_PAGE_1M;
-#endif /* CONFIG_DEBUG_PAGEALLOC */
+found:
+       if (!debug_pagealloc_enabled()) {
+               /*
+                * Pick a size for the linear mapping. Currently, we only
+                * support 16M, 1M and 4K which is the default
+                */
+               if (mmu_psize_defs[MMU_PAGE_16M].shift)
+                       mmu_linear_psize = MMU_PAGE_16M;
+               else if (mmu_psize_defs[MMU_PAGE_1M].shift)
+                       mmu_linear_psize = MMU_PAGE_1M;
+       }
 
 #ifdef CONFIG_PPC_64K_PAGES
        /*
        prot = pgprot_val(PAGE_KERNEL);
 
 #ifdef CONFIG_DEBUG_PAGEALLOC
-       linear_map_hash_count = memblock_end_of_DRAM() >> PAGE_SHIFT;
-       linear_map_hash_slots = __va(memblock_alloc_base(linear_map_hash_count,
-                                                   1, ppc64_rma_size));
-       memset(linear_map_hash_slots, 0, linear_map_hash_count);
+       if (debug_pagealloc_enabled()) {
+               linear_map_hash_count = memblock_end_of_DRAM() >> PAGE_SHIFT;
+               linear_map_hash_slots = __va(memblock_alloc_base(
+                               linear_map_hash_count, 1, ppc64_rma_size));
+               memset(linear_map_hash_slots, 0, linear_map_hash_count);
+       }
 #endif /* CONFIG_DEBUG_PAGEALLOC */
 
        /* On U3 based machines, we need to reserve the DART area and