Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

init/main: add checks for the return value of memblock_alloc*()

Add panic() calls if memblock_alloc() returns NULL.

The panic() format duplicates the one used by memblock itself and in
order to avoid explosion with long parameters list replace open coded
allocation size calculations with a local variable.

Link: http://lkml.kernel.org/r/1548057848-15136-18-git-send-email-rppt@linux.ibm.com
Signed-off-by: Mike Rapoport <rppt@linux.ibm.com>
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: 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: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Mike Rapoport and committed by
Linus Torvalds
f5c7310a f655f405

+20 -6
+20 -6
init/main.c
··· 373 373 */ 374 374 static void __init setup_command_line(char *command_line) 375 375 { 376 - saved_command_line = 377 - memblock_alloc(strlen(boot_command_line) + 1, SMP_CACHE_BYTES); 378 - initcall_command_line = 379 - memblock_alloc(strlen(boot_command_line) + 1, SMP_CACHE_BYTES); 380 - static_command_line = memblock_alloc(strlen(command_line) + 1, 381 - SMP_CACHE_BYTES); 376 + size_t len = strlen(boot_command_line) + 1; 377 + 378 + saved_command_line = memblock_alloc(len, SMP_CACHE_BYTES); 379 + if (!saved_command_line) 380 + panic("%s: Failed to allocate %zu bytes\n", __func__, len); 381 + 382 + initcall_command_line = memblock_alloc(len, SMP_CACHE_BYTES); 383 + if (!initcall_command_line) 384 + panic("%s: Failed to allocate %zu bytes\n", __func__, len); 385 + 386 + static_command_line = memblock_alloc(len, SMP_CACHE_BYTES); 387 + if (!static_command_line) 388 + panic("%s: Failed to allocate %zu bytes\n", __func__, len); 389 + 382 390 strcpy(saved_command_line, boot_command_line); 383 391 strcpy(static_command_line, command_line); 384 392 } ··· 778 770 pr_debug("blacklisting initcall %s\n", str_entry); 779 771 entry = memblock_alloc(sizeof(*entry), 780 772 SMP_CACHE_BYTES); 773 + if (!entry) 774 + panic("%s: Failed to allocate %zu bytes\n", 775 + __func__, sizeof(*entry)); 781 776 entry->buf = memblock_alloc(strlen(str_entry) + 1, 782 777 SMP_CACHE_BYTES); 778 + if (!entry->buf) 779 + panic("%s: Failed to allocate %zu bytes\n", 780 + __func__, strlen(str_entry) + 1); 783 781 strcpy(entry->buf, str_entry); 784 782 list_add(&entry->next, &blacklisted_initcalls); 785 783 }