From 717aeab42943efa7cfa876b3b687c6ff36eae867 Mon Sep 17 00:00:00 2001 From: Jagdish Gediya Date: Thu, 12 May 2022 20:22:59 -0700 Subject: mm: convert sysfs input to bool using kstrtobool() 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. [akpm@linux-foundation.org: propagate kstrtobool() return value, per Andy] Link: https://lkml.kernel.org/r/20220426180203.70782-2-jvgediya@linux.ibm.com Signed-off-by: Jagdish Gediya Reviewed-by: Matthew Wilcox (Oracle) Reviewed-by: Andy Shevchenko Cc: Alexey Dobriyan Cc: Dave Hansen Cc: "Huang, Ying" Cc: Jonathan Cameron Cc: Petr Mladek Cc: Richard Fitzgerald Signed-off-by: Andrew Morton --- mm/swap_state.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'mm/swap_state.c') diff --git a/mm/swap_state.c b/mm/swap_state.c index d41746a572a2..27c4e28f795f 100644 --- a/mm/swap_state.c +++ b/mm/swap_state.c @@ -874,12 +874,11 @@ 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 - return -EINVAL; + ssize_t ret; + + ret = kstrtobool(buf, &enable_vma_readahead); + if (ret) + return ret; return count; } -- cgit v1.2.3-58-ga151