Skip to content

Commit a81a5a1

Browse files
keestorvalds
authored andcommitted
lib: add "on"/"off" support to kstrtobool
Add support for "on" and "off" when converting to boolean. Signed-off-by: Kees Cook <keescook@chromium.org> Cc: Amitkumar Karwar <akarwar@marvell.com> Cc: Andy Shevchenko <andy.shevchenko@gmail.com> Cc: Daniel Borkmann <daniel@iogearbox.net> Cc: Heiko Carstens <heiko.carstens@de.ibm.com> Cc: Joe Perches <joe@perches.com> Cc: Kalle Valo <kvalo@codeaurora.org> Cc: Martin Schwidefsky <schwidefsky@de.ibm.com> Cc: Michael Ellerman <mpe@ellerman.id.au> Cc: Nishant Sarmukadam <nishants@marvell.com> Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk> Cc: Steve French <sfrench@samba.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 1404297 commit a81a5a1

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

lib/kstrtox.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,9 +326,9 @@ EXPORT_SYMBOL(kstrtos8);
326326
* @s: input string
327327
* @res: result
328328
*
329-
* This routine returns 0 iff the first character is one of 'Yy1Nn0'.
330-
* Otherwise it will return -EINVAL. Value pointed to by res is
331-
* updated upon finding a match.
329+
* This routine returns 0 iff the first character is one of 'Yy1Nn0', or
330+
* [oO][NnFf] for "on" and "off". Otherwise it will return -EINVAL. Value
331+
* pointed to by res is updated upon finding a match.
332332
*/
333333
int kstrtobool(const char *s, bool *res)
334334
{
@@ -346,6 +346,20 @@ int kstrtobool(const char *s, bool *res)
346346
case '0':
347347
*res = false;
348348
return 0;
349+
case 'o':
350+
case 'O':
351+
switch (s[1]) {
352+
case 'n':
353+
case 'N':
354+
*res = true;
355+
return 0;
356+
case 'f':
357+
case 'F':
358+
*res = false;
359+
return 0;
360+
default:
361+
break;
362+
}
349363
default:
350364
break;
351365
}

0 commit comments

Comments
 (0)