]> git.baikalelectronics.ru Git - kernel.git/commitdiff
mm: convert sysfs input to bool using kstrtobool()
authorJagdish Gediya <jvgediya@linux.ibm.com>
Fri, 13 May 2022 03:22:59 +0000 (20:22 -0700)
committerAndrew Morton <akpm@linux-foundation.org>
Fri, 13 May 2022 14:20:13 +0000 (07:20 -0700)
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 <jvgediya@linux.ibm.com>
Reviewed-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: Alexey Dobriyan <adobriyan@gmail.com>
Cc: Dave Hansen <dave.hansen@intel.com>
Cc: "Huang, Ying" <ying.huang@intel.com>
Cc: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Cc: Petr Mladek <pmladek@suse.com>
Cc: Richard Fitzgerald <rf@opensource.cirrus.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/migrate.c
mm/swap_state.c

index b2678279eb43d1a8c7f82bf2ecd84b261e8e38ec..ab46ad93af9f7071fa38a78a12fbdc85ffe271eb 100644 (file)
@@ -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;
 }
index d41746a572a280a1879f2bd2b508054009eddf07..27c4e28f795fa5094339858a660b2722d815e244 100644 (file)
@@ -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;
 }