All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jagdish Gediya <jvgediya@linux.ibm.com>
To: linux-kernel@vger.kernel.org, linux-mm@kvack.org
Cc: willy@infradead.org, ying.huang@intel.com, dave.hansen@intel.com,
	Jonathan.Cameron@huawei.com, adobriyan@gmail.com,
	akpm@linux-foundation.org, andriy.shevchenko@linux.intel.com,
	rf@opensource.cirrus.com, pmladek@suse.com,
	Jagdish Gediya <jvgediya@linux.ibm.com>
Subject: [PATCH v3 2/2] mm: Convert sysfs input to bool using kstrtobool()
Date: Tue, 26 Apr 2022 23:32:03 +0530	[thread overview]
Message-ID: <20220426180203.70782-2-jvgediya@linux.ibm.com> (raw)
In-Reply-To: <20220426180203.70782-1-jvgediya@linux.ibm.com>

Sysfs input conversion to corrosponding bool value e.g. "false" or "0"
to false, "true" or "1" to true are currently handled through strncmp
at multiple places. Use kstrtobool() to convert sysfs input to bool
value.

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>

 mm/migrate.c    | 6 +-----
 mm/swap_state.c | 6 +-----
 2 files changed, 2 insertions(+), 10 deletions(-)

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


  reply	other threads:[~2022-04-26 18:03 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 ` Jagdish Gediya [this message]
2022-04-26 19:14 ` 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

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=20220426180203.70782-2-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=willy@infradead.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.