linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 1/2] lib/kstrtox.c: Add "false"/"true" support to kstrtobool()
@ 2022-04-26 18:02 Jagdish Gediya
  2022-04-26 18:02 ` [PATCH v3 2/2] mm: Convert sysfs input to bool using kstrtobool() Jagdish Gediya
                   ` (3 more replies)
  0 siblings, 4 replies; 18+ messages in thread
From: Jagdish Gediya @ 2022-04-26 18:02 UTC (permalink / raw)
  To: linux-kernel, linux-mm
  Cc: willy, ying.huang, dave.hansen, Jonathan.Cameron, adobriyan,
	akpm, andriy.shevchenko, rf, pmladek, Jagdish Gediya

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>
Reviewed-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
Chnages in v2:
- kstrtobool to kstrtobool() in commit message.
- Split single patch into 2
- Remove strcmp usage from kstrtobool() and instead compare 1st
  character only.

Changes in v3:
- Covert -> Convert in patch 2 subject
- Collected Reviewed-by: Matthew Wilcox (Oracle) <willy@infradead.org>

 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



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

end of thread, other threads:[~2022-08-26 10:36 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-26 18:02 [PATCH v3 1/2] lib/kstrtox.c: Add "false"/"true" support to kstrtobool() Jagdish Gediya
2022-04-26 18:02 ` [PATCH v3 2/2] mm: Convert sysfs input to bool using kstrtobool() Jagdish Gediya
2022-04-26 19:14 ` [PATCH v3 1/2] lib/kstrtox.c: Add "false"/"true" support to kstrtobool() Matthew Wilcox
2022-04-26 20:40   ` David Laight
2022-04-27 10:21   ` Jagdish Gediya
2022-04-27 15:13 ` Andy Shevchenko
2022-04-27 17:39   ` Andrew Morton
2022-04-27 18:17     ` Andy Shevchenko
2022-04-27 18:19       ` Andy Shevchenko
2022-07-25 14:55 ` Mark Rutland
2022-07-25 15:21   ` Matthew Wilcox
2022-07-25 15:36     ` Mark Rutland
2022-07-29 14:35     ` Andy Shevchenko
2022-07-29 14:36       ` Andy Shevchenko
2022-08-25 13:39         ` Petr Mladek
2022-08-26 10:35           ` Will Deacon
2022-07-29 15:17       ` Alexey Dobriyan
2022-07-29 15:32         ` Andy Shevchenko

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).