linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Use existing helper to convert "on/off" to boolean
@ 2016-04-29  5:47 Minfei Huang
  2016-04-29  8:04 ` Michal Hocko
  2016-04-29 21:21 ` Andrew Morton
  0 siblings, 2 replies; 6+ messages in thread
From: Minfei Huang @ 2016-04-29  5:47 UTC (permalink / raw)
  To: akpm, labbott, rjw, mgorman, mhocko, vbabka, rientjes,
	kirill.shutemov, iamjoonsoo.kim, izumi.taku, alexander.h.duyck,
	hannes
  Cc: linux-mm, linux-kernel, Minfei Huang

It's more convenient to use existing function helper to convert string
"on/off" to boolean.

Signed-off-by: Minfei Huang <mnghuan@gmail.com>
---
 lib/kstrtox.c    | 2 +-
 mm/page_alloc.c  | 9 +--------
 mm/page_poison.c | 8 +-------
 3 files changed, 3 insertions(+), 16 deletions(-)

diff --git a/lib/kstrtox.c b/lib/kstrtox.c
index d8a5cf6..3c66fc4 100644
--- a/lib/kstrtox.c
+++ b/lib/kstrtox.c
@@ -326,7 +326,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 if the first character is one of 'Yy1Nn0', or
  * [oO][NnFf] for "on" and "off". Otherwise it will return -EINVAL.  Value
  * pointed to by res is updated upon finding a match.
  */
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 59de90d..d31426d 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -513,14 +513,7 @@ static int __init early_debug_pagealloc(char *buf)
 {
 	if (!buf)
 		return -EINVAL;
-
-	if (strcmp(buf, "on") == 0)
-		_debug_pagealloc_enabled = true;
-
-	if (strcmp(buf, "off") == 0)
-		_debug_pagealloc_enabled = false;
-
-	return 0;
+	return kstrtobool(buf, &_debug_pagealloc_enabled);
 }
 early_param("debug_pagealloc", early_debug_pagealloc);
 
diff --git a/mm/page_poison.c b/mm/page_poison.c
index 479e7ea..1eae5fa 100644
--- a/mm/page_poison.c
+++ b/mm/page_poison.c
@@ -13,13 +13,7 @@ static int early_page_poison_param(char *buf)
 {
 	if (!buf)
 		return -EINVAL;
-
-	if (strcmp(buf, "on") == 0)
-		want_page_poisoning = true;
-	else if (strcmp(buf, "off") == 0)
-		want_page_poisoning = false;
-
-	return 0;
+	return strtobool(buf, &want_page_poisoning);
 }
 early_param("page_poison", early_page_poison_param);
 
-- 
2.6.3

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] Use existing helper to convert "on/off" to boolean
  2016-04-29  5:47 [PATCH] Use existing helper to convert "on/off" to boolean Minfei Huang
@ 2016-04-29  8:04 ` Michal Hocko
  2016-04-29  9:07   ` Minfei Huang
  2016-04-29 21:21 ` Andrew Morton
  1 sibling, 1 reply; 6+ messages in thread
From: Michal Hocko @ 2016-04-29  8:04 UTC (permalink / raw)
  To: Minfei Huang
  Cc: akpm, labbott, rjw, mgorman, vbabka, rientjes, kirill.shutemov,
	iamjoonsoo.kim, izumi.taku, alexander.h.duyck, hannes, linux-mm,
	linux-kernel

On Fri 29-04-16 13:47:04, Minfei Huang wrote:
> It's more convenient to use existing function helper to convert string
> "on/off" to boolean.

But kstrtobool in linux-next only does "This routine returns 0 iff the
first character is one of 'Yy1Nn0'" so it doesn't know about on/off.
Or am I missing anything?

> 
> Signed-off-by: Minfei Huang <mnghuan@gmail.com>
> ---
>  lib/kstrtox.c    | 2 +-
>  mm/page_alloc.c  | 9 +--------
>  mm/page_poison.c | 8 +-------
>  3 files changed, 3 insertions(+), 16 deletions(-)
> 
> diff --git a/lib/kstrtox.c b/lib/kstrtox.c
> index d8a5cf6..3c66fc4 100644
> --- a/lib/kstrtox.c
> +++ b/lib/kstrtox.c
> @@ -326,7 +326,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 if the first character is one of 'Yy1Nn0', or
>   * [oO][NnFf] for "on" and "off". Otherwise it will return -EINVAL.  Value
>   * pointed to by res is updated upon finding a match.
>   */
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index 59de90d..d31426d 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -513,14 +513,7 @@ static int __init early_debug_pagealloc(char *buf)
>  {
>  	if (!buf)
>  		return -EINVAL;
> -
> -	if (strcmp(buf, "on") == 0)
> -		_debug_pagealloc_enabled = true;
> -
> -	if (strcmp(buf, "off") == 0)
> -		_debug_pagealloc_enabled = false;
> -
> -	return 0;
> +	return kstrtobool(buf, &_debug_pagealloc_enabled);
>  }
>  early_param("debug_pagealloc", early_debug_pagealloc);
>  
> diff --git a/mm/page_poison.c b/mm/page_poison.c
> index 479e7ea..1eae5fa 100644
> --- a/mm/page_poison.c
> +++ b/mm/page_poison.c
> @@ -13,13 +13,7 @@ static int early_page_poison_param(char *buf)
>  {
>  	if (!buf)
>  		return -EINVAL;
> -
> -	if (strcmp(buf, "on") == 0)
> -		want_page_poisoning = true;
> -	else if (strcmp(buf, "off") == 0)
> -		want_page_poisoning = false;
> -
> -	return 0;
> +	return strtobool(buf, &want_page_poisoning);
>  }
>  early_param("page_poison", early_page_poison_param);
>  
> -- 
> 2.6.3
> 

-- 
Michal Hocko
SUSE Labs

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Use existing helper to convert "on/off" to boolean
  2016-04-29  8:04 ` Michal Hocko
@ 2016-04-29  9:07   ` Minfei Huang
  2016-04-29  9:21     ` Michal Hocko
  0 siblings, 1 reply; 6+ messages in thread
From: Minfei Huang @ 2016-04-29  9:07 UTC (permalink / raw)
  To: Michal Hocko
  Cc: akpm, labbott, rjw, mgorman, vbabka, rientjes, kirill.shutemov,
	iamjoonsoo.kim, izumi.taku, alexander.h.duyck, hannes, linux-mm,
	linux-kernel

On 04/29/16 at 10:04P, Michal Hocko wrote:
> On Fri 29-04-16 13:47:04, Minfei Huang wrote:
> > It's more convenient to use existing function helper to convert string
> > "on/off" to boolean.
> 
> But kstrtobool in linux-next only does "This routine returns 0 iff the
> first character is one of 'Yy1Nn0'" so it doesn't know about on/off.
> Or am I missing anything?

Hi, Michal.

Thanks for your reply.

Following is the kstrtobool comment from linus tree, which has explained
that this function can parse "on"/"off" string. Also Kees Cook has
posted such patch to fix this issue as well. So I think it's safe to fix
it.

"
  This routine returns 0 if the first character is one of 'Yy1Nn0', or
  [oO][NnFf] for "on" and "off". Otherwise it will return -EINVAL.  Value
  pointed to by res is updated upon finding a match.
"

  commit 4cc7ecb7f2a60e8deb783b8fbf7c1ae467acb920
  Author: Kees Cook <keescook@chromium.org>
  Date:   Thu Mar 17 14:23:00 2016 -0700
  
      param: convert some "on"/"off" users to strtobool
  
      This changes several users of manual "on"/"off" parsing to use
      strtobool.
  
      Some side-effects:
      - these uses will now parse y/n/1/0 meaningfully too
      - the early_param uses will now bubble up parse errors

Thanks
Minfei

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Use existing helper to convert "on/off" to boolean
  2016-04-29  9:07   ` Minfei Huang
@ 2016-04-29  9:21     ` Michal Hocko
  0 siblings, 0 replies; 6+ messages in thread
From: Michal Hocko @ 2016-04-29  9:21 UTC (permalink / raw)
  To: Minfei Huang
  Cc: akpm, labbott, rjw, mgorman, vbabka, rientjes, kirill.shutemov,
	iamjoonsoo.kim, izumi.taku, alexander.h.duyck, hannes, linux-mm,
	linux-kernel

On Fri 29-04-16 17:07:42, Minfei Huang wrote:
> On 04/29/16 at 10:04P, Michal Hocko wrote:
> > On Fri 29-04-16 13:47:04, Minfei Huang wrote:
> > > It's more convenient to use existing function helper to convert string
> > > "on/off" to boolean.
> > 
> > But kstrtobool in linux-next only does "This routine returns 0 iff the
> > first character is one of 'Yy1Nn0'" so it doesn't know about on/off.
> > Or am I missing anything?
> 
> Hi, Michal.
> 
> Thanks for your reply.
> 
> Following is the kstrtobool comment from linus tree, which has explained
> that this function can parse "on"/"off" string. Also Kees Cook has
> posted such patch to fix this issue as well. So I think it's safe to fix
> it.

OK, I was looking at wrong tree and missed a81a5a17d44b ("lib: add
"on"/"off" support to kstrtobool")

Sorry about the confusion. Feel free to add
Acked-by: Michal Hocko <mhocko@suse.com>
-- 
Michal Hocko
SUSE Labs

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Use existing helper to convert "on/off" to boolean
  2016-04-29  5:47 [PATCH] Use existing helper to convert "on/off" to boolean Minfei Huang
  2016-04-29  8:04 ` Michal Hocko
@ 2016-04-29 21:21 ` Andrew Morton
  2016-04-30  4:47   ` Minfei Huang
  1 sibling, 1 reply; 6+ messages in thread
From: Andrew Morton @ 2016-04-29 21:21 UTC (permalink / raw)
  To: Minfei Huang
  Cc: labbott, rjw, mgorman, mhocko, vbabka, rientjes, kirill.shutemov,
	iamjoonsoo.kim, izumi.taku, alexander.h.duyck, hannes, linux-mm,
	linux-kernel

On Fri, 29 Apr 2016 13:47:04 +0800 Minfei Huang <mnghuan@gmail.com> wrote:

> It's more convenient to use existing function helper to convert string
> "on/off" to boolean.
> 
> ...
>
> --- a/lib/kstrtox.c
> +++ b/lib/kstrtox.c
> @@ -326,7 +326,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 if the first character is one of 'Yy1Nn0', or

That isn't actually a typo.  "iff" is shorthand for "if and only if". 
ie: kstrtobool() will not return 0 in any other case.

Use of "iff" is a bit pretentious but I guess it does convey some
conceivably useful info.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Use existing helper to convert "on/off" to boolean
  2016-04-29 21:21 ` Andrew Morton
@ 2016-04-30  4:47   ` Minfei Huang
  0 siblings, 0 replies; 6+ messages in thread
From: Minfei Huang @ 2016-04-30  4:47 UTC (permalink / raw)
  To: Andrew Morton
  Cc: labbott, rjw, mgorman, mhocko, vbabka, rientjes, kirill.shutemov,
	iamjoonsoo.kim, izumi.taku, hannes, linux-mm, linux-kernel

On 04/29/16 at 02:21P, Andrew Morton wrote:
> On Fri, 29 Apr 2016 13:47:04 +0800 Minfei Huang <mnghuan@gmail.com> wrote:
> 
> > It's more convenient to use existing function helper to convert string
> > "on/off" to boolean.
> > 
> > ...
> >
> > --- a/lib/kstrtox.c
> > +++ b/lib/kstrtox.c
> > @@ -326,7 +326,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 if the first character is one of 'Yy1Nn0', or
> 
> That isn't actually a typo.  "iff" is shorthand for "if and only if". 
> ie: kstrtobool() will not return 0 in any other case.
> 
> Use of "iff" is a bit pretentious but I guess it does convey some
> conceivably useful info.
> 

Got it. Thanks for your explanation.

Thanks
Minfei

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2016-04-30  4:47 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-04-29  5:47 [PATCH] Use existing helper to convert "on/off" to boolean Minfei Huang
2016-04-29  8:04 ` Michal Hocko
2016-04-29  9:07   ` Minfei Huang
2016-04-29  9:21     ` Michal Hocko
2016-04-29 21:21 ` Andrew Morton
2016-04-30  4:47   ` Minfei Huang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).