From mboxrd@z Thu Jan 1 00:00:00 1970 From: Pingfan Liu Date: Thu, 02 May 2019 06:22:06 +0000 Subject: Re: [PATCHv2] kernel/crash: make parse_crashkernel()'s return value more indicant Message-Id: List-Id: References: <1556087581-14513-1-git-send-email-kernelfans@gmail.com> <10dc5468-6cd9-85c7-ba66-1dfa5aa922b7@suse.com> In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: Matthias Brugger Cc: Rich Felker , linux-ia64@vger.kernel.org, Julien Thierry , Yangtao Li , Benjamin Herrenschmidt , Palmer Dabbelt , Heiko Carstens , Stefan Agner , linux-mips@vger.kernel.org, Paul Mackerras , "H. Peter Anvin" , Thomas Gleixner , Logan Gunthorpe , linux-s390@vger.kernel.org, Florian Fainelli , Yoshinori Sato , linux-sh@vger.kernel.org, Michael Ellerman , x86@kernel.org, Russell King , Ingo Molnar , Hari Bathini , Catalin Marinas , James Hogan , Dave Young , Fenghua Yu , Will Deacon , Johannes Weiner , Ananth N Mavinakayanahalli , Borislav Petkov , David Hildenbrand , linux-arm-kernel@lists.infradead.org, Jens Axboe , Tony Luck , Baoquan He , Ard Biesheuvel , Robin Murphy , LKML , Ralf Baechle , Thomas Bogendoerfer , Paul Burton , Greg Kroah-Hartman , Martin Schwidefsky , Andrew Morton , linuxppc-dev@lists.ozlabs.org, Greg Hackmann On Thu, Apr 25, 2019 at 4:20 PM Pingfan Liu wrote: > > On Wed, Apr 24, 2019 at 4:31 PM Matthias Brugger wrote: > > > > > [...] > > > @@ -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 -EINVAL; > > > > This covers the case where I pass an argument like "crashkernel=0M" ? > > Can't we fix that by using kstrtoull() in memparse and check if the return value > > is < 0? In that case we could return without updating the retptr and we will be > > fine. After a series of work, I suddenly realized that it can not be done like this way. "0M" causes kstrtoull() to return -EINVAL, but this is caused by "M", not "0". If passing "0" to kstrtoull(), it will return 0 on success. > > > It seems that kstrtoull() treats 0M as invalid parameter, while > simple_strtoull() does not. > My careless going through the code. And I tested with a valid value "256M" using kstrtoull(), it also returned -EINVAL. So I think there is no way to distinguish 0 from a positive value inside this basic math function. Do I miss anything? Thanks and regards, Pingfan From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CA018C04AA8 for ; Thu, 2 May 2019 06:22:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 98E1D20873 for ; Thu, 2 May 2019 06:22:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="OUxx+AAH" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726357AbfEBGWT (ORCPT ); Thu, 2 May 2019 02:22:19 -0400 Received: from mail-it1-f196.google.com ([209.85.166.196]:55119 "EHLO mail-it1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725764AbfEBGWS (ORCPT ); Thu, 2 May 2019 02:22:18 -0400 Received: by mail-it1-f196.google.com with SMTP id a190so1381374ite.4; Wed, 01 May 2019 23:22:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=k56mmNJm2c37muwGSNyw5prel5SUd23hcD0vEkYllYY=; b=OUxx+AAHpV80+7jWx8f1+E7itJj9D1rgHeIv5/3VMm7TKAnaU1bHWCA0kR/Uu4B/N0 YiDM2kOhNwjBsVDh7yPbvcSscs4wrg/XbXz1H/w3lDdnJU4TQ9QwedxsTFe/Bbjt18D3 JRn/qzW0ooD8Rl7s9nAI0qgl8XU1Fhb9EsRc0VNWcSWwmT5yQ/Ep3gbO5ZmDWB/2TOjs 56aGZ16FpdQ10TxCUNbdRMfiLjvkeIGo1brUr0GBhS/X+j6ZJRXFbl8XXTiVI/tpSorx HgJ21xXoiQgpOYV/KzFy4OYZm4ZtO8AhUMxPfwPWagYl7mDnLgavitYf7mYuADYjNy/N 5KRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=k56mmNJm2c37muwGSNyw5prel5SUd23hcD0vEkYllYY=; b=MIyo4SDSGi/WvE33ca1hznAocUQEWoDqMwzG+5wsQ8x40U+aElZTVV6cC1Cay8TR+M KI654MWkZ+5cI6RqMrG+Fq+ijr0oCojrjuLS0dpAbm2IDNcKuG9jFI2I+ue5JVnChLwO tF/tdKd5JmbtCLlErt2pO87fridJB/nnsFlLngNnYFi+fn084SQYS+K8xx6ur+tiKdlM 3j3klGWMGeanQkoCtACPslOEvMj4G9tKlM9s/4LcW4uco0583l+ldyM/HjsKxet/i4+3 vnZeub/YcYzhfV/b7z9ZKnk6B2BWAGdpsF2bWqrrs9w2MbbNAwK9oKxCkxQDuimTJ87C 5cLw== X-Gm-Message-State: APjAAAVC7lf9nWQ7pU6RjkY1B7DsjoFlcku1nJgZzzMxboY5YwajECx/ hZAeysXcmv0Kj+IDOSlrwExVawlnhycTOLvuTg== X-Google-Smtp-Source: APXvYqx2USGvNZCoaLJnd+1UamBCWbf1OMfqf8foQXGwbUGpu68tSJhvorSVm2AnXEjYEs1kPbB4DdJnuY+hXU3VFhQ= X-Received: by 2002:a05:660c:38e:: with SMTP id x14mr1138760itj.146.1556778137619; Wed, 01 May 2019 23:22:17 -0700 (PDT) MIME-Version: 1.0 References: <1556087581-14513-1-git-send-email-kernelfans@gmail.com> <10dc5468-6cd9-85c7-ba66-1dfa5aa922b7@suse.com> In-Reply-To: From: Pingfan Liu Date: Thu, 2 May 2019 14:22:06 +0800 Message-ID: Subject: Re: [PATCHv2] kernel/crash: make parse_crashkernel()'s return value more indicant To: Matthias Brugger Cc: LKML , Rich Felker , linux-ia64@vger.kernel.org, Julien Thierry , Yangtao Li , Benjamin Herrenschmidt , Palmer Dabbelt , Heiko Carstens , x86@kernel.org, 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 Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Apr 25, 2019 at 4:20 PM Pingfan Liu wrote: > > On Wed, Apr 24, 2019 at 4:31 PM Matthias Brugger wrote: > > > > > [...] > > > @@ -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 -EINVAL; > > > > This covers the case where I pass an argument like "crashkernel=0M" ? > > Can't we fix that by using kstrtoull() in memparse and check if the return value > > is < 0? In that case we could return without updating the retptr and we will be > > fine. After a series of work, I suddenly realized that it can not be done like this way. "0M" causes kstrtoull() to return -EINVAL, but this is caused by "M", not "0". If passing "0" to kstrtoull(), it will return 0 on success. > > > It seems that kstrtoull() treats 0M as invalid parameter, while > simple_strtoull() does not. > My careless going through the code. And I tested with a valid value "256M" using kstrtoull(), it also returned -EINVAL. So I think there is no way to distinguish 0 from a positive value inside this basic math function. Do I miss anything? Thanks and regards, Pingfan From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: MIME-Version: 1.0 References: <1556087581-14513-1-git-send-email-kernelfans@gmail.com> <10dc5468-6cd9-85c7-ba66-1dfa5aa922b7@suse.com> In-Reply-To: From: Pingfan Liu Date: Thu, 2 May 2019 14:22:06 +0800 Message-ID: Subject: Re: [PATCHv2] kernel/crash: make parse_crashkernel()'s return value more indicant List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org List-Archive: To: Matthias Brugger Cc: Rich Felker , linux-ia64@vger.kernel.org, Julien Thierry , Yangtao Li , Benjamin Herrenschmidt , Palmer Dabbelt , Heiko Carstens , Stefan Agner , linux-mips@vger.kernel.org, Paul Mackerras , "H. Peter Anvin" , Thomas Gleixner , Logan Gunthorpe , linux-s390@vger.kernel.org, Florian Fainelli , Yoshinori Sato , linux-sh@vger.kernel.org, Michael Ellerman , x86@kernel.org, Russell King , Ingo Molnar , Hari Bathini , Catalin Marinas , James Hogan , Dave Young , Fenghua Yu , Will Deacon , Johannes Weiner , Ananth N Mavinakayanahalli , Borislav Petkov , David Hildenbrand , linux-arm-kernel@lists.infradead.org, Jens Axboe , Tony Luck , Baoquan He , Ard Biesheuvel , Robin Murphy , LKML , Ralf Baechle , Thomas Bogendoerfer , Paul Burton , Greg Kroah-Hartman , Martin Schwidefsky , Andrew Morton , linuxppc-dev@lists.ozlabs.org, Greg Hackmann List-ID: On Thu, Apr 25, 2019 at 4:20 PM Pingfan Liu wrote: > > On Wed, Apr 24, 2019 at 4:31 PM Matthias Brugger wrote: > > > > > [...] > > > @@ -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 -EINVAL; > > > > This covers the case where I pass an argument like "crashkernel=0M" ? > > Can't we fix that by using kstrtoull() in memparse and check if the return value > > is < 0? In that case we could return without updating the retptr and we will be > > fine. After a series of work, I suddenly realized that it can not be done like this way. "0M" causes kstrtoull() to return -EINVAL, but this is caused by "M", not "0". If passing "0" to kstrtoull(), it will return 0 on success. > > > It seems that kstrtoull() treats 0M as invalid parameter, while > simple_strtoull() does not. > My careless going through the code. And I tested with a valid value "256M" using kstrtoull(), it also returned -EINVAL. So I think there is no way to distinguish 0 from a positive value inside this basic math function. Do I miss anything? Thanks and regards, Pingfan _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-0.7 required=3.0 tests=DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 915F2C43219 for ; Thu, 2 May 2019 06:24:00 +0000 (UTC) Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C8BCC20873 for ; Thu, 2 May 2019 06:23:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="OUxx+AAH" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C8BCC20873 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 44vlb12mjLzDqVQ for ; Thu, 2 May 2019 16:23:57 +1000 (AEST) Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::141; helo=mail-it1-x141.google.com; envelope-from=kernelfans@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="OUxx+AAH"; dkim-atps=neutral Received: from mail-it1-x141.google.com (mail-it1-x141.google.com [IPv6:2607:f8b0:4864:20::141]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 44vlYB0PR9zDqLV for ; Thu, 2 May 2019 16:22:21 +1000 (AEST) Received: by mail-it1-x141.google.com with SMTP id q19so1447535itk.3 for ; Wed, 01 May 2019 23:22:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=k56mmNJm2c37muwGSNyw5prel5SUd23hcD0vEkYllYY=; b=OUxx+AAHpV80+7jWx8f1+E7itJj9D1rgHeIv5/3VMm7TKAnaU1bHWCA0kR/Uu4B/N0 YiDM2kOhNwjBsVDh7yPbvcSscs4wrg/XbXz1H/w3lDdnJU4TQ9QwedxsTFe/Bbjt18D3 JRn/qzW0ooD8Rl7s9nAI0qgl8XU1Fhb9EsRc0VNWcSWwmT5yQ/Ep3gbO5ZmDWB/2TOjs 56aGZ16FpdQ10TxCUNbdRMfiLjvkeIGo1brUr0GBhS/X+j6ZJRXFbl8XXTiVI/tpSorx HgJ21xXoiQgpOYV/KzFy4OYZm4ZtO8AhUMxPfwPWagYl7mDnLgavitYf7mYuADYjNy/N 5KRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=k56mmNJm2c37muwGSNyw5prel5SUd23hcD0vEkYllYY=; b=jTCnwodCu9o8Y44kYY2SRHQeb7F5Fdc9QzPHNTBNBhwVwodTZuNplhLyqX8TCsDFcp uVlwybWGtYAB/aLDQ5/xRv8kvdjJ41TZaDr3+2VuOr50MDdFOtAamX/KSMeaVfLu6ITm IYuJQtEzjo+WLCDJ0yec5OmZXHr7k0gm3EtArho5uLK3IMQF23tH0/6EmOE5lo6dfOGR rmuHYEiaT81MvKbLu4Aio47fCyVCg/cqcQK+uxBYZeDNrGERtgNJV4kCX+zYvkhaY5Fu U4NTp89zID4Cd9YU+1XXMNMe9/q8uDr4q47JI1X8wkqNRX7N0Hceg4r2lRpp+ak+YfPo WL2A== X-Gm-Message-State: APjAAAV8b6kyZm/Ya2H1O+SYO+tfRjHmGnMt1fkFjn1fUpC6YMJybhG+ MzoGFiXF/zmXu3YbqQxJ7BmPRIB6CglJH9P4KQ== X-Google-Smtp-Source: APXvYqx2USGvNZCoaLJnd+1UamBCWbf1OMfqf8foQXGwbUGpu68tSJhvorSVm2AnXEjYEs1kPbB4DdJnuY+hXU3VFhQ= X-Received: by 2002:a05:660c:38e:: with SMTP id x14mr1138760itj.146.1556778137619; Wed, 01 May 2019 23:22:17 -0700 (PDT) MIME-Version: 1.0 References: <1556087581-14513-1-git-send-email-kernelfans@gmail.com> <10dc5468-6cd9-85c7-ba66-1dfa5aa922b7@suse.com> In-Reply-To: From: Pingfan Liu Date: Thu, 2 May 2019 14:22:06 +0800 Message-ID: Subject: Re: [PATCHv2] kernel/crash: make parse_crashkernel()'s return value more indicant To: Matthias Brugger Content-Type: text/plain; charset="UTF-8" X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Rich Felker , linux-ia64@vger.kernel.org, Julien Thierry , Yangtao Li , Palmer Dabbelt , Heiko Carstens , Stefan Agner , linux-mips@vger.kernel.org, Paul Mackerras , "H. Peter Anvin" , Thomas Gleixner , Logan Gunthorpe , linux-s390@vger.kernel.org, Florian Fainelli , Yoshinori Sato , linux-sh@vger.kernel.org, x86@kernel.org, Russell King , Ingo Molnar , Hari Bathini , Catalin Marinas , James Hogan , Dave Young , Fenghua Yu , Will Deacon , Johannes Weiner , Borislav Petkov , David Hildenbrand , linux-arm-kernel@lists.infradead.org, Jens Axboe , Tony Luck , Baoquan He , Ard Biesheuvel , Robin Murphy , LKML , Ralf Baechle , Thomas Bogendoerfer , Paul Burton , Greg Kroah-Hartman , Martin Schwidefsky , Andrew Morton , linuxppc-dev@lists.ozlabs.org, Greg Hackmann Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" On Thu, Apr 25, 2019 at 4:20 PM Pingfan Liu wrote: > > On Wed, Apr 24, 2019 at 4:31 PM Matthias Brugger wrote: > > > > > [...] > > > @@ -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 -EINVAL; > > > > This covers the case where I pass an argument like "crashkernel=0M" ? > > Can't we fix that by using kstrtoull() in memparse and check if the return value > > is < 0? In that case we could return without updating the retptr and we will be > > fine. After a series of work, I suddenly realized that it can not be done like this way. "0M" causes kstrtoull() to return -EINVAL, but this is caused by "M", not "0". If passing "0" to kstrtoull(), it will return 0 on success. > > > It seems that kstrtoull() treats 0M as invalid parameter, while > simple_strtoull() does not. > My careless going through the code. And I tested with a valid value "256M" using kstrtoull(), it also returned -EINVAL. So I think there is no way to distinguish 0 from a positive value inside this basic math function. Do I miss anything? Thanks and regards, Pingfan