Skip to content

Commit 8a7f97b

Browse files
rppttorvalds
authored andcommitted
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>
1 parent a0bf842 commit 8a7f97b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+411
-32
lines changed

arch/alpha/kernel/core_cia.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,9 @@ cia_prepare_tbia_workaround(int window)
332332

333333
/* Use minimal 1K map. */
334334
ppte = memblock_alloc(CIA_BROKEN_TBIA_SIZE, 32768);
335+
if (!ppte)
336+
panic("%s: Failed to allocate %u bytes align=0x%x\n",
337+
__func__, CIA_BROKEN_TBIA_SIZE, 32768);
335338
pte = (virt_to_phys(ppte) >> (PAGE_SHIFT - 1)) | 1;
336339

337340
for (i = 0; i < CIA_BROKEN_TBIA_SIZE / sizeof(unsigned long); ++i)

arch/alpha/kernel/core_marvel.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ mk_resource_name(int pe, int port, char *str)
8383

8484
sprintf(tmp, "PCI %s PE %d PORT %d", str, pe, port);
8585
name = memblock_alloc(strlen(tmp) + 1, SMP_CACHE_BYTES);
86+
if (!name)
87+
panic("%s: Failed to allocate %zu bytes\n", __func__,
88+
strlen(tmp) + 1);
8689
strcpy(name, tmp);
8790

8891
return name;
@@ -118,6 +121,9 @@ alloc_io7(unsigned int pe)
118121
}
119122

120123
io7 = memblock_alloc(sizeof(*io7), SMP_CACHE_BYTES);
124+
if (!io7)
125+
panic("%s: Failed to allocate %zu bytes\n", __func__,
126+
sizeof(*io7));
121127
io7->pe = pe;
122128
raw_spin_lock_init(&io7->irq_lock);
123129

arch/alpha/kernel/pci-noop.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ alloc_pci_controller(void)
3434
struct pci_controller *hose;
3535

3636
hose = memblock_alloc(sizeof(*hose), SMP_CACHE_BYTES);
37+
if (!hose)
38+
panic("%s: Failed to allocate %zu bytes\n", __func__,
39+
sizeof(*hose));
3740

3841
*hose_tail = hose;
3942
hose_tail = &hose->next;
@@ -44,7 +47,13 @@ alloc_pci_controller(void)
4447
struct resource * __init
4548
alloc_resource(void)
4649
{
47-
return memblock_alloc(sizeof(struct resource), SMP_CACHE_BYTES);
50+
void *ptr = memblock_alloc(sizeof(struct resource), SMP_CACHE_BYTES);
51+
52+
if (!ptr)
53+
panic("%s: Failed to allocate %zu bytes\n", __func__,
54+
sizeof(struct resource));
55+
56+
return ptr;
4857
}
4958

5059
SYSCALL_DEFINE3(pciconfig_iobase, long, which, unsigned long, bus,
@@ -54,7 +63,7 @@ SYSCALL_DEFINE3(pciconfig_iobase, long, which, unsigned long, bus,
5463

5564
/* from hose or from bus.devfn */
5665
if (which & IOBASE_FROM_HOSE) {
57-
for (hose = hose_head; hose; hose = hose->next)
66+
for (hose = hose_head; hose; hose = hose->next)
5867
if (hose->index == bus)
5968
break;
6069
if (!hose)

arch/alpha/kernel/pci.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,9 @@ alloc_pci_controller(void)
393393
struct pci_controller *hose;
394394

395395
hose = memblock_alloc(sizeof(*hose), SMP_CACHE_BYTES);
396+
if (!hose)
397+
panic("%s: Failed to allocate %zu bytes\n", __func__,
398+
sizeof(*hose));
396399

397400
*hose_tail = hose;
398401
hose_tail = &hose->next;
@@ -403,7 +406,13 @@ alloc_pci_controller(void)
403406
struct resource * __init
404407
alloc_resource(void)
405408
{
406-
return memblock_alloc(sizeof(struct resource), SMP_CACHE_BYTES);
409+
void *ptr = memblock_alloc(sizeof(struct resource), SMP_CACHE_BYTES);
410+
411+
if (!ptr)
412+
panic("%s: Failed to allocate %zu bytes\n", __func__,
413+
sizeof(struct resource));
414+
415+
return ptr;
407416
}
408417

409418

arch/alpha/kernel/pci_iommu.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ iommu_arena_new_node(int nid, struct pci_controller *hose, dma_addr_t base,
8080
" falling back to system-wide allocation\n",
8181
__func__, nid);
8282
arena = memblock_alloc(sizeof(*arena), SMP_CACHE_BYTES);
83+
if (!arena)
84+
panic("%s: Failed to allocate %zu bytes\n", __func__,
85+
sizeof(*arena));
8386
}
8487

8588
arena->ptes = memblock_alloc_node(sizeof(*arena), align, nid);
@@ -88,12 +91,21 @@ iommu_arena_new_node(int nid, struct pci_controller *hose, dma_addr_t base,
8891
" falling back to system-wide allocation\n",
8992
__func__, nid);
9093
arena->ptes = memblock_alloc(mem_size, align);
94+
if (!arena->ptes)
95+
panic("%s: Failed to allocate %lu bytes align=0x%lx\n",
96+
__func__, mem_size, align);
9197
}
9298

9399
#else /* CONFIG_DISCONTIGMEM */
94100

95101
arena = memblock_alloc(sizeof(*arena), SMP_CACHE_BYTES);
102+
if (!arena)
103+
panic("%s: Failed to allocate %zu bytes\n", __func__,
104+
sizeof(*arena));
96105
arena->ptes = memblock_alloc(mem_size, align);
106+
if (!arena->ptes)
107+
panic("%s: Failed to allocate %lu bytes align=0x%lx\n",
108+
__func__, mem_size, align);
97109

98110
#endif /* CONFIG_DISCONTIGMEM */
99111

arch/arc/mm/highmem.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ static noinline pte_t * __init alloc_kmap_pgtable(unsigned long kvaddr)
124124
pmd_k = pmd_offset(pud_k, kvaddr);
125125

126126
pte_k = (pte_t *)memblock_alloc_low(PAGE_SIZE, PAGE_SIZE);
127+
if (!pte_k)
128+
panic("%s: Failed to allocate %lu bytes align=0x%lx\n",
129+
__func__, PAGE_SIZE, PAGE_SIZE);
130+
127131
pmd_populate_kernel(&init_mm, pmd_k, pte_k);
128132
return pte_k;
129133
}

arch/arm/kernel/setup.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -867,6 +867,9 @@ static void __init request_standard_resources(const struct machine_desc *mdesc)
867867
boot_alias_start = phys_to_idmap(start);
868868
if (arm_has_idmap_alias() && boot_alias_start != IDMAP_INVALID_ADDR) {
869869
res = memblock_alloc(sizeof(*res), SMP_CACHE_BYTES);
870+
if (!res)
871+
panic("%s: Failed to allocate %zu bytes\n",
872+
__func__, sizeof(*res));
870873
res->name = "System RAM (boot alias)";
871874
res->start = boot_alias_start;
872875
res->end = phys_to_idmap(end);
@@ -875,6 +878,9 @@ static void __init request_standard_resources(const struct machine_desc *mdesc)
875878
}
876879

877880
res = memblock_alloc(sizeof(*res), SMP_CACHE_BYTES);
881+
if (!res)
882+
panic("%s: Failed to allocate %zu bytes\n", __func__,
883+
sizeof(*res));
878884
res->name = "System RAM";
879885
res->start = start;
880886
res->end = end;

arch/arm/mm/mmu.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,13 @@ EXPORT_SYMBOL(phys_mem_access_prot);
721721

722722
static void __init *early_alloc(unsigned long sz)
723723
{
724-
return memblock_alloc(sz, sz);
724+
void *ptr = memblock_alloc(sz, sz);
725+
726+
if (!ptr)
727+
panic("%s: Failed to allocate %lu bytes align=0x%lx\n",
728+
__func__, sz, sz);
729+
730+
return ptr;
725731
}
726732

727733
static void *__init late_alloc(unsigned long sz)
@@ -994,6 +1000,9 @@ void __init iotable_init(struct map_desc *io_desc, int nr)
9941000
return;
9951001

9961002
svm = memblock_alloc(sizeof(*svm) * nr, __alignof__(*svm));
1003+
if (!svm)
1004+
panic("%s: Failed to allocate %zu bytes align=0x%zx\n",
1005+
__func__, sizeof(*svm) * nr, __alignof__(*svm));
9971006

9981007
for (md = io_desc; nr; md++, nr--) {
9991008
create_mapping(md);
@@ -1016,6 +1025,9 @@ void __init vm_reserve_area_early(unsigned long addr, unsigned long size,
10161025
struct static_vm *svm;
10171026

10181027
svm = memblock_alloc(sizeof(*svm), __alignof__(*svm));
1028+
if (!svm)
1029+
panic("%s: Failed to allocate %zu bytes align=0x%zx\n",
1030+
__func__, sizeof(*svm), __alignof__(*svm));
10191031

10201032
vm = &svm->vm;
10211033
vm->addr = (void *)addr;

arch/arm64/kernel/setup.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,16 +208,18 @@ static void __init request_standard_resources(void)
208208
struct memblock_region *region;
209209
struct resource *res;
210210
unsigned long i = 0;
211+
size_t res_size;
211212

212213
kernel_code.start = __pa_symbol(_text);
213214
kernel_code.end = __pa_symbol(__init_begin - 1);
214215
kernel_data.start = __pa_symbol(_sdata);
215216
kernel_data.end = __pa_symbol(_end - 1);
216217

217218
num_standard_resources = memblock.memory.cnt;
218-
standard_resources = memblock_alloc_low(num_standard_resources *
219-
sizeof(*standard_resources),
220-
SMP_CACHE_BYTES);
219+
res_size = num_standard_resources * sizeof(*standard_resources);
220+
standard_resources = memblock_alloc_low(res_size, SMP_CACHE_BYTES);
221+
if (!standard_resources)
222+
panic("%s: Failed to allocate %zu bytes\n", __func__, res_size);
221223

222224
for_each_memblock(memory, region) {
223225
res = &standard_resources[i++];

arch/arm64/mm/kasan_init.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ static phys_addr_t __init kasan_alloc_zeroed_page(int node)
4040
void *p = memblock_alloc_try_nid(PAGE_SIZE, PAGE_SIZE,
4141
__pa(MAX_DMA_ADDRESS),
4242
MEMBLOCK_ALLOC_KASAN, node);
43+
if (!p)
44+
panic("%s: Failed to allocate %lu bytes align=0x%lx nid=%d from=%llx\n",
45+
__func__, PAGE_SIZE, PAGE_SIZE, node,
46+
__pa(MAX_DMA_ADDRESS));
47+
4348
return __pa(p);
4449
}
4550

@@ -48,6 +53,11 @@ static phys_addr_t __init kasan_alloc_raw_page(int node)
4853
void *p = memblock_alloc_try_nid_raw(PAGE_SIZE, PAGE_SIZE,
4954
__pa(MAX_DMA_ADDRESS),
5055
MEMBLOCK_ALLOC_KASAN, node);
56+
if (!p)
57+
panic("%s: Failed to allocate %lu bytes align=0x%lx nid=%d from=%llx\n",
58+
__func__, PAGE_SIZE, PAGE_SIZE, node,
59+
__pa(MAX_DMA_ADDRESS));
60+
5161
return __pa(p);
5262
}
5363

arch/c6x/mm/dma-coherent.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ void __init coherent_mem_init(phys_addr_t start, u32 size)
138138

139139
dma_bitmap = memblock_alloc(BITS_TO_LONGS(dma_pages) * sizeof(long),
140140
sizeof(long));
141+
if (!dma_bitmap)
142+
panic("%s: Failed to allocate %zu bytes align=0x%zx\n",
143+
__func__, BITS_TO_LONGS(dma_pages) * sizeof(long),
144+
sizeof(long));
141145
}
142146

143147
static void c6x_dma_sync(struct device *dev, phys_addr_t paddr, size_t size,

arch/c6x/mm/init.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ void __init paging_init(void)
4040

4141
empty_zero_page = (unsigned long) memblock_alloc(PAGE_SIZE,
4242
PAGE_SIZE);
43+
if (!empty_zero_page)
44+
panic("%s: Failed to allocate %lu bytes align=0x%lx\n",
45+
__func__, PAGE_SIZE, PAGE_SIZE);
4346

4447
/*
4548
* Set up user data space

arch/csky/mm/highmem.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@ static void __init fixrange_init(unsigned long start, unsigned long end,
141141
for (; (k < PTRS_PER_PMD) && (vaddr != end); pmd++, k++) {
142142
if (pmd_none(*pmd)) {
143143
pte = (pte_t *) memblock_alloc_low(PAGE_SIZE, PAGE_SIZE);
144+
if (!pte)
145+
panic("%s: Failed to allocate %lu bytes align=%lx\n",
146+
__func__, PAGE_SIZE,
147+
PAGE_SIZE);
148+
144149
set_pmd(pmd, __pmd(__pa(pte)));
145150
BUG_ON(pte != pte_offset_kernel(pmd, 0));
146151
}

arch/h8300/mm/init.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ void __init paging_init(void)
6868
* to a couple of allocated pages.
6969
*/
7070
empty_zero_page = (unsigned long)memblock_alloc(PAGE_SIZE, PAGE_SIZE);
71+
if (!empty_zero_page)
72+
panic("%s: Failed to allocate %lu bytes align=0x%lx\n",
73+
__func__, PAGE_SIZE, PAGE_SIZE);
7174

7275
/*
7376
* Set up SFC/DFC registers (user data space).

arch/m68k/atari/stram.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ void __init atari_stram_reserve_pages(void *start_mem)
9797
pr_debug("atari_stram pool: kernel in ST-RAM, using alloc_bootmem!\n");
9898
stram_pool.start = (resource_size_t)memblock_alloc_low(pool_size,
9999
PAGE_SIZE);
100+
if (!stram_pool.start)
101+
panic("%s: Failed to allocate %lu bytes align=%lx\n",
102+
__func__, pool_size, PAGE_SIZE);
103+
100104
stram_pool.end = stram_pool.start + pool_size - 1;
101105
request_resource(&iomem_resource, &stram_pool);
102106
stram_virt_offset = 0;

arch/m68k/mm/init.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ void __init paging_init(void)
9494
high_memory = (void *) end_mem;
9595

9696
empty_zero_page = memblock_alloc(PAGE_SIZE, PAGE_SIZE);
97+
if (!empty_zero_page)
98+
panic("%s: Failed to allocate %lu bytes align=0x%lx\n",
99+
__func__, PAGE_SIZE, PAGE_SIZE);
97100

98101
/*
99102
* Set up SFC/DFC registers (user data space).

arch/m68k/mm/mcfmmu.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,19 @@ void __init paging_init(void)
4444
int i;
4545

4646
empty_zero_page = (void *) memblock_alloc(PAGE_SIZE, PAGE_SIZE);
47+
if (!empty_zero_page)
48+
panic("%s: Failed to allocate %lu bytes align=0x%lx\n",
49+
__func__, PAGE_SIZE, PAGE_SIZE);
4750

4851
pg_dir = swapper_pg_dir;
4952
memset(swapper_pg_dir, 0, sizeof(swapper_pg_dir));
5053

5154
size = num_pages * sizeof(pte_t);
5255
size = (size + PAGE_SIZE) & ~(PAGE_SIZE-1);
5356
next_pgtable = (unsigned long) memblock_alloc(size, PAGE_SIZE);
57+
if (!next_pgtable)
58+
panic("%s: Failed to allocate %lu bytes align=0x%lx\n",
59+
__func__, size, PAGE_SIZE);
5460

5561
bootmem_end = (next_pgtable + size + PAGE_SIZE) & PAGE_MASK;
5662
pg_dir += PAGE_OFFSET >> PGDIR_SHIFT;

arch/m68k/mm/motorola.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ static pte_t * __init kernel_page_table(void)
5555
pte_t *ptablep;
5656

5757
ptablep = (pte_t *)memblock_alloc_low(PAGE_SIZE, PAGE_SIZE);
58+
if (!ptablep)
59+
panic("%s: Failed to allocate %lu bytes align=%lx\n",
60+
__func__, PAGE_SIZE, PAGE_SIZE);
5861

5962
clear_page(ptablep);
6063
__flush_page_to_ram(ptablep);
@@ -96,6 +99,9 @@ static pmd_t * __init kernel_ptr_table(void)
9699
if (((unsigned long)last_pgtable & ~PAGE_MASK) == 0) {
97100
last_pgtable = (pmd_t *)memblock_alloc_low(PAGE_SIZE,
98101
PAGE_SIZE);
102+
if (!last_pgtable)
103+
panic("%s: Failed to allocate %lu bytes align=%lx\n",
104+
__func__, PAGE_SIZE, PAGE_SIZE);
99105

100106
clear_page(last_pgtable);
101107
__flush_page_to_ram(last_pgtable);
@@ -278,6 +284,9 @@ void __init paging_init(void)
278284
* to a couple of allocated pages
279285
*/
280286
empty_zero_page = memblock_alloc(PAGE_SIZE, PAGE_SIZE);
287+
if (!empty_zero_page)
288+
panic("%s: Failed to allocate %lu bytes align=0x%lx\n",
289+
__func__, PAGE_SIZE, PAGE_SIZE);
281290

282291
/*
283292
* Set up SFC/DFC registers

arch/m68k/mm/sun3mmu.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ void __init paging_init(void)
4646
unsigned long size;
4747

4848
empty_zero_page = memblock_alloc(PAGE_SIZE, PAGE_SIZE);
49+
if (!empty_zero_page)
50+
panic("%s: Failed to allocate %lu bytes align=0x%lx\n",
51+
__func__, PAGE_SIZE, PAGE_SIZE);
4952

5053
address = PAGE_OFFSET;
5154
pg_dir = swapper_pg_dir;
@@ -56,6 +59,9 @@ void __init paging_init(void)
5659
size = (size + PAGE_SIZE) & ~(PAGE_SIZE-1);
5760

5861
next_pgtable = (unsigned long)memblock_alloc(size, PAGE_SIZE);
62+
if (!next_pgtable)
63+
panic("%s: Failed to allocate %lu bytes align=0x%lx\n",
64+
__func__, size, PAGE_SIZE);
5965
bootmem_end = (next_pgtable + size + PAGE_SIZE) & PAGE_MASK;
6066

6167
/* Map whole memory from PAGE_OFFSET (0x0E000000) */

arch/m68k/sun3/sun3dvma.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,9 @@ void __init dvma_init(void)
269269

270270
iommu_use = memblock_alloc(IOMMU_TOTAL_ENTRIES * sizeof(unsigned long),
271271
SMP_CACHE_BYTES);
272+
if (!iommu_use)
273+
panic("%s: Failed to allocate %zu bytes\n", __func__,
274+
IOMMU_TOTAL_ENTRIES * sizeof(unsigned long));
272275

273276
dvma_unmap_iommu(DVMA_START, DVMA_SIZE);
274277

arch/microblaze/mm/init.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,10 +374,14 @@ void * __ref zalloc_maybe_bootmem(size_t size, gfp_t mask)
374374
{
375375
void *p;
376376

377-
if (mem_init_done)
377+
if (mem_init_done) {
378378
p = kzalloc(size, mask);
379-
else
379+
} else {
380380
p = memblock_alloc(size, SMP_CACHE_BYTES);
381+
if (!p)
382+
panic("%s: Failed to allocate %zu bytes\n",
383+
__func__, size);
384+
}
381385

382386
return p;
383387
}

0 commit comments

Comments
 (0)