From: Alexey Dobriyan <adobriyan@gmail.com>
To: gregkh@linuxfoundation.org, rafael@kernel.org
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] driver core: cleanup kstrto*() usage
Date: Sun, 22 Nov 2020 15:10:18 +0300 [thread overview]
Message-ID: <20201122121018.GA48617@localhost.localdomain> (raw)
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;
}
next reply other threads:[~2020-11-22 12:10 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-22 12:10 Alexey Dobriyan [this message]
2020-11-23 0:31 ` [PATCH] driver core: cleanup kstrto*() usage kernel test robot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201122121018.GA48617@localhost.localdomain \
--to=adobriyan@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rafael@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox