From: Jagdish Gediya <jvgediya@linux.ibm.com>
To: linux-kernel@vger.kernel.org, linux-mm@kvack.org
Cc: Jonathan.Cameron@huawei.com, adobriyan@gmail.com,
akpm@linux-foundation.org, andriy.shevchenko@linux.intel.com,
rf@opensource.cirrus.com, pmladek@suse.com, ying.huang@intel.com,
dave.hansen@intel.com, Jagdish Gediya <jvgediya@linux.ibm.com>
Subject: [PATCH v2 1/2] lib/kstrtox.c: Add "false"/"true" support to kstrtobool()
Date: Tue, 26 Apr 2022 22:30:39 +0530 [thread overview]
Message-ID: <20220426170040.65487-1-jvgediya@linux.ibm.com> (raw)
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, kstrtobool() can be utilized at such places but
currently it doesn't have support to accept "false"/"true".
Add support to accept "false"/"true" as valid string in kstrtobool().
Signed-off-by: Jagdish Gediya <jvgediya@linux.ibm.com>
---
Chnage in v2:
- kstrtobool to kstrtobool() in commit message.
- Split single patch into 2
- Remove strcmp usage and instead compare 1st character only.
lib/kstrtox.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/lib/kstrtox.c b/lib/kstrtox.c
index 886510d248e5..465e31e4d70d 100644
--- a/lib/kstrtox.c
+++ b/lib/kstrtox.c
@@ -340,7 +340,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 'YyTt1NnFf0', or
* [oO][NnFf] for "on" and "off". Otherwise it will return -EINVAL. Value
* pointed to by res is updated upon finding a match.
*/
@@ -353,11 +353,15 @@ int kstrtobool(const char *s, bool *res)
switch (s[0]) {
case 'y':
case 'Y':
+ case 't':
+ case 'T':
case '1':
*res = true;
return 0;
case 'n':
case 'N':
+ case 'f':
+ case 'F':
case '0':
*res = false;
return 0;
--
2.35.1
next reply other threads:[~2022-04-26 17:01 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-26 17:00 Jagdish Gediya [this message]
2022-04-26 17:00 ` [PATCH v2 2/2] mm: Covert sysfs input to bool using kstrtobool() Jagdish Gediya
2022-04-26 17:24 ` Matthew Wilcox
2022-04-27 15:17 ` Andy Shevchenko
2022-05-13 1:05 ` Andrew Morton
2022-05-13 18:28 ` Alexey Dobriyan
2022-05-16 10:48 ` Jagdish Gediya
2022-05-16 10:47 ` Jagdish Gediya
2022-04-26 17:23 ` [PATCH v2 1/2] lib/kstrtox.c: Add "false"/"true" support to kstrtobool() Matthew Wilcox
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=20220426170040.65487-1-jvgediya@linux.ibm.com \
--to=jvgediya@linux.ibm.com \
--cc=Jonathan.Cameron@huawei.com \
--cc=adobriyan@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=andriy.shevchenko@linux.intel.com \
--cc=dave.hansen@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=pmladek@suse.com \
--cc=rf@opensource.cirrus.com \
--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;
as well as URLs for NNTP newsgroup(s).