From patchwork Fri Apr 19 07:58:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pingfan Liu X-Patchwork-Id: 10908679 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9F4EF17EE for ; Fri, 19 Apr 2019 08:00:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 90FF028531 for ; Fri, 19 Apr 2019 08:00:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 840C628A3E; Fri, 19 Apr 2019 08:00:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8B16228531 for ; Fri, 19 Apr 2019 08:00:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=oQycUIdVlrZBmmWQA6a+oPDVxtN5TeM1eN3F7ClElFA=; b=V+r 5Pmeu8/EaZyTgrVfAQXuzeXvh4gWt22xo/2mbG/RvXAaIoOXVRDLyf8lD3KzsT/CxcdVm7taf0M/t EGO+vgH09/CRaBgtZjRciyUaSdA9x6lZAopM9tv9yJFFPKZgLbGy5Cl3BykehQwWEIJtaJWULGb12 aMjeII9m/sEYw3a3B4xqLonauVvDrbzaIUE6Kf/+7IUt4o7dvInFsSFdPvlYKNV49k1DgEpOdfn4n nmnAMQe2Xrp1sSdasNaWo0C1dfCuSPwee4ujxGFgiZFV0mz+Xosu/clwmbbS5UsS4xergQ7oJdtcF u1gYBm35ViIpUpFnB85c3KNC2FX13KA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hHORE-0002cK-F2; Fri, 19 Apr 2019 08:00:00 +0000 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hHORA-0002bo-Uk for linux-arm-kernel@lists.infradead.org; Fri, 19 Apr 2019 07:59:58 +0000 Received: by mail-pf1-x444.google.com with SMTP id 10so2265694pfo.5 for ; Fri, 19 Apr 2019 00:59:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=CXshfHJtKJBB6RqEy0dCa+LvOEJLdnOQQ3VtYxqDG/Q=; b=m+1qD9inpy98UNWdyPrH41Vv6SnLyKdbHpGjQgNBywjaLXYrYFWY8JWoha9TI702ey 9KjrGLavWbVU+nW5V4lfoP/5GloKcxZbQCwWKvJdYQhAUZMyzt2pDleT8WKN2W9N+SJj E3ZkBJr3oFTYkHSXhYFFTvnPOz+Wvy5Gf8C9CxRiGEZMH4JzfjXuGMuNedYBzk0hanop /6XgNVoaAKuy3QOpKOljbI6/wFH5CH8zRjZeHdG2GzIk4m35hNafeoDowTFh6PXvHnEl UpPJ8kGZGazdqef+w5z4Oq7Lw/6V88tF0pf+o1tJYhXf7ZJnJu2UINO8JId9gLLtCSQv P8oA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=CXshfHJtKJBB6RqEy0dCa+LvOEJLdnOQQ3VtYxqDG/Q=; b=MN3wZDinV6mzXUyTxNWAHF2SnC3eVspYg4Yg80uFJCrOCNi7gXL1mDbhITgfCJurVr NtaHaW1SWBtt9VbJ1CctXXbFuzzMuNaCmBsYggOpTlbkmvopaxnM+uP0nlLPERZvJopV 1MJJLuN3dndYYmy1f+2rtoxR1G5jfF0rFmW/yvKjweVVfOgRV2sm0Z3GfWagYyalNnLJ FdjT8TTPpx6CIthg/X32fh2IB4qDkBHoxJBq/hyRswjUV8N0PUXmbFJLolJYDmKhv2X2 jALxfZ49rHngxRxESegzyVwLZSqhuRsU4W5IIHFM5anUSlPXphbZFo24/pJtyY1G16NI bzxg== X-Gm-Message-State: APjAAAVqIcpn65tl4NNyxDDynkRKkQs78Fa1lUv/1LSrGsx3nqlgx9Zv Soc4cERk3y+tFAS2BPTu3w== X-Google-Smtp-Source: APXvYqxFW63Fu4eIqRYM7gy4ONzAzxxoT/2sTzVYmEUMdFtfIrWJPhW/PY6EH1932JyZE7+yaVfzaw== X-Received: by 2002:aa7:8b08:: with SMTP id f8mr2551028pfd.146.1555660795554; Fri, 19 Apr 2019 00:59:55 -0700 (PDT) Received: from mylaptop.redhat.com ([2408:8207:782a:91d0:d21b:f3c4:1cf5:d5f7]) by smtp.gmail.com with ESMTPSA id u8sm2250574pgc.10.2019.04.19.00.59.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 Apr 2019 00:59:54 -0700 (PDT) From: Pingfan Liu To: linux-kernel@vger.kernel.org Subject: [PATCH] kernel/crash: make parse_crashkernel()'s return value more indicant Date: Fri, 19 Apr 2019 15:58:37 +0800 Message-Id: <1555660717-18731-1-git-send-email-kernelfans@gmail.com> X-Mailer: git-send-email 2.7.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190419_005956_990863_E941D37A X-CRM114-Status: GOOD ( 19.94 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Rich Felker , linux-ia64@vger.kernel.org, Julien Thierry , Yangtao Li , Benjamin Herrenschmidt , Palmer Dabbelt , Heiko Carstens , x86@kernel.org, Pingfan Liu , linux-mips@vger.kernel.org, Paul Mackerras , "H. Peter Anvin" , linux-s390@vger.kernel.org, Florian Fainelli , Yoshinori Sato , linux-sh@vger.kernel.org, Michael Ellerman , David Hildenbrand , Russell King , Ingo Molnar , linux-arm-kernel@lists.infradead.org, Catalin Marinas , James Hogan , Dave Young , Fenghua Yu , Will Deacon , linuxppc-dev@lists.ozlabs.org, Ananth N Mavinakayanahalli , Borislav Petkov , Stefan Agner , Thomas Gleixner , Hari Bathini , Jens Axboe , Tony Luck , Baoquan He , Ard Biesheuvel , Robin Murphy , Greg Kroah-Hartman , Ralf Baechle , Thomas Bogendoerfer , Paul Burton , Johannes Weiner , Martin Schwidefsky , Andrew Morton , Logan Gunthorpe , Greg Hackmann MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Cc: Russell King Cc: Catalin Marinas Cc: Will Deacon Cc: Tony Luck Cc: Fenghua Yu Cc: Ralf Baechle Cc: Paul Burton Cc: James Hogan Cc: Benjamin Herrenschmidt Cc: Paul Mackerras Cc: Michael Ellerman Cc: Martin Schwidefsky Cc: Heiko Carstens Cc: Yoshinori Sato Cc: Rich Felker Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: "H. Peter Anvin" Cc: Andrew Morton Cc: Julien Thierry Cc: Palmer Dabbelt Cc: Ard Biesheuvel Cc: Florian Fainelli Cc: Logan Gunthorpe Cc: Robin Murphy Cc: Greg Hackmann Cc: Stefan Agner Cc: Johannes Weiner Cc: David Hildenbrand Cc: Jens Axboe Cc: Thomas Bogendoerfer Cc: Greg Kroah-Hartman Cc: Hari Bathini Cc: Ananth N Mavinakayanahalli Cc: Yangtao Li Cc: Dave Young Cc: Baoquan He 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(-) diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c index 5d78b6a..2feab13 100644 --- a/arch/arm/kernel/setup.c +++ b/arch/arm/kernel/setup.c @@ -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) { diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c index 6bc1350..240918c 100644 --- a/arch/arm64/mm/init.c +++ b/arch/arm64/mm/init.c @@ -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); diff --git a/arch/ia64/kernel/setup.c b/arch/ia64/kernel/setup.c index 583a374..99cae33 100644 --- a/arch/ia64/kernel/setup.c +++ b/arch/ia64/kernel/setup.c @@ -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); diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c index 8d1dc6c..168571b 100644 --- a/arch/mips/kernel/setup.c +++ b/arch/mips/kernel/setup.c @@ -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)) { diff --git a/arch/powerpc/kernel/fadump.c b/arch/powerpc/kernel/fadump.c index 45a8d0b..0b626e2 100644 --- a/arch/powerpc/kernel/fadump.c +++ b/arch/powerpc/kernel/fadump.c @@ -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) diff --git a/arch/powerpc/kernel/machine_kexec.c b/arch/powerpc/kernel/machine_kexec.c index 63f5a93..9f3e61a 100644 --- a/arch/powerpc/kernel/machine_kexec.c +++ b/arch/powerpc/kernel/machine_kexec.c @@ -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; } diff --git a/arch/s390/kernel/setup.c b/arch/s390/kernel/setup.c index 2c642af..d4bd61b 100644 --- a/arch/s390/kernel/setup.c +++ b/arch/s390/kernel/setup.c @@ -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) { diff --git a/arch/sh/kernel/machine_kexec.c b/arch/sh/kernel/machine_kexec.c index 63d63a3..612b21e 100644 --- a/arch/sh/kernel/machine_kexec.c +++ b/arch/sh/kernel/machine_kexec.c @@ -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; } diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c index 3d872a5..62d07d4 100644 --- a/arch/x86/kernel/setup.c +++ b/arch/x86/kernel/setup.c @@ -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; } diff --git a/kernel/crash_core.c b/kernel/crash_core.c index 093c9f9..563d86d 100644 --- a/kernel/crash_core.c +++ b/kernel/crash_core.c @@ -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,