Skip to content

Commit d80db5c

Browse files
rppttorvalds
authored andcommitted
ia64: add checks for the return value of memblock_alloc*()
Add panic() calls if memblock_alloc*() returns NULL. Most of the changes are simply addition of if(!ptr) panic(); statements after the calls to memblock_alloc*() variants. Exceptions are create_mem_map_page_table() and ia64_log_init() that were slightly refactored to accommodate the change. Link: http://lkml.kernel.org/r/1548057848-15136-15-git-send-email-rppt@linux.ibm.com Signed-off-by: Mike Rapoport <rppt@linux.ibm.com> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: Christophe Leroy <christophe.leroy@c-s.fr> Cc: Christoph Hellwig <hch@lst.de> Cc: "David S. Miller" <davem@davemloft.net> Cc: Dennis Zhou <dennis@kernel.org> Cc: Geert Uytterhoeven <geert@linux-m68k.org> Cc: Greentime Hu <green.hu@gmail.com> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: Guan Xuetao <gxt@pku.edu.cn> Cc: Guo Ren <guoren@kernel.org> Cc: Guo Ren <ren_guo@c-sky.com> [c-sky] Cc: Heiko Carstens <heiko.carstens@de.ibm.com> Cc: Juergen Gross <jgross@suse.com> [Xen] Cc: Mark Salter <msalter@redhat.com> Cc: Matt Turner <mattst88@gmail.com> Cc: Max Filippov <jcmvbkbc@gmail.com> Cc: Michael Ellerman <mpe@ellerman.id.au> Cc: Michal Simek <monstr@monstr.eu> Cc: Paul Burton <paul.burton@mips.com> Cc: Petr Mladek <pmladek@suse.com> Cc: Richard Weinberger <richard@nod.at> Cc: Rich Felker <dalias@libc.org> Cc: Rob Herring <robh+dt@kernel.org> Cc: Rob Herring <robh@kernel.org> Cc: Russell King <linux@armlinux.org.uk> Cc: Stafford Horne <shorne@gmail.com> Cc: Tony Luck <tony.luck@intel.com> Cc: Vineet Gupta <vgupta@synopsys.com> Cc: Yoshinori Sato <ysato@users.sourceforge.jp> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 0240dfd commit d80db5c

File tree

7 files changed

+74
-17
lines changed

7 files changed

+74
-17
lines changed

arch/ia64/kernel/mca.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -359,11 +359,6 @@ typedef struct ia64_state_log_s
359359

360360
static ia64_state_log_t ia64_state_log[IA64_MAX_LOG_TYPES];
361361

362-
#define IA64_LOG_ALLOCATE(it, size) \
363-
{ia64_state_log[it].isl_log[IA64_LOG_CURR_INDEX(it)] = \
364-
(ia64_err_rec_t *)memblock_alloc(size, SMP_CACHE_BYTES); \
365-
ia64_state_log[it].isl_log[IA64_LOG_NEXT_INDEX(it)] = \
366-
(ia64_err_rec_t *)memblock_alloc(size, SMP_CACHE_BYTES);}
367362
#define IA64_LOG_LOCK_INIT(it) spin_lock_init(&ia64_state_log[it].isl_lock)
368363
#define IA64_LOG_LOCK(it) spin_lock_irqsave(&ia64_state_log[it].isl_lock, s)
369364
#define IA64_LOG_UNLOCK(it) spin_unlock_irqrestore(&ia64_state_log[it].isl_lock,s)
@@ -378,6 +373,19 @@ static ia64_state_log_t ia64_state_log[IA64_MAX_LOG_TYPES];
378373
#define IA64_LOG_CURR_BUFFER(it) (void *)((ia64_state_log[it].isl_log[IA64_LOG_CURR_INDEX(it)]))
379374
#define IA64_LOG_COUNT(it) ia64_state_log[it].isl_count
380375

376+
static inline void ia64_log_allocate(int it, u64 size)
377+
{
378+
ia64_state_log[it].isl_log[IA64_LOG_CURR_INDEX(it)] =
379+
(ia64_err_rec_t *)memblock_alloc(size, SMP_CACHE_BYTES);
380+
if (!ia64_state_log[it].isl_log[IA64_LOG_CURR_INDEX(it)])
381+
panic("%s: Failed to allocate %llu bytes\n", __func__, size);
382+
383+
ia64_state_log[it].isl_log[IA64_LOG_NEXT_INDEX(it)] =
384+
(ia64_err_rec_t *)memblock_alloc(size, SMP_CACHE_BYTES);
385+
if (!ia64_state_log[it].isl_log[IA64_LOG_NEXT_INDEX(it)])
386+
panic("%s: Failed to allocate %llu bytes\n", __func__, size);
387+
}
388+
381389
/*
382390
* ia64_log_init
383391
* Reset the OS ia64 log buffer
@@ -399,7 +407,7 @@ ia64_log_init(int sal_info_type)
399407
return;
400408

401409
// set up OS data structures to hold error info
402-
IA64_LOG_ALLOCATE(sal_info_type, max_size);
410+
ia64_log_allocate(sal_info_type, max_size);
403411
}
404412

405413
/*

arch/ia64/mm/contig.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,13 @@ void *per_cpu_init(void)
8484
static inline void
8585
alloc_per_cpu_data(void)
8686
{
87-
cpu_data = memblock_alloc_from(PERCPU_PAGE_SIZE * num_possible_cpus(),
88-
PERCPU_PAGE_SIZE,
87+
size_t size = PERCPU_PAGE_SIZE * num_possible_cpus();
88+
89+
cpu_data = memblock_alloc_from(size, PERCPU_PAGE_SIZE,
8990
__pa(MAX_DMA_ADDRESS));
91+
if (!cpu_data)
92+
panic("%s: Failed to allocate %lu bytes align=%lx from=%lx\n",
93+
__func__, size, PERCPU_PAGE_SIZE, __pa(MAX_DMA_ADDRESS));
9094
}
9195

9296
/**

arch/ia64/mm/discontig.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,10 @@ static void __init *memory_less_node_alloc(int nid, unsigned long pernodesize)
454454
__pa(MAX_DMA_ADDRESS),
455455
MEMBLOCK_ALLOC_ACCESSIBLE,
456456
bestnode);
457+
if (!ptr)
458+
panic("%s: Failed to allocate %lu bytes align=0x%lx nid=%d from=%lx\n",
459+
__func__, pernodesize, PERCPU_PAGE_SIZE, bestnode,
460+
__pa(MAX_DMA_ADDRESS));
457461

458462
return ptr;
459463
}

arch/ia64/mm/init.c

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -444,23 +444,45 @@ int __init create_mem_map_page_table(u64 start, u64 end, void *arg)
444444

445445
for (address = start_page; address < end_page; address += PAGE_SIZE) {
446446
pgd = pgd_offset_k(address);
447-
if (pgd_none(*pgd))
448-
pgd_populate(&init_mm, pgd, memblock_alloc_node(PAGE_SIZE, PAGE_SIZE, node));
447+
if (pgd_none(*pgd)) {
448+
pud = memblock_alloc_node(PAGE_SIZE, PAGE_SIZE, node);
449+
if (!pud)
450+
goto err_alloc;
451+
pgd_populate(&init_mm, pgd, pud);
452+
}
449453
pud = pud_offset(pgd, address);
450454

451-
if (pud_none(*pud))
452-
pud_populate(&init_mm, pud, memblock_alloc_node(PAGE_SIZE, PAGE_SIZE, node));
455+
if (pud_none(*pud)) {
456+
pmd = memblock_alloc_node(PAGE_SIZE, PAGE_SIZE, node);
457+
if (!pmd)
458+
goto err_alloc;
459+
pud_populate(&init_mm, pud, pmd);
460+
}
453461
pmd = pmd_offset(pud, address);
454462

455-
if (pmd_none(*pmd))
456-
pmd_populate_kernel(&init_mm, pmd, memblock_alloc_node(PAGE_SIZE, PAGE_SIZE, node));
463+
if (pmd_none(*pmd)) {
464+
pte = memblock_alloc_node(PAGE_SIZE, PAGE_SIZE, node);
465+
if (!pte)
466+
goto err_alloc;
467+
pmd_populate_kernel(&init_mm, pmd, pte);
468+
}
457469
pte = pte_offset_kernel(pmd, address);
458470

459-
if (pte_none(*pte))
460-
set_pte(pte, pfn_pte(__pa(memblock_alloc_node(PAGE_SIZE, PAGE_SIZE, node)) >> PAGE_SHIFT,
471+
if (pte_none(*pte)) {
472+
void *page = memblock_alloc_node(PAGE_SIZE, PAGE_SIZE,
473+
node);
474+
if (!page)
475+
goto err_alloc;
476+
set_pte(pte, pfn_pte(__pa(page) >> PAGE_SHIFT,
461477
PAGE_KERNEL));
478+
}
462479
}
463480
return 0;
481+
482+
err_alloc:
483+
panic("%s: Failed to allocate %lu bytes align=0x%lx nid=%d\n",
484+
__func__, PAGE_SIZE, PAGE_SIZE, node);
485+
return -ENOMEM;
464486
}
465487

466488
struct memmap_init_callback_data {

arch/ia64/mm/tlb.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,14 @@ mmu_context_init (void)
6161
{
6262
ia64_ctx.bitmap = memblock_alloc((ia64_ctx.max_ctx + 1) >> 3,
6363
SMP_CACHE_BYTES);
64+
if (!ia64_ctx.bitmap)
65+
panic("%s: Failed to allocate %u bytes\n", __func__,
66+
(ia64_ctx.max_ctx + 1) >> 3);
6467
ia64_ctx.flushmap = memblock_alloc((ia64_ctx.max_ctx + 1) >> 3,
6568
SMP_CACHE_BYTES);
69+
if (!ia64_ctx.flushmap)
70+
panic("%s: Failed to allocate %u bytes\n", __func__,
71+
(ia64_ctx.max_ctx + 1) >> 3);
6672
}
6773

6874
/*

arch/ia64/sn/kernel/io_common.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,9 @@ void __init hubdev_init_node(nodepda_t * npda, cnodeid_t node)
394394
hubdev_info = (struct hubdev_info *)memblock_alloc_node(size,
395395
SMP_CACHE_BYTES,
396396
node);
397+
if (!hubdev_info)
398+
panic("%s: Failed to allocate %d bytes align=0x%x nid=%d\n",
399+
__func__, size, SMP_CACHE_BYTES, node);
397400

398401
npda->pdinfo = (void *)hubdev_info;
399402
}

arch/ia64/sn/kernel/setup.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,10 @@ static void __init sn_init_pdas(char **cmdline_p)
513513
nodepdaindr[cnode] =
514514
memblock_alloc_node(sizeof(nodepda_t), SMP_CACHE_BYTES,
515515
cnode);
516+
if (!nodepdaindr[cnode])
517+
panic("%s: Failed to allocate %lu bytes align=0x%x nid=%d\n",
518+
__func__, sizeof(nodepda_t), SMP_CACHE_BYTES,
519+
cnode);
516520
memset(nodepdaindr[cnode]->phys_cpuid, -1,
517521
sizeof(nodepdaindr[cnode]->phys_cpuid));
518522
spin_lock_init(&nodepdaindr[cnode]->ptc_lock);
@@ -521,9 +525,15 @@ static void __init sn_init_pdas(char **cmdline_p)
521525
/*
522526
* Allocate & initialize nodepda for TIOs. For now, put them on node 0.
523527
*/
524-
for (cnode = num_online_nodes(); cnode < num_cnodes; cnode++)
528+
for (cnode = num_online_nodes(); cnode < num_cnodes; cnode++) {
525529
nodepdaindr[cnode] =
526530
memblock_alloc_node(sizeof(nodepda_t), SMP_CACHE_BYTES, 0);
531+
if (!nodepdaindr[cnode])
532+
panic("%s: Failed to allocate %lu bytes align=0x%x nid=%d\n",
533+
__func__, sizeof(nodepda_t), SMP_CACHE_BYTES,
534+
cnode);
535+
}
536+
527537

528538
/*
529539
* Now copy the array of nodepda pointers to each nodepda.

0 commit comments

Comments
 (0)