treewide: add checks for the return value of memblock_alloc*()
authorMike Rapoport <rppt@linux.ibm.com>
Tue, 12 Mar 2019 06:30:31 +0000 (23:30 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Tue, 12 Mar 2019 17:04:02 +0000 (10:04 -0700)
commit8a7f97b902f4fb0d94b355b6b3f1fbd7154cafb9
tree5d246cde363bba8494a6e6755ad0a26c2dad5cb8
parenta0bf842e89a3842162aa8514b9bf4611c86fee10
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>
74 files changed:
arch/alpha/kernel/core_cia.c
arch/alpha/kernel/core_marvel.c
arch/alpha/kernel/pci-noop.c
arch/alpha/kernel/pci.c
arch/alpha/kernel/pci_iommu.c
arch/arc/mm/highmem.c
arch/arm/kernel/setup.c
arch/arm/mm/mmu.c
arch/arm64/kernel/setup.c
arch/arm64/mm/kasan_init.c
arch/c6x/mm/dma-coherent.c
arch/c6x/mm/init.c
arch/csky/mm/highmem.c
arch/h8300/mm/init.c
arch/m68k/atari/stram.c
arch/m68k/mm/init.c
arch/m68k/mm/mcfmmu.c
arch/m68k/mm/motorola.c
arch/m68k/mm/sun3mmu.c
arch/m68k/sun3/sun3dvma.c
arch/microblaze/mm/init.c
arch/mips/cavium-octeon/dma-octeon.c
arch/mips/kernel/setup.c
arch/mips/kernel/traps.c
arch/mips/mm/init.c
arch/nds32/mm/init.c
arch/openrisc/mm/ioremap.c
arch/powerpc/kernel/dt_cpu_ftrs.c
arch/powerpc/kernel/pci_32.c
arch/powerpc/kernel/setup-common.c
arch/powerpc/kernel/setup_64.c
arch/powerpc/lib/alloc.c
arch/powerpc/mm/hash_utils_64.c
arch/powerpc/mm/mmu_context_nohash.c
arch/powerpc/mm/pgtable-book3e.c
arch/powerpc/mm/pgtable-book3s64.c
arch/powerpc/mm/pgtable-radix.c
arch/powerpc/mm/ppc_mmu_32.c
arch/powerpc/platforms/pasemi/iommu.c
arch/powerpc/platforms/powermac/nvram.c
arch/powerpc/platforms/powernv/opal.c
arch/powerpc/platforms/powernv/pci-ioda.c
arch/powerpc/platforms/ps3/setup.c
arch/powerpc/sysdev/msi_bitmap.c
arch/s390/kernel/setup.c
arch/s390/kernel/smp.c
arch/s390/kernel/topology.c
arch/s390/numa/mode_emu.c
arch/s390/numa/numa.c
arch/sh/mm/init.c
arch/sh/mm/numa.c
arch/um/drivers/net_kern.c
arch/um/drivers/vector_kern.c
arch/um/kernel/initrd.c
arch/um/kernel/mem.c
arch/unicore32/kernel/setup.c
arch/unicore32/mm/mmu.c
arch/x86/kernel/acpi/boot.c
arch/x86/kernel/apic/io_apic.c
arch/x86/kernel/e820.c
arch/x86/platform/olpc/olpc_dt.c
arch/x86/xen/p2m.c
arch/xtensa/mm/kasan_init.c
arch/xtensa/mm/mmu.c
drivers/clk/ti/clk.c
drivers/macintosh/smu.c
drivers/of/fdt.c
drivers/of/unittest.c
drivers/xen/swiotlb-xen.c
kernel/dma/swiotlb.c
kernel/power/snapshot.c
lib/cpumask.c
mm/kasan/init.c
mm/sparse.c