Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b1e1c869 authored by Mike Rapoport's avatar Mike Rapoport Committed by Linus Torvalds
Browse files

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: default avatarMike Rapoport <rppt@linux.ibm.com>
Acked-by: default avatarDavid 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: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent d80db5c1
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -33,6 +33,8 @@ void * __init prom_early_alloc(unsigned long size)
	void *ret;

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

	prom_early_allocated += size;

+6 −0
Original line number Diff line number Diff line
@@ -624,8 +624,14 @@ void __init alloc_irqstack_bootmem(void)

		softirq_stack[i] = memblock_alloc_node(THREAD_SIZE,
						       THREAD_SIZE, node);
		if (!softirq_stack[i])
			panic("%s: Failed to allocate %lu bytes align=%lx nid=%d\n",
			      __func__, THREAD_SIZE, THREAD_SIZE, node);
		hardirq_stack[i] = memblock_alloc_node(THREAD_SIZE,
						       THREAD_SIZE, node);
		if (!hardirq_stack[i])
			panic("%s: Failed to allocate %lu bytes align=%lx nid=%d\n",
			      __func__, THREAD_SIZE, THREAD_SIZE, node);
	}
}

+12 −0
Original line number Diff line number Diff line
@@ -1628,6 +1628,8 @@ static void __init pcpu_populate_pte(unsigned long addr)
		pud_t *new;

		new = memblock_alloc_from(PAGE_SIZE, PAGE_SIZE, PAGE_SIZE);
		if (!new)
			goto err_alloc;
		pgd_populate(&init_mm, pgd, new);
	}

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

		new = memblock_alloc_from(PAGE_SIZE, PAGE_SIZE, PAGE_SIZE);
		if (!new)
			goto err_alloc;
		pud_populate(&init_mm, pud, new);
	}

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

		new = memblock_alloc_from(PAGE_SIZE, PAGE_SIZE, PAGE_SIZE);
		if (!new)
			goto err_alloc;
		pmd_populate_kernel(&init_mm, pmd, new);
	}

	return;

err_alloc:
	panic("%s: Failed to allocate %lu bytes align=%lx from=%lx\n",
	      __func__, PAGE_SIZE, PAGE_SIZE, PAGE_SIZE);
}

void __init setup_per_cpu_areas(void)
+11 −0
Original line number Diff line number Diff line
@@ -1809,6 +1809,8 @@ static unsigned long __ref kernel_map_range(unsigned long pstart,

			new = memblock_alloc_from(PAGE_SIZE, PAGE_SIZE,
						  PAGE_SIZE);
			if (!new)
				goto err_alloc;
			alloc_bytes += PAGE_SIZE;
			pgd_populate(&init_mm, pgd, new);
		}
@@ -1822,6 +1824,8 @@ static unsigned long __ref kernel_map_range(unsigned long pstart,
			}
			new = memblock_alloc_from(PAGE_SIZE, PAGE_SIZE,
						  PAGE_SIZE);
			if (!new)
				goto err_alloc;
			alloc_bytes += PAGE_SIZE;
			pud_populate(&init_mm, pud, new);
		}
@@ -1836,6 +1840,8 @@ static unsigned long __ref kernel_map_range(unsigned long pstart,
			}
			new = memblock_alloc_from(PAGE_SIZE, PAGE_SIZE,
						  PAGE_SIZE);
			if (!new)
				goto err_alloc;
			alloc_bytes += PAGE_SIZE;
			pmd_populate_kernel(&init_mm, pmd, new);
		}
@@ -1855,6 +1861,11 @@ static unsigned long __ref kernel_map_range(unsigned long pstart,
	}

	return alloc_bytes;

err_alloc:
	panic("%s: Failed to allocate %lu bytes align=%lx from=%lx\n",
	      __func__, PAGE_SIZE, PAGE_SIZE, PAGE_SIZE);
	return -ENOMEM;
}

static void __init flush_all_kernel_tsbs(void)
+8 −0
Original line number Diff line number Diff line
@@ -305,11 +305,17 @@ static void __init srmmu_nocache_init(void)

	srmmu_nocache_pool = memblock_alloc(srmmu_nocache_size,
					    SRMMU_NOCACHE_ALIGN_MAX);
	if (!srmmu_nocache_pool)
		panic("%s: Failed to allocate %lu bytes align=0x%x\n",
		      __func__, srmmu_nocache_size, SRMMU_NOCACHE_ALIGN_MAX);
	memset(srmmu_nocache_pool, 0, srmmu_nocache_size);

	srmmu_nocache_bitmap =
		memblock_alloc(BITS_TO_LONGS(bitmap_bits) * sizeof(long),
			       SMP_CACHE_BYTES);
	if (!srmmu_nocache_bitmap)
		panic("%s: Failed to allocate %zu bytes\n", __func__,
		      BITS_TO_LONGS(bitmap_bits) * sizeof(long));
	bit_map_init(&srmmu_nocache_map, srmmu_nocache_bitmap, bitmap_bits);

	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)

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

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