mirror of
https://github.com/torvalds/linux.git
synced 2026-10-07 05:31:08 -04:00
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(). [[email protected]: undo s/iff/if/, per Matthew] Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Jagdish Gediya <[email protected]> Reviewed-by: Matthew Wilcox (Oracle) <[email protected]> Reviewed-by: Andy Shevchenko <[email protected]> Cc: "Huang, Ying" <[email protected]> Cc: Dave Hansen <[email protected]> Cc: Jonathan Cameron <[email protected]> Cc: Alexey Dobriyan <[email protected]> Cc: Richard Fitzgerald <[email protected]> Cc: Petr Mladek <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
This commit is contained in:
1 parent
d8ff6fde8e
commit
0d6ea3ac94
1 file changed
+5
-1
+5
-1
@@ -340,7 +340,7 @@ EXPORT_SYMBOL(kstrtos8);
|
||||
* @s: input string
|
||||
* @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
|
||||
* pointed to by res is updated upon finding a match.
|
||||
*/
|
||||
@@ -353,11 +353,15 @@ int kstrtobool(const char *s, bool *res)
|
||||
switch (s[0]) {
|
||||
case 'y':
|
||||
case 'Y':
|
||||
case 't':
|
||||
case 'T':
|
||||
case '1':
|
||||
*res = true;
|
||||
return 0;
|
||||
case 'n':
|
||||
case 'N':
|
||||
case 'f':
|
||||
case 'F':
|
||||
case '0':
|
||||
*res = false;
|
||||
return 0;
|
||||
|
||||
Reference in new issue
Block a user