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=-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 3375BC4361B for ; Wed, 16 Dec 2020 04:43:34 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D642A23371 for ; Wed, 16 Dec 2020 04:43:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D642A23371 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 6CC7B6B0068; Tue, 15 Dec 2020 23:43:33 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 67B216B007B; Tue, 15 Dec 2020 23:43:33 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4F6CB6B007D; Tue, 15 Dec 2020 23:43:33 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0084.hostedemail.com [216.40.44.84]) by kanga.kvack.org (Postfix) with ESMTP id 35CFC6B0068 for ; Tue, 15 Dec 2020 23:43:33 -0500 (EST) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 0AAA7362D for ; Wed, 16 Dec 2020 04:43:33 +0000 (UTC) X-FDA: 77597901906.07.scene68_2b09eec27429 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin07.hostedemail.com (Postfix) with ESMTP id E643F1803FFCF for ; Wed, 16 Dec 2020 04:43:32 +0000 (UTC) X-HE-Tag: scene68_2b09eec27429 X-Filterd-Recvd-Size: 3211 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf03.hostedemail.com (Postfix) with ESMTP for ; Wed, 16 Dec 2020 04:43:32 +0000 (UTC) Date: Tue, 15 Dec 2020 20:43:30 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1608093811; bh=dYzhad7ZJ0fx36GnLLU5lopaUG3x56KBRcnwrH6tbnM=; h=From:To:Subject:In-Reply-To:From; b=Wjs2KkmImc3G/HtgmUC5+F32HUG+rGqDUXZkKA44FLdmx/r+SM2t2afmCa5CcwSOV A3SzNfb/En6mEbGRm/b98DqLVHvDlhIMR4EAXg3ddq0KHii5WgsRMe/3aLCMpdgjFY 0eL/I67DjP0VH+5v6MewkVYrN24rYbwLp8eHv5bA= 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 22/95] lib/cmdline: allow NULL to be an output for get_option() Message-ID: <20201216044330.xDkb95Dmk%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: allow NULL to be an output for get_option() In the future we would like to use get_option() to only validate the string and parse it separately. To achieve this, allow NULL to be an output for get_option(). Link: https://lkml.kernel.org/r/20201112180732.75589-5-andriy.shevchenko@linux.intel.com 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 | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) --- a/lib/cmdline.c~lib-cmdline-allow-null-to-be-an-output-for-get_option +++ a/lib/cmdline.c @@ -35,11 +35,14 @@ static int get_range(char **str, int *pi /** * get_option - Parse integer from an option string * @str: option string - * @pint: (output) integer value parsed from @str + * @pint: (optional output) integer value parsed from @str * * Read an int from an option string; if available accept a subsequent * comma as well. * + * When @pint is NULL the function can be used as a validator of + * the current option in the string. + * * Return values: * 0 - no int in string * 1 - int found, no subsequent comma @@ -53,13 +56,16 @@ static int get_range(char **str, int *pi int get_option(char **str, int *pint) { char *cur = *str; + int value; if (!cur || !(*cur)) return 0; if (*cur == '-') - *pint = -simple_strtoull(++cur, str, 0); + value = -simple_strtoull(++cur, str, 0); else - *pint = simple_strtoull(cur, str, 0); + value = simple_strtoull(cur, str, 0); + if (pint) + *pint = value; if (cur == *str) return 0; if (**str == ',') { _