mirror of
https://github.com/edk2-porting/linux-next.git
synced 2024-12-16 17:23:55 +08:00
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 <andriy.shevchenko@linux.intel.com> Cc: Brendan Higgins <brendanhiggins@google.com> Cc: David Gow <davidgow@google.com> Cc: Mark Brown <broonie@kernel.org> Cc: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com> Cc: Shuah Khan <skhan@linuxfoundation.org> Cc: Vitor Massaru Iha <vitor@massaru.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
e291851d65
commit
6b2b6b8646
@ -35,11 +35,14 @@ static int get_range(char **str, int *pint, int n)
|
|||||||
/**
|
/**
|
||||||
* get_option - Parse integer from an option string
|
* get_option - Parse integer from an option string
|
||||||
* @str: 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
|
* Read an int from an option string; if available accept a subsequent
|
||||||
* comma as well.
|
* comma as well.
|
||||||
*
|
*
|
||||||
|
* When @pint is NULL the function can be used as a validator of
|
||||||
|
* the current option in the string.
|
||||||
|
*
|
||||||
* Return values:
|
* Return values:
|
||||||
* 0 - no int in string
|
* 0 - no int in string
|
||||||
* 1 - int found, no subsequent comma
|
* 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)
|
int get_option(char **str, int *pint)
|
||||||
{
|
{
|
||||||
char *cur = *str;
|
char *cur = *str;
|
||||||
|
int value;
|
||||||
|
|
||||||
if (!cur || !(*cur))
|
if (!cur || !(*cur))
|
||||||
return 0;
|
return 0;
|
||||||
if (*cur == '-')
|
if (*cur == '-')
|
||||||
*pint = -simple_strtoull(++cur, str, 0);
|
value = -simple_strtoull(++cur, str, 0);
|
||||||
else
|
else
|
||||||
*pint = simple_strtoull(cur, str, 0);
|
value = simple_strtoull(cur, str, 0);
|
||||||
|
if (pint)
|
||||||
|
*pint = value;
|
||||||
if (cur == *str)
|
if (cur == *str)
|
||||||
return 0;
|
return 0;
|
||||||
if (**str == ',') {
|
if (**str == ',') {
|
||||||
|
Loading…
Reference in New Issue
Block a user