Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Kees Cook and committed by
Linus Torvalds
a81a5a17 1404297e

+17 -3
+17 -3
lib/kstrtox.c
··· 326 326 * @s: input string 327 327 * @res: result 328 328 * 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. 332 332 */ 333 333 int kstrtobool(const char *s, bool *res) 334 334 { ··· 346 346 case '0': 347 347 *res = false; 348 348 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 + } 349 363 default: 350 364 break; 351 365 }