[PATCH 07/12] samples: configfs: replace simple_strtoul() with kstrtoint()
From: Bartosz Golaszewski
Date: Thu Sep 24 2020 - 08:45:57 EST
From: Bartosz Golaszewski <bgolaszewski@xxxxxxxxxxxx>
simple_strtoul() is deprecated. Use kstrtoint().
Signed-off-by: Bartosz Golaszewski <bgolaszewski@xxxxxxxxxxxx>
---
samples/configfs/configfs_sample.c | 29 +++++++++--------------------
1 file changed, 9 insertions(+), 20 deletions(-)
diff --git a/samples/configfs/configfs_sample.c b/samples/configfs/configfs_sample.c
index 3e6f0e0b0f72..d89a1ffea620 100644
--- a/samples/configfs/configfs_sample.c
+++ b/samples/configfs/configfs_sample.c
@@ -14,6 +14,7 @@
#include <linux/configfs.h>
#include <linux/init.h>
+#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/slab.h>
@@ -61,17 +62,11 @@ static ssize_t childless_storeme_store(struct config_item *item,
const char *page, size_t count)
{
struct childless *childless = to_childless(item);
- unsigned long tmp;
- char *p = (char *) page;
-
- tmp = simple_strtoul(p, &p, 10);
- if (!p || (*p && (*p != '\n')))
- return -EINVAL;
-
- if (tmp > INT_MAX)
- return -ERANGE;
+ int ret;
- childless->storeme = tmp;
+ ret = kstrtoint(page, 10, &childless->storeme);
+ if (ret)
+ return ret;
return count;
}
@@ -144,17 +139,11 @@ static ssize_t simple_child_storeme_store(struct config_item *item,
const char *page, size_t count)
{
struct simple_child *simple_child = to_simple_child(item);
- unsigned long tmp;
- char *p = (char *) page;
-
- tmp = simple_strtoul(p, &p, 10);
- if (!p || (*p && (*p != '\n')))
- return -EINVAL;
-
- if (tmp > INT_MAX)
- return -ERANGE;
+ int ret;
- simple_child->storeme = tmp;
+ ret = kstrtoint(page, 10, &simple_child->storeme);
+ if (ret)
+ return ret;
return count;
}
--
2.17.1