From: Jagdish Gediya <jvgediya@linux.ibm.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: andy@kernel.org, linux-kernel@vger.kernel.org,
linux-mm@kvack.org, minchan@kernel.org, ying.huang@intel.com,
dave.hansen@intel.com
Subject: Re: [RESEND PATCH] string_helpers: sysfs: Add helper to get bool from string
Date: Tue, 26 Apr 2022 12:11:46 +0530 [thread overview]
Message-ID: <YmeUKg9s5AZUKXj8@li-6e1fa1cc-351b-11b2-a85c-b897023bb5f3.ibm.com> (raw)
In-Reply-To: <20220425150046.e23a0198e0076221549eb7cf@linux-foundation.org>
On Mon, Apr 25, 2022 at 03:00:46PM -0700, Andrew Morton wrote:
> On Mon, 25 Apr 2022 14:22:33 +0530 Jagdish Gediya <jvgediya@linux.ibm.com> wrote:
>
> > At many places in kernel, It is necessary to convert sysfs input
> > to corrosponding bool value e.g. "false" or "0" need to be converted
> > to bool false, "true" or "1" need to be converted to bool true,
> > places where such conversion is needed currently check the input
> > string manually. Also, such conversions compare sysfs input using
> > strncmp functions so even if certain number of character match in the
> > beginning, they assume the string as valid bool, which is not the
> > right semantic e.g. false is bool but falseX is not.
> >
> > Introduce new string helper function to convert sysfs input to
> > corrosponding bool value. Modify existing such conversions to use
> > this new function.
> >
> > logs,
> > $ cat /sys/kernel/mm/numa/demotion_enabled
> > false
> > $ echo true > /sys/kernel/mm/numa/demotion_enabled
> > $ cat demotion_enabled
> > true
> > $ echo truex > /sys/kernel/mm/numa/demotion_enabled
> > -bash: echo: write error: Invalid argument
> > $ echo 10 > /sys/kernel/mm/numa/demotion_enabled
> > -bash: echo: write error: Invalid argument
> > $ echo false > /sys/kernel/mm/numa/demotion_enabled
> > $ cat demotion_enabled
> > false
> > $ echo falseabc > /sys/kernel/mm/numa/demotion_enabled
> > -bash: echo: write error: Invalid argument
> > $ echo 1 > /sys/kernel/mm/numa/demotion_enabled
> > $ cat demotion_enabled
> > true
> > $ echo 0 > /sys/kernel/mm/numa/demotion_enabled
> > $ cat demotion_enabled
> > false
> >
> > This patch doesn't have any functionality change.
> >
> > ...
> >
> > --- a/lib/string_helpers.c
> > +++ b/lib/string_helpers.c
> > @@ -967,6 +967,26 @@ void memcpy_and_pad(void *dest, size_t dest_len, const void *src, size_t count,
> > }
> > EXPORT_SYMBOL(memcpy_and_pad);
> >
> > +/**
> > + * sysfs_strbool - Get bool value corrosponding to string
> > + * @s: The string to operate on.
> > + * @output: Pointer to fill resulting bool value
> > + *
> > + * Returns 1 if string represents bool value, 0 otherwise
> > + */
> > +int sysfs_strbool(const char *s, bool *output)
> > +{
> > + if (sysfs_streq(s, "1") || sysfs_streq(s, "true"))
> > + *output = true;
> > + else if (sysfs_streq(s, "0") || sysfs_streq(s, "false"))
> > + *output = false;
> > + else
> > + return 0;
> > +
> > + return 1;
> > +}
> > +EXPORT_SYMBOL(sysfs_strbool);
> > +
>
> Can we teach kstrtobool() about "true" and "false" then use that?
I think we can do that, I have sent v2. Thanks
prev parent reply other threads:[~2022-04-26 6:42 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-25 8:52 Jagdish Gediya
2022-04-25 22:00 ` Andrew Morton
2022-04-26 6:41 ` Jagdish Gediya [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YmeUKg9s5AZUKXj8@li-6e1fa1cc-351b-11b2-a85c-b897023bb5f3.ibm.com \
--to=jvgediya@linux.ibm.com \
--cc=akpm@linux-foundation.org \
--cc=andy@kernel.org \
--cc=dave.hansen@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=minchan@kernel.org \
--cc=ying.huang@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox