From patchwork Wed Dec 16 04:43:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 11976439 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=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham 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 039BFC4361B for ; Wed, 16 Dec 2020 04:43:31 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9A0CE23370 for ; Wed, 16 Dec 2020 04:43:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9A0CE23370 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 288C78D000B; Tue, 15 Dec 2020 23:43:30 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1C6718D0009; Tue, 15 Dec 2020 23:43:30 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 060B88D000B; Tue, 15 Dec 2020 23:43:29 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0188.hostedemail.com [216.40.44.188]) by kanga.kvack.org (Postfix) with ESMTP id E20278D0009 for ; Tue, 15 Dec 2020 23:43:29 -0500 (EST) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id B06E0362D for ; Wed, 16 Dec 2020 04:43:29 +0000 (UTC) X-FDA: 77597901738.25.blow76_4316ef727429 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin25.hostedemail.com (Postfix) with ESMTP id 809E21804E3B7 for ; Wed, 16 Dec 2020 04:43:29 +0000 (UTC) X-HE-Tag: blow76_4316ef727429 X-Filterd-Recvd-Size: 3039 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf37.hostedemail.com (Postfix) with ESMTP for ; Wed, 16 Dec 2020 04:43:29 +0000 (UTC) Date: Tue, 15 Dec 2020 20:43:27 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1608093808; bh=J7D5U/638dEYAewELIIchQGhPwn2487IxwMi9w4kjOI=; h=From:To:Subject:In-Reply-To:From; b=TFSIklyt6GKQgcQapb4HVNqMdxTLKJSnnPMXT03+HM0aa35yRntSyfwTwib3Iaq8O Gw2Dt31KaOOiPttthV+EoIRXHm1N5yq3dhtrXCXeGwjmaCDu7jwiM9DISOFP0Kl1pH O/E7au7LCVTzqHmsoyCqMsIu8ZCii9lJufqy5lF8= From: Andrew Morton To: akpm@linux-foundation.org, andriy.shevchenko@linux.intel.com, brendanhiggins@google.com, broonie@kernel.org, davidgow@google.com, linux-mm@kvack.org, matti.vaittinen@fi.rohmeurope.com, mm-commits@vger.kernel.org, skhan@linuxfoundation.org, torvalds@linux-foundation.org, vitor@massaru.org Subject: [patch 21/95] lib/cmdline: fix get_option() for strings starting with hyphen Message-ID: <20201216044327.eA-5bSIl3%akpm@linux-foundation.org> In-Reply-To: <20201215204156.f05ec694b907845bcfab5c44@linux-foundation.org> User-Agent: s-nail v14.8.16 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Andy Shevchenko Subject: lib/cmdline: fix get_option() for strings starting with hyphen When string doesn't have an integer and starts from hyphen get_option() may return interesting results. Fix it to return 0. The simple_strtoull() is used due to absence of simple_strtoul() in a boot code on some architectures. Note, the Fixes tag below is rather for anthropological curiosity. Link: https://lkml.kernel.org/r/20201112180732.75589-4-andriy.shevchenko@linux.intel.com Fixes: f68565831e72 ("Import 2.4.0-test2pre3") Signed-off-by: Andy Shevchenko Cc: Brendan Higgins Cc: David Gow Cc: Mark Brown Cc: Matti Vaittinen Cc: Shuah Khan Cc: Vitor Massaru Iha Signed-off-by: Andrew Morton --- lib/cmdline.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) --- a/lib/cmdline.c~lib-cmdline-fix-get_option-for-strings-starting-with-hyphen +++ a/lib/cmdline.c @@ -45,6 +45,9 @@ static int get_range(char **str, int *pi * 1 - int found, no subsequent comma * 2 - int found including a subsequent comma * 3 - hyphen found to denote a range + * + * Leading hyphen without integer is no integer case, but we consume it + * for the sake of simplification. */ int get_option(char **str, int *pint) @@ -53,7 +56,10 @@ int get_option(char **str, int *pint) if (!cur || !(*cur)) return 0; - *pint = simple_strtol(cur, str, 0); + if (*cur == '-') + *pint = -simple_strtoull(++cur, str, 0); + else + *pint = simple_strtoull(cur, str, 0); if (cur == *str) return 0; if (**str == ',') {