From: Jagdish Gediya Date: Fri, 13 May 2022 03:22:59 +0000 (-0700) Subject: mm: convert sysfs input to bool using kstrtobool() X-Git-Tag: baikal/mips/sdk6.1~5677^2~130 X-Git-Url: https://git.baikalelectronics.ru/sdk/?a=commitdiff_plain;h=3b8a8ff9afd9182662a4356c53de4c5021ed362d;p=kernel.git 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 --- diff --git a/mm/migrate.c b/mm/migrate.c index b2678279eb43d..ab46ad93af9f7 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -2523,12 +2523,11 @@ 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 - return -EINVAL; + ssize_t ret; + + ret = kstrtobool(buf, &numa_demotion_enabled); + if (ret) + return ret; return count; } diff --git a/mm/swap_state.c b/mm/swap_state.c index d41746a572a28..27c4e28f795fa 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; }