From: Daniel Yang <danielyangkang@gmail.com>
To: Mark Fasheh <mark@fasheh.com>, Joel Becker <jlbec@evilplan.org>,
Joseph Qi <joseph.qi@linux.alibaba.com>,
"GitAuthor: Daniel Yang" <danielyangkang@gmail.com>,
ocfs2-devel@lists.linux.dev (open list:ORACLE CLUSTER FILESYSTEM
2 (OCFS2)), linux-kernel@vger.kernel.org (open list)
Subject: [PATCH] ocfs2: heartbeat: replace simple_strtoul with kstrtoul
Date: Wed, 13 Nov 2024 00:41:07 -0800 [thread overview]
Message-ID: <20241113084108.186506-1-danielyangkang@gmail.com> (raw)
The function simple_strtoul is deprecated due to ignoring overflows and
also requires clunkier error checking. Replacing with kstrtoul() leads
to safer code and cleaner error checking.
Signed-off-by: Daniel Yang <danielyangkang@gmail.com>
---
fs/ocfs2/cluster/heartbeat.c | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/fs/ocfs2/cluster/heartbeat.c b/fs/ocfs2/cluster/heartbeat.c
index dff18efbc..4fc1b23f1 100644
--- a/fs/ocfs2/cluster/heartbeat.c
+++ b/fs/ocfs2/cluster/heartbeat.c
@@ -1537,8 +1537,9 @@ static int o2hb_read_block_input(struct o2hb_region *reg,
unsigned long bytes;
char *p = (char *)page;
- bytes = simple_strtoul(p, &p, 0);
- if (!p || (*p && (*p != '\n')))
+ int ret = kstrtoul(p, 0, &bytes);
+
+ if (ret)
return -EINVAL;
/* Heartbeat and fs min / max block sizes are the same. */
@@ -1627,8 +1628,9 @@ static ssize_t o2hb_region_blocks_store(struct config_item *item,
if (reg->hr_bdev_file)
return -EINVAL;
- tmp = simple_strtoul(p, &p, 0);
- if (!p || (*p && (*p != '\n')))
+ int ret = kstrtoul(p, 0, &tmp);
+
+ if (ret)
return -EINVAL;
if (tmp > O2NM_MAX_NODES || tmp == 0)
@@ -2142,8 +2144,9 @@ static ssize_t o2hb_heartbeat_group_dead_threshold_store(struct config_item *ite
unsigned long tmp;
char *p = (char *)page;
- tmp = simple_strtoul(p, &p, 10);
- if (!p || (*p && (*p != '\n')))
+ int ret = kstrtoul(p, 10, &tmp);
+
+ if (ret)
return -EINVAL;
/* this will validate ranges for us. */
--
2.39.5
next reply other threads:[~2024-11-13 8:41 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-13 8:41 Daniel Yang [this message]
2024-11-15 1:01 ` Joseph Qi
2024-11-15 7:53 ` Daniel Yang
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=20241113084108.186506-1-danielyangkang@gmail.com \
--to=danielyangkang@gmail.com \
--cc=jlbec@evilplan.org \
--cc=joseph.qi@linux.alibaba.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mark@fasheh.com \
--cc=ocfs2-devel@lists.linux.dev \
/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
all inboxes | Powered by JetHome®