[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20201122121018.GA48617@localhost.localdomain>
Date: Sun, 22 Nov 2020 15:10:18 +0300
From: Alexey Dobriyan <adobriyan@...il.com>
To: gregkh@...uxfoundation.org, rafael@...nel.org
Cc: linux-kernel@...r.kernel.org
Subject: [PATCH] driver core: cleanup kstrto*() usage
kstrto*() functions can write result directly to target memory
if no additional checks needs to be done.
Signed-off-by: Alexey Dobriyan <adobriyan@...il.com>
---
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;
}
Powered by blists - more mailing lists