diff options
author | Kees Cook <keescook@chromium.org> | 2016-03-17 17:22:57 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2016-03-17 18:09:34 -0400 |
commit | a81a5a17d44b26521fb1199f8ccf27f4af337a67 (patch) | |
tree | 20e808f905e3ab2c24fcb9df40e2d0143f5a98b0 | |
parent | 1404297ebf76fd91a41de215fc8c94c2619e5fdb (diff) |
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>
-rw-r--r-- | lib/kstrtox.c | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/lib/kstrtox.c b/lib/kstrtox.c index e8ba4a013e82..d8a5cf66c316 100644 --- a/lib/kstrtox.c +++ b/lib/kstrtox.c | |||
@@ -326,9 +326,9 @@ EXPORT_SYMBOL(kstrtos8); | |||
326 | * @s: input string | 326 | * @s: input string |
327 | * @res: result | 327 | * @res: result |
328 | * | 328 | * |
329 | * This routine returns 0 iff the first character is one of 'Yy1Nn0'. | 329 | * This routine returns 0 iff the first character is one of 'Yy1Nn0', or |
330 | * Otherwise it will return -EINVAL. Value pointed to by res is | 330 | * [oO][NnFf] for "on" and "off". Otherwise it will return -EINVAL. Value |
331 | * updated upon finding a match. | 331 | * pointed to by res is updated upon finding a match. |
332 | */ | 332 | */ |
333 | int kstrtobool(const char *s, bool *res) | 333 | int kstrtobool(const char *s, bool *res) |
334 | { | 334 | { |
@@ -346,6 +346,20 @@ int kstrtobool(const char *s, bool *res) | |||
346 | case '0': | 346 | case '0': |
347 | *res = false; | 347 | *res = false; |
348 | return 0; | 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 | default: | 363 | default: |
350 | break; | 364 | break; |
351 | } | 365 | } |