mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v3] ocfs2: heartbeat: replace simple_strtoul with kstrtoul
@ 2024-11-17 21:52 Daniel Yang
  2024-11-18  1:11 ` Joseph Qi
  0 siblings, 1 reply; 2+ messages in thread
From: Daniel Yang @ 2024-11-17 21:52 UTC (permalink / raw)
  To: Mark Fasheh, Joel Becker, Joseph Qi, GitAuthor: Daniel Yang,
	open list:ORACLE CLUSTER FILESYSTEM 2 (OCFS2),
	open list

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>
---
v2->v3: code style change and return ret
v1->v2: moved ret definition and removed blank lines

 fs/ocfs2/cluster/heartbeat.c | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/fs/ocfs2/cluster/heartbeat.c b/fs/ocfs2/cluster/heartbeat.c
index dff18efbc..76f1e7bfd 100644
--- a/fs/ocfs2/cluster/heartbeat.c
+++ b/fs/ocfs2/cluster/heartbeat.c
@@ -1536,10 +1536,11 @@ static int o2hb_read_block_input(struct o2hb_region *reg,
 {
 	unsigned long bytes;
 	char *p = (char *)page;
+	int ret;
 
-	bytes = simple_strtoul(p, &p, 0);
-	if (!p || (*p && (*p != '\n')))
-		return -EINVAL;
+	ret = kstrtoul(p, 0, &bytes);
+	if (ret)
+		return ret;
 
 	/* Heartbeat and fs min / max block sizes are the same. */
 	if (bytes > 4096 || bytes < 512)
@@ -1623,13 +1624,14 @@ static ssize_t o2hb_region_blocks_store(struct config_item *item,
 	struct o2hb_region *reg = to_o2hb_region(item);
 	unsigned long tmp;
 	char *p = (char *)page;
+	int ret;
 
 	if (reg->hr_bdev_file)
 		return -EINVAL;
 
-	tmp = simple_strtoul(p, &p, 0);
-	if (!p || (*p && (*p != '\n')))
-		return -EINVAL;
+	ret = kstrtoul(p, 0, &tmp);
+	if (ret)
+		return ret;
 
 	if (tmp > O2NM_MAX_NODES || tmp == 0)
 		return -ERANGE;
@@ -2141,10 +2143,11 @@ static ssize_t o2hb_heartbeat_group_dead_threshold_store(struct config_item *ite
 {
 	unsigned long tmp;
 	char *p = (char *)page;
+	int ret;
 
-	tmp = simple_strtoul(p, &p, 10);
-	if (!p || (*p && (*p != '\n')))
-                return -EINVAL;
+	ret = kstrtoul(p, 10, &tmp);
+	if (ret)
+		return ret;
 
 	/* this will validate ranges for us. */
 	o2hb_dead_threshold_set((unsigned int) tmp);
-- 
2.39.5


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

* Re: [PATCH v3] ocfs2: heartbeat: replace simple_strtoul with kstrtoul
  2024-11-17 21:52 [PATCH v3] ocfs2: heartbeat: replace simple_strtoul with kstrtoul Daniel Yang
@ 2024-11-18  1:11 ` Joseph Qi
  0 siblings, 0 replies; 2+ messages in thread
From: Joseph Qi @ 2024-11-18  1:11 UTC (permalink / raw)
  To: Daniel Yang, akpm
  Cc: Mark Fasheh, Joel Becker,
	open list:ORACLE CLUSTER FILESYSTEM 2 (OCFS2),
	open list



On 11/18/24 5:52 AM, Daniel Yang wrote:
> 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>

Reviewed-by: Joseph Qi <joseph.qi@linux.alibaba.com>
> ---
> v2->v3: code style change and return ret
> v1->v2: moved ret definition and removed blank lines
> 
>  fs/ocfs2/cluster/heartbeat.c | 21 ++++++++++++---------
>  1 file changed, 12 insertions(+), 9 deletions(-)
> 
> diff --git a/fs/ocfs2/cluster/heartbeat.c b/fs/ocfs2/cluster/heartbeat.c
> index dff18efbc..76f1e7bfd 100644
> --- a/fs/ocfs2/cluster/heartbeat.c
> +++ b/fs/ocfs2/cluster/heartbeat.c
> @@ -1536,10 +1536,11 @@ static int o2hb_read_block_input(struct o2hb_region *reg,
>  {
>  	unsigned long bytes;
>  	char *p = (char *)page;
> +	int ret;
>  
> -	bytes = simple_strtoul(p, &p, 0);
> -	if (!p || (*p && (*p != '\n')))
> -		return -EINVAL;
> +	ret = kstrtoul(p, 0, &bytes);
> +	if (ret)
> +		return ret;
>  
>  	/* Heartbeat and fs min / max block sizes are the same. */
>  	if (bytes > 4096 || bytes < 512)
> @@ -1623,13 +1624,14 @@ static ssize_t o2hb_region_blocks_store(struct config_item *item,
>  	struct o2hb_region *reg = to_o2hb_region(item);
>  	unsigned long tmp;
>  	char *p = (char *)page;
> +	int ret;
>  
>  	if (reg->hr_bdev_file)
>  		return -EINVAL;
>  
> -	tmp = simple_strtoul(p, &p, 0);
> -	if (!p || (*p && (*p != '\n')))
> -		return -EINVAL;
> +	ret = kstrtoul(p, 0, &tmp);
> +	if (ret)
> +		return ret;
>  
>  	if (tmp > O2NM_MAX_NODES || tmp == 0)
>  		return -ERANGE;
> @@ -2141,10 +2143,11 @@ static ssize_t o2hb_heartbeat_group_dead_threshold_store(struct config_item *ite
>  {
>  	unsigned long tmp;
>  	char *p = (char *)page;
> +	int ret;
>  
> -	tmp = simple_strtoul(p, &p, 10);
> -	if (!p || (*p && (*p != '\n')))
> -                return -EINVAL;
> +	ret = kstrtoul(p, 10, &tmp);
> +	if (ret)
> +		return ret;
>  
>  	/* this will validate ranges for us. */
>  	o2hb_dead_threshold_set((unsigned int) tmp);


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

end of thread, other threads:[~2024-11-18  1:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-11-17 21:52 [PATCH v3] ocfs2: heartbeat: replace simple_strtoul with kstrtoul Daniel Yang
2024-11-18  1:11 ` Joseph Qi

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®