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

Commit d7a5b2ff authored by Michael Ellerman's avatar Michael Ellerman Committed by Paul Mackerras
Browse files

[PATCH] powerpc: Always panic if lmb_alloc() fails



Currently most callers of lmb_alloc() don't check if it worked or not, if it
ever does weird bad things will probably happen. The few callers who do check
just panic or BUG_ON.

So make lmb_alloc() panic internally, to catch bugs at the source. The few
callers who did check the result no longer need to.

The only caller that did anything interesting with the return result was
careful_allocation(). For it we create __lmb_alloc_base() which _doesn't_ panic
automatically, a little messy, but passable.

Signed-off-by: default avatarMichael Ellerman <michael@ellerman.id.au>
Signed-off-by: default avatarPaul Mackerras <paulus@samba.org>
parent 2fb07d77
Loading
Loading
Loading
Loading
+0 −4
Original line number Diff line number Diff line
@@ -831,10 +831,6 @@ void __init unflatten_device_tree(void)

	/* Allocate memory for the expanded device tree */
	mem = lmb_alloc(size + 4, __alignof__(struct device_node));
	if (!mem) {
		DBG("Couldn't allocate memory with lmb_alloc()!\n");
		panic("Couldn't allocate memory with lmb_alloc()!\n");
	}
	mem = (unsigned long) __va(mem);

	((u32 *)mem)[size / 4] = 0xdeadbeef;
+0 −1
Original line number Diff line number Diff line
@@ -430,7 +430,6 @@ void __init htab_initialize(void)
		 * the absolute address space.
		 */
		table = lmb_alloc(htab_size_bytes, htab_size_bytes);
		BUG_ON(table == 0);

		DBG("Hash table allocated at %lx, size: %lx\n", table,
		    htab_size_bytes);
+14 −0
Original line number Diff line number Diff line
@@ -225,6 +225,20 @@ unsigned long __init lmb_alloc(unsigned long size, unsigned long align)

unsigned long __init lmb_alloc_base(unsigned long size, unsigned long align,
				    unsigned long max_addr)
{
	unsigned long alloc;

	alloc = __lmb_alloc_base(size, align, max_addr);

	if (alloc < 0)
		panic("ERROR: Failed to allocate 0x%lx bytes below 0x%lx.\n",
				size, max_addr);

	return alloc;
}

unsigned long __init __lmb_alloc_base(unsigned long size, unsigned long align,
				    unsigned long max_addr)
{
	long i, j;
	unsigned long base = 0;
+0 −1
Original line number Diff line number Diff line
@@ -249,7 +249,6 @@ void __init do_init_bootmem(void)
	bootmap_pages = bootmem_bootmap_pages(total_pages);

	start = lmb_alloc(bootmap_pages << PAGE_SHIFT, PAGE_SIZE);
	BUG_ON(!start);

	boot_mapsize = init_bootmem(start >> PAGE_SHIFT, total_pages);

+2 −2
Original line number Diff line number Diff line
@@ -570,11 +570,11 @@ static void __init *careful_allocation(int nid, unsigned long size,
				       unsigned long end_pfn)
{
	int new_nid;
	unsigned long ret = lmb_alloc_base(size, align, end_pfn << PAGE_SHIFT);
	unsigned long ret = __lmb_alloc_base(size, align, end_pfn << PAGE_SHIFT);

	/* retry over all memory */
	if (!ret)
		ret = lmb_alloc_base(size, align, lmb_end_of_DRAM());
		ret = __lmb_alloc_base(size, align, lmb_end_of_DRAM());

	if (!ret)
		panic("numa.c: cannot allocate %lu bytes on node %d",
Loading