From: Jagdish Gediya Date: Fri, 13 May 2022 03:22:59 +0000 (-0700) Subject: lib/kstrtox.c: add "false"/"true" support to kstrtobool() X-Git-Tag: v6.1-rc5~1253^2~131 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0d6ea3ac94ca77c5273b064524ac5079312052a0;p=platform%2Fkernel%2Flinux-starfive.git 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.com Signed-off-by: Jagdish Gediya Reviewed-by: Matthew Wilcox (Oracle) Reviewed-by: Andy Shevchenko Cc: "Huang, Ying" Cc: Dave Hansen Cc: Jonathan Cameron Cc: Alexey Dobriyan Cc: Richard Fitzgerald Cc: Petr Mladek Signed-off-by: Andrew Morton --- diff --git a/lib/kstrtox.c b/lib/kstrtox.c index 886510d..08c1401 100644 --- a/lib/kstrtox.c +++ b/lib/kstrtox.c @@ -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;