From: Hongbo Li <lihongbo22@huawei.com>
To: <ysato@users.sourceforge.jp>, <dalias@libc.org>,
<glaubitz@physik.fu-berlin.de>, <linux-sh@vger.kernel.org>
Cc: <lihongbo22@huawei.com>
Subject: [PATCH -next v3] sh: intc: replace simple_strtoul to kstrtoul
Date: Mon, 2 Sep 2024 10:45:34 +0800 [thread overview]
Message-ID: <20240902024534.2288168-1-lihongbo22@huawei.com> (raw)
The function simple_strtoul performs no error checking
in scenarios where the input value overflows the intended
output variable.
We can replace the use of the simple_strtoul with the safer
alternatives kstrtoul. For fail case, we also print the extra
message.
Signed-off-by: Hongbo Li <lihongbo22@huawei.com>
---
v3:
- Separate declaration and assignment to make it more consistent.
v2: https://lore.kernel.org/all/20240831094310.4148930-1-lihongbo22@huawei.com/T/
- Pass the error code returned by kstrtoul() suggested by Geert.
v1: https://lore.kernel.org/all/98c7b473-0b2b-4e47-83f6-35d9f417bb01@huawei.com/T/
---
drivers/sh/intc/userimask.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/sh/intc/userimask.c b/drivers/sh/intc/userimask.c
index abe9091827cd..a363f77881d1 100644
--- a/drivers/sh/intc/userimask.c
+++ b/drivers/sh/intc/userimask.c
@@ -32,8 +32,11 @@ store_intc_userimask(struct device *dev,
const char *buf, size_t count)
{
unsigned long level;
+ int ret;
- level = simple_strtoul(buf, NULL, 10);
+ ret = kstrtoul(buf, 10, &level);
+ if (ret != 0)
+ return ret;
/*
* Minimal acceptable IRQ levels are in the 2 - 16 range, but
--
2.34.1
next reply other threads:[~2024-09-02 2:37 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-02 2:45 Hongbo Li [this message]
2024-09-02 12:08 ` [PATCH -next v3] sh: intc: replace simple_strtoul to kstrtoul Geert Uytterhoeven
2024-09-26 12:22 ` John Paul Adrian Glaubitz
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=20240902024534.2288168-1-lihongbo22@huawei.com \
--to=lihongbo22@huawei.com \
--cc=dalias@libc.org \
--cc=glaubitz@physik.fu-berlin.de \
--cc=linux-sh@vger.kernel.org \
--cc=ysato@users.sourceforge.jp \
/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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).