From: Andy Shevchenko Date: Wed, 16 Dec 2020 04:43:30 +0000 (-0800) Subject: lib/cmdline: allow NULL to be an output for get_option() X-Git-Tag: accepted/tizen/unified/20230118.172025~8285^2~67 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6b2b6b864684848f9deacb6d0faa00626860832e;p=platform%2Fkernel%2Flinux-rpi.git 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 Signed-off-by: Linus Torvalds --- diff --git a/lib/cmdline.c b/lib/cmdline.c index ca89846..9e18623 100644 --- a/lib/cmdline.c +++ b/lib/cmdline.c @@ -35,11 +35,14 @@ static int get_range(char **str, int *pint, int n) /** * 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 *pint, int n) 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 == ',') {