Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755454AbbLKRAf (ORCPT ); Fri, 11 Dec 2015 12:00:35 -0500 Received: from mail-qk0-f174.google.com ([209.85.220.174]:33441 "EHLO mail-qk0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755331AbbLKRAd convert rfc822-to-8bit (ORCPT ); Fri, 11 Dec 2015 12:00:33 -0500 MIME-Version: 1.0 In-Reply-To: <1449697404-21076-3-git-send-email-keescook@chromium.org> References: <1449697404-21076-1-git-send-email-keescook@chromium.org> <1449697404-21076-3-git-send-email-keescook@chromium.org> Date: Fri, 11 Dec 2015 19:00:32 +0200 Message-ID: Subject: Re: [PATCH v3 2/8] lib: add "on" and "off" to strtobool From: Andy Shevchenko To: Kees Cook Cc: "linux-kernel@vger.kernel.org" , Rasmus Villemoes , Daniel Borkmann , Ingo Molnar , Andy Lutomirski , "H. Peter Anvin" , Michael Ellerman , Mathias Krause , Thomas Gleixner , "x86@kernel.org" , Arnd Bergmann , PaX Team , Emese Revfy , kernel-hardening@lists.openwall.com, linux-arch Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2291 Lines: 83 On Wed, Dec 9, 2015 at 11:43 PM, Kees Cook wrote: > Several places in the kernel expect to use "on" and "off" for their > boolean signifiers, so add them to strtobool. > > Signed-off-by: Kees Cook > Cc: Rasmus Villemoes > Cc: Daniel Borkmann > --- > lib/string.c | 21 ++++++++++++++++++++- > 1 file changed, 20 insertions(+), 1 deletion(-) > > diff --git a/lib/string.c b/lib/string.c > index 0323c0d5629a..d7550432f91c 100644 > --- a/lib/string.c > +++ b/lib/string.c > @@ -635,12 +635,16 @@ EXPORT_SYMBOL(sysfs_streq); > * @s: input string > * @res: result > * > - * This routine returns 0 iff the first character is one of 'Yy1Nn0'. > + * This routine returns 0 iff the first character is one of 'Yy1Nn0', or > + * 'Oo' when the second character is one of 'fFnN' (for "on" and "off"). Maybe …or [Oo][FfNn] for "off" and "on"… > * Otherwise it will return -EINVAL. Value pointed to by res is > * updated upon finding a match. > */ > int strtobool(const char *s, bool *res) > { > + if (!s) > + return -EINVAL; > + This change I think is better to do separately. Do we have even need for it? > switch (s[0]) { > case 'y': > case 'Y': > @@ -652,6 +656,21 @@ int strtobool(const char *s, bool *res) > case '0': > *res = false; > break; > + case 'o': > + case 'O': > + switch (s[1]) { > + case 'n': > + case 'N': > + *res = true; > + break; > + case 'f': > + case 'F': > + *res = false; > + break; > + default: > + return -EINVAL; > + } > + break; > default: > return -EINVAL; Maybe in both cases default: break; } … } return -EINVAL; -- With Best Regards, Andy Shevchenko -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/