[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220426064001.14241-1-jvgediya@linux.ibm.com>
Date: Tue, 26 Apr 2022 12:10:01 +0530
From: Jagdish Gediya <jvgediya@...ux.ibm.com>
To: linux-kernel@...r.kernel.org, linux-mm@...ck.org
Cc: ying.huang@...el.com, dave.hansen@...el.com,
Jagdish Gediya <jvgediya@...ux.ibm.com>,
Andrew Morton <akpm@...ux-foundation.org>,
Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
Richard Fitzgerald <rf@...nsource.cirrus.com>,
Petr Mladek <pmladek@...e.com>
Subject: [PATCH v2] lib/kstrtox.c: Add "false"/"true" support to kstrtobool
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 kstrtobool doesn't have support to "false"/"true".
Add "false"/"true" support to kstrtobool while string conversion
to bool. Modify existing manual sysfs conversions to use kstrtobool().
This patch doesn't have any functionality change.
Cc: Andrew Morton <akpm@...ux-foundation.org>
Cc: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
Cc: Richard Fitzgerald <rf@...nsource.cirrus.com>
Cc: Petr Mladek <pmladek@...e.com>
Signed-off-by: Jagdish Gediya <jvgediya@...ux.ibm.com>
---
change in v2:
Modified kstrtobool to handle "false"/"true". Removed
new function sysfs_strbool introduced in v1.
lib/kstrtox.c | 7 +++++++
mm/migrate.c | 6 +-----
mm/swap_state.c | 6 +-----
3 files changed, 9 insertions(+), 10 deletions(-)
diff --git a/lib/kstrtox.c b/lib/kstrtox.c
index 886510d248e5..3a5e29557838 100644
--- a/lib/kstrtox.c
+++ b/lib/kstrtox.c
@@ -377,6 +377,13 @@ int kstrtobool(const char *s, bool *res)
}
break;
default:
+ if (!strncmp(s, "true", 4)) {
+ *res = true;
+ return 0;
+ } else if (!strncmp(s, "false", 5)) {
+ *res = false;
+ return 0;
+ }
break;
}
diff --git a/mm/migrate.c b/mm/migrate.c
index 6c31ee1e1c9b..1de39bbfd6f9 100644
--- a/mm/migrate.c
+++ b/mm/migrate.c
@@ -2523,11 +2523,7 @@ static ssize_t numa_demotion_enabled_store(struct kobject *kobj,
struct kobj_attribute *attr,
const char *buf, size_t count)
{
- if (!strncmp(buf, "true", 4) || !strncmp(buf, "1", 1))
- numa_demotion_enabled = true;
- else if (!strncmp(buf, "false", 5) || !strncmp(buf, "0", 1))
- numa_demotion_enabled = false;
- else
+ if (kstrtobool(buf, &numa_demotion_enabled))
return -EINVAL;
return count;
diff --git a/mm/swap_state.c b/mm/swap_state.c
index 013856004825..dba10045a825 100644
--- a/mm/swap_state.c
+++ b/mm/swap_state.c
@@ -865,11 +865,7 @@ static ssize_t vma_ra_enabled_store(struct kobject *kobj,
struct kobj_attribute *attr,
const char *buf, size_t count)
{
- if (!strncmp(buf, "true", 4) || !strncmp(buf, "1", 1))
- enable_vma_readahead = true;
- else if (!strncmp(buf, "false", 5) || !strncmp(buf, "0", 1))
- enable_vma_readahead = false;
- else
+ if (kstrtobool(buf, &enable_vma_readahead))
return -EINVAL;
return count;
--
2.35.1
Powered by blists - more mailing lists