@@ -96,9 +96,6 @@ static void __init map_ram(void)
/* Alloc one page for holding PTE's... */
pte = memblock_alloc_raw(PAGE_SIZE, PAGE_SIZE);
- if (!pte)
- panic("%s: Failed to allocate page for PTEs\n",
- __func__);
set_pmd(pme, __pmd(_KERNPG_TABLE + __pa(pte)));
/* Fill the newly allocated page with PTE'S */
@@ -246,10 +246,6 @@ void __init allocate_paca_ptrs(void)
paca_ptrs_size = sizeof(struct paca_struct *) * nr_cpu_ids;
paca_ptrs = memblock_alloc_raw(paca_ptrs_size, SMP_CACHE_BYTES);
- if (!paca_ptrs)
- panic("Failed to allocate %d bytes for paca pointers\n",
- paca_ptrs_size);
-
memset(paca_ptrs, 0x88, paca_ptrs_size);
}
@@ -128,9 +128,6 @@ static void __init move_device_tree(void)
!memblock_is_memory(start + size - 1) ||
overlaps_crashkernel(start, size) || overlaps_initrd(start, size)) {
p = memblock_alloc_raw(size, PAGE_SIZE);
- if (!p)
- panic("Failed to allocate %lu bytes to move device tree\n",
- size);
memcpy(p, initial_boot_params, size);
initial_boot_params = p;
DBG("Moved device tree to 0x%px\n", p);
@@ -671,7 +671,7 @@ void __init plpks_early_init_devtree(void)
return;
}
- ospassword = memblock_alloc_raw(len, SMP_CACHE_BYTES);
+ ospassword = memblock_alloc_raw_no_panic(len, SMP_CACHE_BYTES);
if (!ospassword) {
pr_err("Error allocating memory for password.\n");
goto out;
@@ -418,20 +418,17 @@ static __always_inline void *memblock_alloc(phys_addr_t size, phys_addr_t align)
}
void *__memblock_alloc_panic(phys_addr_t size, phys_addr_t align,
- const char *func, bool should_panic);
+ const char *func, bool should_panic, bool raw);
#define memblock_alloc(size, align) \
- __memblock_alloc_panic(size, align, __func__, true)
+ __memblock_alloc_panic(size, align, __func__, true, false)
#define memblock_alloc_no_panic(size, align) \
- __memblock_alloc_panic(size, align, __func__, false)
+ __memblock_alloc_panic(size, align, __func__, false, false)
-static inline void *memblock_alloc_raw(phys_addr_t size,
- phys_addr_t align)
-{
- return memblock_alloc_try_nid_raw(size, align, MEMBLOCK_LOW_LIMIT,
- MEMBLOCK_ALLOC_ACCESSIBLE,
- NUMA_NO_NODE);
-}
+#define memblock_alloc_raw(size, align) \
+ __memblock_alloc_panic(size, align, __func__, true, true)
+#define memblock_alloc_raw_no_panic(size, align) \
+ __memblock_alloc_panic(size, align, __func__, false, true)
static inline void *memblock_alloc_from(phys_addr_t size,
phys_addr_t align,
@@ -1697,15 +1697,24 @@ void * __init memblock_alloc_try_nid(
* @align: alignment of the region and block's size
* @func: caller func name
* @should_panic: whether failed panic
+ * @raw: whether zeroing mem
*
* In case of failure, it calls panic with the formatted message.
* This function should not be used directly, please use the macro
* memblock_alloc and memblock_alloc_no_panic.
+ * memblock_alloc_raw and memblock_alloc_raw_no_panic.
*/
void *__init __memblock_alloc_panic(phys_addr_t size, phys_addr_t align,
- const char *func, bool should_panic)
+ const char *func, bool should_panic,
+ bool raw)
{
- void *addr = memblock_alloc_try_nid(size, align, MEMBLOCK_LOW_LIMIT,
+ void *addr;
+
+ if (unlikely(raw))
+ addr = memblock_alloc_try_nid_raw(size, align, MEMBLOCK_LOW_LIMIT,
+ MEMBLOCK_ALLOC_ACCESSIBLE, NUMA_NO_NODE);
+ else
+ addr = memblock_alloc_try_nid(size, align, MEMBLOCK_LOW_LIMIT,
MEMBLOCK_ALLOC_ACCESSIBLE, NUMA_NO_NODE);
if (unlikely(!addr && should_panic))
Just like memblock_alloc, the default failure behavior of memblock_alloc_raw is now modified to trigger a panic when allocation fails. memblock_alloc_no_panic has been introduced to handle cases where panic behavior is not desired. Signed-off-by: Guo Weikang <guoweikang.kernel@gmail.com> --- arch/openrisc/mm/init.c | 3 --- arch/powerpc/kernel/paca.c | 4 ---- arch/powerpc/kernel/prom.c | 3 --- arch/powerpc/platforms/pseries/plpks.c | 2 +- include/linux/memblock.h | 17 +++++++---------- mm/memblock.c | 13 +++++++++++-- 6 files changed, 19 insertions(+), 23 deletions(-)