2022-02-27 22:51:34

by Dr. David Alan Gilbert

[permalink] [raw]
Subject: [PATCH] mm: Use strtobool for param parsing

Use strtobool rather than open coding "on" and "off" parsing in
mm/hugetlb_vmemmap.c and mm/page_table_check.c.

Signed-off-by: Dr. David Alan Gilbert <[email protected]>
---
mm/hugetlb_vmemmap.c | 12 +-----------
mm/page_table_check.c | 10 +---------
2 files changed, 2 insertions(+), 20 deletions(-)

diff --git a/mm/hugetlb_vmemmap.c b/mm/hugetlb_vmemmap.c
index c540c21e26f5b..919411386e547 100644
--- a/mm/hugetlb_vmemmap.c
+++ b/mm/hugetlb_vmemmap.c
@@ -192,17 +192,7 @@ static int __init early_hugetlb_free_vmemmap_param(char *buf)
return 0;
}

- if (!buf)
- return -EINVAL;
-
- if (!strcmp(buf, "on"))
- hugetlb_free_vmemmap_enabled = true;
- else if (!strcmp(buf, "off"))
- hugetlb_free_vmemmap_enabled = false;
- else
- return -EINVAL;
-
- return 0;
+ return strtobool(buf, &hugetlb_free_vmemmap_enabled);
}
early_param("hugetlb_free_vmemmap", early_hugetlb_free_vmemmap_param);

diff --git a/mm/page_table_check.c b/mm/page_table_check.c
index 3763bd077861a..2458281bff893 100644
--- a/mm/page_table_check.c
+++ b/mm/page_table_check.c
@@ -23,15 +23,7 @@ EXPORT_SYMBOL(page_table_check_disabled);

static int __init early_page_table_check_param(char *buf)
{
- if (!buf)
- return -EINVAL;
-
- if (strcmp(buf, "on") == 0)
- __page_table_check_enabled = true;
- else if (strcmp(buf, "off") == 0)
- __page_table_check_enabled = false;
-
- return 0;
+ return strtobool(buf, &__page_table_check_enabled);
}

early_param("page_table_check", early_page_table_check_param);
--
2.35.1


2022-02-28 06:31:47

by Andrew Morton

[permalink] [raw]
Subject: Re: [PATCH] mm: Use strtobool for param parsing

On Sun, 27 Feb 2022 18:10:39 +0000 "Dr. David Alan Gilbert" <[email protected]> wrote:

> Use strtobool rather than open coding "on" and "off" parsing in
> mm/hugetlb_vmemmap.c and mm/page_table_check.c.
>
> Signed-off-by: Dr. David Alan Gilbert <[email protected]>
> ---
> mm/hugetlb_vmemmap.c | 12 +-----------
> mm/page_table_check.c | 10 +---------
> 2 files changed, 2 insertions(+), 20 deletions(-)
>
> diff --git a/mm/hugetlb_vmemmap.c b/mm/hugetlb_vmemmap.c
> index c540c21e26f5b..919411386e547 100644
> --- a/mm/hugetlb_vmemmap.c
> +++ b/mm/hugetlb_vmemmap.c
> @@ -192,17 +192,7 @@ static int __init early_hugetlb_free_vmemmap_param(char *buf)
> return 0;
> }
>
> - if (!buf)
> - return -EINVAL;
> -
> - if (!strcmp(buf, "on"))
> - hugetlb_free_vmemmap_enabled = true;
> - else if (!strcmp(buf, "off"))
> - hugetlb_free_vmemmap_enabled = false;
> - else
> - return -EINVAL;
> -
> - return 0;
> + return strtobool(buf, &hugetlb_free_vmemmap_enabled);
> }
> early_param("hugetlb_free_vmemmap", early_hugetlb_free_vmemmap_param);

This part falls afoul of the changes in
https://lkml.kernel.org/r/[email protected]

> diff --git a/mm/page_table_check.c b/mm/page_table_check.c
> index 3763bd077861a..2458281bff893 100644
> --- a/mm/page_table_check.c
> +++ b/mm/page_table_check.c
> @@ -23,15 +23,7 @@ EXPORT_SYMBOL(page_table_check_disabled);
>
> static int __init early_page_table_check_param(char *buf)
> {
> - if (!buf)
> - return -EINVAL;
> -
> - if (strcmp(buf, "on") == 0)
> - __page_table_check_enabled = true;
> - else if (strcmp(buf, "off") == 0)
> - __page_table_check_enabled = false;
> -
> - return 0;
> + return strtobool(buf, &__page_table_check_enabled);
> }

But this works OK.

2022-02-28 17:58:56

by Dr. David Alan Gilbert

[permalink] [raw]
Subject: Re: [PATCH] mm: Use strtobool for param parsing

* Andrew Morton ([email protected]) wrote:
> On Sun, 27 Feb 2022 18:10:39 +0000 "Dr. David Alan Gilbert" <[email protected]> wrote:
>
> > Use strtobool rather than open coding "on" and "off" parsing in
> > mm/hugetlb_vmemmap.c and mm/page_table_check.c.
> >
> > Signed-off-by: Dr. David Alan Gilbert <[email protected]>
> > ---
> > mm/hugetlb_vmemmap.c | 12 +-----------
> > mm/page_table_check.c | 10 +---------
> > 2 files changed, 2 insertions(+), 20 deletions(-)
> >
> > diff --git a/mm/hugetlb_vmemmap.c b/mm/hugetlb_vmemmap.c
> > index c540c21e26f5b..919411386e547 100644
> > --- a/mm/hugetlb_vmemmap.c
> > +++ b/mm/hugetlb_vmemmap.c
> > @@ -192,17 +192,7 @@ static int __init early_hugetlb_free_vmemmap_param(char *buf)
> > return 0;
> > }
> >
> > - if (!buf)
> > - return -EINVAL;
> > -
> > - if (!strcmp(buf, "on"))
> > - hugetlb_free_vmemmap_enabled = true;
> > - else if (!strcmp(buf, "off"))
> > - hugetlb_free_vmemmap_enabled = false;
> > - else
> > - return -EINVAL;
> > -
> > - return 0;
> > + return strtobool(buf, &hugetlb_free_vmemmap_enabled);
> > }
> > early_param("hugetlb_free_vmemmap", early_hugetlb_free_vmemmap_param);
>
> This part falls afoul of the changes in
> https://lkml.kernel.org/r/[email protected]

Hmm, yes that's quite different.

> > diff --git a/mm/page_table_check.c b/mm/page_table_check.c
> > index 3763bd077861a..2458281bff893 100644
> > --- a/mm/page_table_check.c
> > +++ b/mm/page_table_check.c
> > @@ -23,15 +23,7 @@ EXPORT_SYMBOL(page_table_check_disabled);
> >
> > static int __init early_page_table_check_param(char *buf)
> > {
> > - if (!buf)
> > - return -EINVAL;
> > -
> > - if (strcmp(buf, "on") == 0)
> > - __page_table_check_enabled = true;
> > - else if (strcmp(buf, "off") == 0)
> > - __page_table_check_enabled = false;
> > -
> > - return 0;
> > + return strtobool(buf, &__page_table_check_enabled);
> > }
>
> But this works OK.

Thanks for taking it.

Dave

--
-----Open up your eyes, open up your mind, open up your code -------
/ Dr. David Alan Gilbert | Running GNU/Linux | Happy \
\ dave @ treblig.org | | In Hex /
\ _________________________|_____ http://www.treblig.org |_______/