Commit 0d6ea3ac authored by Jagdish Gediya's avatar Jagdish Gediya Committed by Andrew Morton

lib/kstrtox.c: add "false"/"true" support to kstrtobool()

At many places in kernel, It is necessary to convert sysfs input to
corresponding bool value e.g.  "false" or "0" need to be converted to bool
false, "true" or "1" need to be converted to bool true, places where such
conversion is needed currently check the input string manually,
kstrtobool() can be utilized at such places but currently it doesn't have
support to accept "false"/"true".

Add support to accept "false"/"true" as valid string in kstrtobool().

[akpm@linux-foundation.org: undo s/iff/if/, per Matthew]
Link: https://lkml.kernel.org/r/20220426180203.70782-1-jvgediya@linux.ibm.comSigned-off-by: default avatarJagdish Gediya <jvgediya@linux.ibm.com>
Reviewed-by: default avatarMatthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: default avatarAndy Shevchenko <andy.shevchenko@gmail.com>
Cc: "Huang, Ying" <ying.huang@intel.com>
Cc: Dave Hansen <dave.hansen@intel.com>
Cc: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Cc: Alexey Dobriyan <adobriyan@gmail.com>
Cc: Richard Fitzgerald <rf@opensource.cirrus.com>
Cc: Petr Mladek <pmladek@suse.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
parent d8ff6fde
...@@ -340,7 +340,7 @@ EXPORT_SYMBOL(kstrtos8); ...@@ -340,7 +340,7 @@ EXPORT_SYMBOL(kstrtos8);
* @s: input string * @s: input string
* @res: result * @res: result
* *
* This routine returns 0 iff the first character is one of 'Yy1Nn0', or * This routine returns 0 iff the first character is one of 'YyTt1NnFf0', or
* [oO][NnFf] for "on" and "off". Otherwise it will return -EINVAL. Value * [oO][NnFf] for "on" and "off". Otherwise it will return -EINVAL. Value
* pointed to by res is updated upon finding a match. * pointed to by res is updated upon finding a match.
*/ */
...@@ -353,11 +353,15 @@ int kstrtobool(const char *s, bool *res) ...@@ -353,11 +353,15 @@ int kstrtobool(const char *s, bool *res)
switch (s[0]) { switch (s[0]) {
case 'y': case 'y':
case 'Y': case 'Y':
case 't':
case 'T':
case '1': case '1':
*res = true; *res = true;
return 0; return 0;
case 'n': case 'n':
case 'N': case 'N':
case 'f':
case 'F':
case '0': case '0':
*res = false; *res = false;
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment