[PATCH] driver core: cleanup kstrto*() usage
From: Alexey Dobriyan
Date: Sun Nov 22 2020 - 07:12:52 EST
kstrto*() functions can write result directly to target memory
if no additional checks needs to be done.
Signed-off-by: Alexey Dobriyan <adobriyan@xxxxxxxxx>
---
drivers/base/core.c | 12 +++---------
1 file changed, 3 insertions(+), 9 deletions(-)
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -1701,12 +1701,10 @@ ssize_t device_store_ulong(struct device *dev,
{
struct dev_ext_attribute *ea = to_ext_attr(attr);
int ret;
- unsigned long new;
- ret = kstrtoul(buf, 0, &new);
+ ret = kstrtoul(buf, 0, (unsigned long *)ea->var);
if (ret)
return ret;
- *(unsigned long *)(ea->var) = new;
/* Always return full write size even if we didn't consume all */
return size;
}
@@ -1726,16 +1724,12 @@ ssize_t device_store_int(struct device *dev,
const char *buf, size_t size)
{
struct dev_ext_attribute *ea = to_ext_attr(attr);
+ int val;
int ret;
- long new;
- ret = kstrtol(buf, 0, &new);
+ ret = kstrtoint(buf, 0, (int *)ea->var);
if (ret)
return ret;
-
- if (new > INT_MAX || new < INT_MIN)
- return -EINVAL;
- *(int *)(ea->var) = new;
/* Always return full write size even if we didn't consume all */
return size;
}