linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] driver core: cleanup kstrto*() usage
@ 2020-11-22 12:10 Alexey Dobriyan
  2020-11-23  0:31 ` kernel test robot
  0 siblings, 1 reply; 2+ messages in thread
From: Alexey Dobriyan @ 2020-11-22 12:10 UTC (permalink / raw)
  To: gregkh, rafael; +Cc: linux-kernel

kstrto*() functions can write result directly to target memory
if no additional checks needs to be done.

Signed-off-by: Alexey Dobriyan <adobriyan@gmail.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;
 }

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-11-23  0:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-22 12:10 [PATCH] driver core: cleanup kstrto*() usage Alexey Dobriyan
2020-11-23  0:31 ` kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).