@@ -997,7 +997,7 @@ static void __init reserve_crashkernel(void)
total_mem = get_total_mem();
ret = parse_crashkernel(boot_command_line, total_mem,
&crash_size, &crash_base);
- if (ret)
+ if (ret < 0)
return;
if (crash_base <= 0) {
@@ -79,7 +79,7 @@ static void __init reserve_crashkernel(void)
ret = parse_crashkernel(boot_command_line, memblock_phys_mem_size(),
&crash_size, &crash_base);
/* no crashkernel= or invalid value specified */
- if (ret || !crash_size)
+ if (ret < 0)
return;
crash_size = PAGE_ALIGN(crash_size);
@@ -277,7 +277,7 @@ static void __init setup_crashkernel(unsigned long total, int *n)
ret = parse_crashkernel(boot_command_line, total,
&size, &base);
- if (ret == 0 && size > 0) {
+ if (ret >= 0) {
if (!base) {
sort_regions(rsvd_region, *n);
*n = merge_regions(rsvd_region, *n);
@@ -715,7 +715,7 @@ static void __init mips_parse_crashkernel(void)
total_mem = get_total_mem();
ret = parse_crashkernel(boot_command_line, total_mem,
&crash_size, &crash_base);
- if (ret != 0 || crash_size <= 0)
+ if (ret < 0)
return;
if (!memory_region_available(crash_base, crash_size)) {
@@ -376,7 +376,7 @@ static inline unsigned long fadump_calculate_reserve_size(void)
*/
ret = parse_crashkernel(boot_command_line, memblock_phys_mem_size(),
&size, &base);
- if (ret == 0 && size > 0) {
+ if (ret >= 0) {
unsigned long max_size;
if (fw_dump.reserve_bootvar)
@@ -122,7 +122,7 @@ void __init reserve_crashkernel(void)
/* use common parsing */
ret = parse_crashkernel(boot_command_line, memblock_phys_mem_size(),
&crash_size, &crash_base);
- if (ret == 0 && crash_size > 0) {
+ if (ret >= 0) {
crashk_res.start = crash_base;
crashk_res.end = crash_base + crash_size - 1;
}
@@ -671,7 +671,7 @@ static void __init reserve_crashkernel(void)
crash_base = ALIGN(crash_base, KEXEC_CRASH_MEM_ALIGN);
crash_size = ALIGN(crash_size, KEXEC_CRASH_MEM_ALIGN);
- if (rc || crash_size == 0)
+ if (rc < 0)
return;
if (memblock.memory.regions[0].size < crash_size) {
@@ -157,7 +157,7 @@ void __init reserve_crashkernel(void)
ret = parse_crashkernel(boot_command_line, memblock_phys_mem_size(),
&crash_size, &crash_base);
- if (ret == 0 && crash_size > 0) {
+ if (ret >= 0) {
crashk_res.start = crash_base;
crashk_res.end = crash_base + crash_size - 1;
}
@@ -526,11 +526,11 @@ static void __init reserve_crashkernel(void)
/* crashkernel=XM */
ret = parse_crashkernel(boot_command_line, total_mem, &crash_size, &crash_base);
- if (ret != 0 || crash_size <= 0) {
+ if (ret == -EINVAL) {
/* crashkernel=X,high */
ret = parse_crashkernel_high(boot_command_line, total_mem,
&crash_size, &crash_base);
- if (ret != 0 || crash_size <= 0)
+ if (ret < 0)
return;
high = true;
}
@@ -87,7 +87,7 @@ static int __init parse_crashkernel_mem(char *cmdline,
cur = tmp;
if (size >= system_ram) {
pr_warn("crashkernel: invalid size\n");
- return -EINVAL;
+ return -1;
}
/* match ? */
@@ -108,8 +108,10 @@ static int __init parse_crashkernel_mem(char *cmdline,
return -EINVAL;
}
}
- } else
+ } else {
pr_info("crashkernel size resulted in zero bytes\n");
+ return -1;
+ }
return 0;
}
@@ -139,6 +141,8 @@ static int __init parse_crashkernel_simple(char *cmdline,
pr_warn("crashkernel: unrecognized char: %c\n", *cur);
return -EINVAL;
}
+ if (*crash_size == 0)
+ return -1;
return 0;
}
@@ -181,6 +185,8 @@ static int __init parse_crashkernel_suffix(char *cmdline,
pr_warn("crashkernel: unrecognized char: %c\n", *cur);
return -EINVAL;
}
+ if (*crash_size == 0)
+ return -1;
return 0;
}
@@ -266,6 +272,8 @@ static int __init __parse_crashkernel(char *cmdline,
/*
* That function is the entry point for command line parsing and should be
* called from the arch-specific code.
+ * On success 0 or 1 if @offset is given. On error -EINVAL if bad syntax,
+ * or -1 if the parsing results in crash_size=0.
*/
int __init parse_crashkernel(char *cmdline,
unsigned long long system_ram,
At present, both return and crash_size should be checked to guarantee the success of parse_crashkernel(). Simplify the way by returning negative if fail, positive if success. In case of failure, -EINVAL for bad syntax, -1 for the parsing results in crash_size=0. Signed-off-by: Pingfan Liu <kernelfans@gmail.com> Cc: Russell King <linux@armlinux.org.uk> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: Will Deacon <will.deacon@arm.com> Cc: Tony Luck <tony.luck@intel.com> Cc: Fenghua Yu <fenghua.yu@intel.com> Cc: Ralf Baechle <ralf@linux-mips.org> Cc: Paul Burton <paul.burton@mips.com> Cc: James Hogan <jhogan@kernel.org> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org> Cc: Paul Mackerras <paulus@samba.org> Cc: Michael Ellerman <mpe@ellerman.id.au> Cc: Martin Schwidefsky <schwidefsky@de.ibm.com> Cc: Heiko Carstens <heiko.carstens@de.ibm.com> Cc: Yoshinori Sato <ysato@users.sourceforge.jp> Cc: Rich Felker <dalias@libc.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Ingo Molnar <mingo@redhat.com> Cc: Borislav Petkov <bp@alien8.de> Cc: "H. Peter Anvin" <hpa@zytor.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Julien Thierry <julien.thierry@arm.com> Cc: Palmer Dabbelt <palmer@sifive.com> Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org> Cc: Florian Fainelli <f.fainelli@gmail.com> Cc: Logan Gunthorpe <logang@deltatee.com> Cc: Robin Murphy <robin.murphy@arm.com> Cc: Greg Hackmann <ghackmann@android.com> Cc: Stefan Agner <stefan@agner.ch> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: David Hildenbrand <david@redhat.com> Cc: Jens Axboe <axboe@kernel.dk> Cc: Thomas Bogendoerfer <tbogendoerfer@suse.de> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: Hari Bathini <hbathini@linux.ibm.com> Cc: Ananth N Mavinakayanahalli <ananth@linux.vnet.ibm.com> Cc: Yangtao Li <tiny.windzz@gmail.com> Cc: Dave Young <dyoung@redhat.com> Cc: Baoquan He <bhe@redhat.com> Cc: x86@kernel.org Cc: linux-arm-kernel@lists.infradead.org Cc: linux-ia64@vger.kernel.org Cc: linux-mips@vger.kernel.org Cc: linuxppc-dev@lists.ozlabs.org Cc: linux-s390@vger.kernel.org Cc: linux-sh@vger.kernel.org --- arch/arm/kernel/setup.c | 2 +- arch/arm64/mm/init.c | 2 +- arch/ia64/kernel/setup.c | 2 +- arch/mips/kernel/setup.c | 2 +- arch/powerpc/kernel/fadump.c | 2 +- arch/powerpc/kernel/machine_kexec.c | 2 +- arch/s390/kernel/setup.c | 2 +- arch/sh/kernel/machine_kexec.c | 2 +- arch/x86/kernel/setup.c | 4 ++-- kernel/crash_core.c | 12 ++++++++++-- 10 files changed, 20 insertions(+), 12 deletions(-)