Skip to content

Commit b1e1c86

Browse files
rppttorvalds
authored andcommitted
sparc: 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 pcpu_populate_pte() and kernel_map_range() that were slightly refactored to accommodate the change. Link: http://lkml.kernel.org/r/1548057848-15136-16-git-send-email-rppt@linux.ibm.com Signed-off-by: Mike Rapoport <rppt@linux.ibm.com> Acked-by: David S. Miller <davem@davemloft.net> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: Christophe Leroy <christophe.leroy@c-s.fr> Cc: Christoph Hellwig <hch@lst.de> 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 d80db5c commit b1e1c86

File tree

5 files changed

+39
-0
lines changed

5 files changed

+39
-0
lines changed

arch/sparc/kernel/prom_32.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ void * __init prom_early_alloc(unsigned long size)
3333
void *ret;
3434

3535
ret = memblock_alloc(size, SMP_CACHE_BYTES);
36+
if (!ret)
37+
panic("%s: Failed to allocate %lu bytes\n", __func__, size);
3638

3739
prom_early_allocated += size;
3840

arch/sparc/kernel/setup_64.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,8 +624,14 @@ void __init alloc_irqstack_bootmem(void)
624624

625625
softirq_stack[i] = memblock_alloc_node(THREAD_SIZE,
626626
THREAD_SIZE, node);
627+
if (!softirq_stack[i])
628+
panic("%s: Failed to allocate %lu bytes align=%lx nid=%d\n",
629+
__func__, THREAD_SIZE, THREAD_SIZE, node);
627630
hardirq_stack[i] = memblock_alloc_node(THREAD_SIZE,
628631
THREAD_SIZE, node);
632+
if (!hardirq_stack[i])
633+
panic("%s: Failed to allocate %lu bytes align=%lx nid=%d\n",
634+
__func__, THREAD_SIZE, THREAD_SIZE, node);
629635
}
630636
}
631637

arch/sparc/kernel/smp_64.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1628,6 +1628,8 @@ static void __init pcpu_populate_pte(unsigned long addr)
16281628
pud_t *new;
16291629

16301630
new = memblock_alloc_from(PAGE_SIZE, PAGE_SIZE, PAGE_SIZE);
1631+
if (!new)
1632+
goto err_alloc;
16311633
pgd_populate(&init_mm, pgd, new);
16321634
}
16331635

@@ -1636,6 +1638,8 @@ static void __init pcpu_populate_pte(unsigned long addr)
16361638
pmd_t *new;
16371639

16381640
new = memblock_alloc_from(PAGE_SIZE, PAGE_SIZE, PAGE_SIZE);
1641+
if (!new)
1642+
goto err_alloc;
16391643
pud_populate(&init_mm, pud, new);
16401644
}
16411645

@@ -1644,8 +1648,16 @@ static void __init pcpu_populate_pte(unsigned long addr)
16441648
pte_t *new;
16451649

16461650
new = memblock_alloc_from(PAGE_SIZE, PAGE_SIZE, PAGE_SIZE);
1651+
if (!new)
1652+
goto err_alloc;
16471653
pmd_populate_kernel(&init_mm, pmd, new);
16481654
}
1655+
1656+
return;
1657+
1658+
err_alloc:
1659+
panic("%s: Failed to allocate %lu bytes align=%lx from=%lx\n",
1660+
__func__, PAGE_SIZE, PAGE_SIZE, PAGE_SIZE);
16491661
}
16501662

16511663
void __init setup_per_cpu_areas(void)

arch/sparc/mm/init_64.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1809,6 +1809,8 @@ static unsigned long __ref kernel_map_range(unsigned long pstart,
18091809

18101810
new = memblock_alloc_from(PAGE_SIZE, PAGE_SIZE,
18111811
PAGE_SIZE);
1812+
if (!new)
1813+
goto err_alloc;
18121814
alloc_bytes += PAGE_SIZE;
18131815
pgd_populate(&init_mm, pgd, new);
18141816
}
@@ -1822,6 +1824,8 @@ static unsigned long __ref kernel_map_range(unsigned long pstart,
18221824
}
18231825
new = memblock_alloc_from(PAGE_SIZE, PAGE_SIZE,
18241826
PAGE_SIZE);
1827+
if (!new)
1828+
goto err_alloc;
18251829
alloc_bytes += PAGE_SIZE;
18261830
pud_populate(&init_mm, pud, new);
18271831
}
@@ -1836,6 +1840,8 @@ static unsigned long __ref kernel_map_range(unsigned long pstart,
18361840
}
18371841
new = memblock_alloc_from(PAGE_SIZE, PAGE_SIZE,
18381842
PAGE_SIZE);
1843+
if (!new)
1844+
goto err_alloc;
18391845
alloc_bytes += PAGE_SIZE;
18401846
pmd_populate_kernel(&init_mm, pmd, new);
18411847
}
@@ -1855,6 +1861,11 @@ static unsigned long __ref kernel_map_range(unsigned long pstart,
18551861
}
18561862

18571863
return alloc_bytes;
1864+
1865+
err_alloc:
1866+
panic("%s: Failed to allocate %lu bytes align=%lx from=%lx\n",
1867+
__func__, PAGE_SIZE, PAGE_SIZE, PAGE_SIZE);
1868+
return -ENOMEM;
18581869
}
18591870

18601871
static void __init flush_all_kernel_tsbs(void)

arch/sparc/mm/srmmu.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,11 +305,17 @@ static void __init srmmu_nocache_init(void)
305305

306306
srmmu_nocache_pool = memblock_alloc(srmmu_nocache_size,
307307
SRMMU_NOCACHE_ALIGN_MAX);
308+
if (!srmmu_nocache_pool)
309+
panic("%s: Failed to allocate %lu bytes align=0x%x\n",
310+
__func__, srmmu_nocache_size, SRMMU_NOCACHE_ALIGN_MAX);
308311
memset(srmmu_nocache_pool, 0, srmmu_nocache_size);
309312

310313
srmmu_nocache_bitmap =
311314
memblock_alloc(BITS_TO_LONGS(bitmap_bits) * sizeof(long),
312315
SMP_CACHE_BYTES);
316+
if (!srmmu_nocache_bitmap)
317+
panic("%s: Failed to allocate %zu bytes\n", __func__,
318+
BITS_TO_LONGS(bitmap_bits) * sizeof(long));
313319
bit_map_init(&srmmu_nocache_map, srmmu_nocache_bitmap, bitmap_bits);
314320

315321
srmmu_swapper_pg_dir = __srmmu_get_nocache(SRMMU_PGD_TABLE_SIZE, SRMMU_PGD_TABLE_SIZE);
@@ -468,6 +474,8 @@ static void __init sparc_context_init(int numctx)
468474

469475
size = numctx * sizeof(struct ctx_list);
470476
ctx_list_pool = memblock_alloc(size, SMP_CACHE_BYTES);
477+
if (!ctx_list_pool)
478+
panic("%s: Failed to allocate %lu bytes\n", __func__, size);
471479

472480
for (ctx = 0; ctx < numctx; ctx++) {
473481
struct ctx_list *clist;

0 commit comments

Comments
 (0)