summaryrefslogtreecommitdiffstats
path: root/arch/um
diff options
context:
space:
mode:
authorMike Rapoport <rppt@linux.ibm.com>2019-03-12 02:30:31 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2019-03-12 13:04:02 -0400
commit8a7f97b902f4fb0d94b355b6b3f1fbd7154cafb9 (patch)
tree5d246cde363bba8494a6e6755ad0a26c2dad5cb8 /arch/um
parenta0bf842e89a3842162aa8514b9bf4611c86fee10 (diff)
treewide: add checks for the return value of memblock_alloc*()
Add check for the return value of memblock_alloc*() functions and call panic() in case of error. The panic message repeats the one used by panicing memblock allocators with adjustment of parameters to include only relevant ones. The replacement was mostly automated with semantic patches like the one below with manual massaging of format strings. @@ expression ptr, size, align; @@ ptr = memblock_alloc(size, align); + if (!ptr) + panic("%s: Failed to allocate %lu bytes align=0x%lx\n", __func__, size, align); [anders.roxell@linaro.org: use '%pa' with 'phys_addr_t' type] Link: http://lkml.kernel.org/r/20190131161046.21886-1-anders.roxell@linaro.org [rppt@linux.ibm.com: fix format strings for panics after memblock_alloc] Link: http://lkml.kernel.org/r/1548950940-15145-1-git-send-email-rppt@linux.ibm.com [rppt@linux.ibm.com: don't panic if the allocation in sparse_buffer_init fails] Link: http://lkml.kernel.org/r/20190131074018.GD28876@rapoport-lnx [akpm@linux-foundation.org: fix xtensa printk warning] Link: http://lkml.kernel.org/r/1548057848-15136-20-git-send-email-rppt@linux.ibm.com Signed-off-by: Mike Rapoport <rppt@linux.ibm.com> Signed-off-by: Anders Roxell <anders.roxell@linaro.org> Reviewed-by: Guo Ren <ren_guo@c-sky.com> [c-sky] Acked-by: Paul Burton <paul.burton@mips.com> [MIPS] Acked-by: Heiko Carstens <heiko.carstens@de.ibm.com> [s390] Reviewed-by: Juergen Gross <jgross@suse.com> [Xen] Reviewed-by: Geert Uytterhoeven <geert@linux-m68k.org> [m68k] Acked-by: Max Filippov <jcmvbkbc@gmail.com> [xtensa] 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: 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: Mark Salter <msalter@redhat.com> Cc: Matt Turner <mattst88@gmail.com> Cc: Michael Ellerman <mpe@ellerman.id.au> Cc: Michal Simek <monstr@monstr.eu> 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>
Diffstat (limited to 'arch/um')
-rw-r--r--arch/um/drivers/net_kern.c3
-rw-r--r--arch/um/drivers/vector_kern.c3
-rw-r--r--arch/um/kernel/initrd.c2
-rw-r--r--arch/um/kernel/mem.c16
4 files changed, 24 insertions, 0 deletions
diff --git a/arch/um/drivers/net_kern.c b/arch/um/drivers/net_kern.c
index d80cfb1d9430..6e5be5fb4143 100644
--- a/arch/um/drivers/net_kern.c
+++ b/arch/um/drivers/net_kern.c
@@ -649,6 +649,9 @@ static int __init eth_setup(char *str)
649 } 649 }
650 650
651 new = memblock_alloc(sizeof(*new), SMP_CACHE_BYTES); 651 new = memblock_alloc(sizeof(*new), SMP_CACHE_BYTES);
652 if (!new)
653 panic("%s: Failed to allocate %zu bytes\n", __func__,
654 sizeof(*new));
652 655
653 INIT_LIST_HEAD(&new->list); 656 INIT_LIST_HEAD(&new->list);
654 new->index = n; 657 new->index = n;
diff --git a/arch/um/drivers/vector_kern.c b/arch/um/drivers/vector_kern.c
index 046fa9ea0ccc..596e7056f376 100644
--- a/arch/um/drivers/vector_kern.c
+++ b/arch/um/drivers/vector_kern.c
@@ -1576,6 +1576,9 @@ static int __init vector_setup(char *str)
1576 return 1; 1576 return 1;
1577 } 1577 }
1578 new = memblock_alloc(sizeof(*new), SMP_CACHE_BYTES); 1578 new = memblock_alloc(sizeof(*new), SMP_CACHE_BYTES);
1579 if (!new)
1580 panic("%s: Failed to allocate %zu bytes\n", __func__,
1581 sizeof(*new));
1579 INIT_LIST_HEAD(&new->list); 1582 INIT_LIST_HEAD(&new->list);
1580 new->unit = n; 1583 new->unit = n;
1581 new->arguments = str; 1584 new->arguments = str;
diff --git a/arch/um/kernel/initrd.c b/arch/um/kernel/initrd.c
index ce169ea87e61..1dcd310cb34d 100644
--- a/arch/um/kernel/initrd.c
+++ b/arch/um/kernel/initrd.c
@@ -37,6 +37,8 @@ int __init read_initrd(void)
37 } 37 }
38 38
39 area = memblock_alloc(size, SMP_CACHE_BYTES); 39 area = memblock_alloc(size, SMP_CACHE_BYTES);
40 if (!area)
41 panic("%s: Failed to allocate %llu bytes\n", __func__, size);
40 42
41 if (load_initrd(initrd, area, size) == -1) 43 if (load_initrd(initrd, area, size) == -1)
42 return 0; 44 return 0;
diff --git a/arch/um/kernel/mem.c b/arch/um/kernel/mem.c
index 799b571a8f88..99aa11bf53d1 100644
--- a/arch/um/kernel/mem.c
+++ b/arch/um/kernel/mem.c
@@ -66,6 +66,10 @@ static void __init one_page_table_init(pmd_t *pmd)
66 if (pmd_none(*pmd)) { 66 if (pmd_none(*pmd)) {
67 pte_t *pte = (pte_t *) memblock_alloc_low(PAGE_SIZE, 67 pte_t *pte = (pte_t *) memblock_alloc_low(PAGE_SIZE,
68 PAGE_SIZE); 68 PAGE_SIZE);
69 if (!pte)
70 panic("%s: Failed to allocate %lu bytes align=%lx\n",
71 __func__, PAGE_SIZE, PAGE_SIZE);
72
69 set_pmd(pmd, __pmd(_KERNPG_TABLE + 73 set_pmd(pmd, __pmd(_KERNPG_TABLE +
70 (unsigned long) __pa(pte))); 74 (unsigned long) __pa(pte)));
71 if (pte != pte_offset_kernel(pmd, 0)) 75 if (pte != pte_offset_kernel(pmd, 0))
@@ -77,6 +81,10 @@ static void __init one_md_table_init(pud_t *pud)
77{ 81{
78#ifdef CONFIG_3_LEVEL_PGTABLES 82#ifdef CONFIG_3_LEVEL_PGTABLES
79 pmd_t *pmd_table = (pmd_t *) memblock_alloc_low(PAGE_SIZE, PAGE_SIZE); 83 pmd_t *pmd_table = (pmd_t *) memblock_alloc_low(PAGE_SIZE, PAGE_SIZE);
84 if (!pmd_table)
85 panic("%s: Failed to allocate %lu bytes align=%lx\n",
86 __func__, PAGE_SIZE, PAGE_SIZE);
87
80 set_pud(pud, __pud(_KERNPG_TABLE + (unsigned long) __pa(pmd_table))); 88 set_pud(pud, __pud(_KERNPG_TABLE + (unsigned long) __pa(pmd_table)));
81 if (pmd_table != pmd_offset(pud, 0)) 89 if (pmd_table != pmd_offset(pud, 0))
82 BUG(); 90 BUG();
@@ -126,6 +134,10 @@ static void __init fixaddr_user_init( void)
126 134
127 fixrange_init( FIXADDR_USER_START, FIXADDR_USER_END, swapper_pg_dir); 135 fixrange_init( FIXADDR_USER_START, FIXADDR_USER_END, swapper_pg_dir);
128 v = (unsigned long) memblock_alloc_low(size, PAGE_SIZE); 136 v = (unsigned long) memblock_alloc_low(size, PAGE_SIZE);
137 if (!v)
138 panic("%s: Failed to allocate %lu bytes align=%lx\n",
139 __func__, size, PAGE_SIZE);
140
129 memcpy((void *) v , (void *) FIXADDR_USER_START, size); 141 memcpy((void *) v , (void *) FIXADDR_USER_START, size);
130 p = __pa(v); 142 p = __pa(v);
131 for ( ; size > 0; size -= PAGE_SIZE, vaddr += PAGE_SIZE, 143 for ( ; size > 0; size -= PAGE_SIZE, vaddr += PAGE_SIZE,
@@ -146,6 +158,10 @@ void __init paging_init(void)
146 158
147 empty_zero_page = (unsigned long *) memblock_alloc_low(PAGE_SIZE, 159 empty_zero_page = (unsigned long *) memblock_alloc_low(PAGE_SIZE,
148 PAGE_SIZE); 160 PAGE_SIZE);
161 if (!empty_zero_page)
162 panic("%s: Failed to allocate %lu bytes align=%lx\n",
163 __func__, PAGE_SIZE, PAGE_SIZE);
164
149 for (i = 0; i < ARRAY_SIZE(zones_size); i++) 165 for (i = 0; i < ARRAY_SIZE(zones_size); i++)
150 zones_size[i] = 0; 166 zones_size[i] = 0;
151 167