[PATCH v2] ocfs2: replace deprecated simple_strtol with kstrtol

Daniel Yang posted 1 patch 1 week ago
fs/ocfs2/cluster/heartbeat.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
[PATCH v2] ocfs2: replace deprecated simple_strtol with kstrtol
Posted by Daniel Yang 1 week ago
The function simple_strtol ignores overflows and has an awkward
interface for error checking. Replace with the recommended kstrtol
function leads to clearer error checking and safer conversions.

Signed-off-by: Daniel Yang <danielyangkang@gmail.com>
---
v1->v2: reuse ret and remove blank line

 fs/ocfs2/cluster/heartbeat.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/fs/ocfs2/cluster/heartbeat.c b/fs/ocfs2/cluster/heartbeat.c
index 4b9f45d70..18333aa19 100644
--- a/fs/ocfs2/cluster/heartbeat.c
+++ b/fs/ocfs2/cluster/heartbeat.c
@@ -3,6 +3,7 @@
  * Copyright (C) 2004, 2005 Oracle.  All rights reserved.
  */
 
+#include "linux/kstrtox.h"
 #include <linux/kernel.h>
 #include <linux/sched.h>
 #include <linux/jiffies.h>
@@ -1777,8 +1778,8 @@ static ssize_t o2hb_region_dev_store(struct config_item *item,
 	if (o2nm_this_node() == O2NM_MAX_NODES)
 		goto out;
 
-	fd = simple_strtol(p, &p, 0);
-	if (!p || (*p && (*p != '\n')))
+	ret = kstrtol(p, 0, &fd);
+	if (ret < 0)
 		goto out;
 
 	if (fd < 0 || fd >= INT_MAX)
-- 
2.39.5
Re: [PATCH v2] ocfs2: replace deprecated simple_strtol with kstrtol
Posted by Joseph Qi 5 days, 4 hours ago

On 11/15/24 4:00 PM, Daniel Yang wrote:
> The function simple_strtol ignores overflows and has an awkward
> interface for error checking. Replace with the recommended kstrtol
> function leads to clearer error checking and safer conversions.
> 
> Signed-off-by: Daniel Yang <danielyangkang@gmail.com>

Looks good.
Reviewed-by: Joseph Qi <joseph.qi@linux.alibaba.com>

> ---
> v1->v2: reuse ret and remove blank line
> 
>  fs/ocfs2/cluster/heartbeat.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/ocfs2/cluster/heartbeat.c b/fs/ocfs2/cluster/heartbeat.c
> index 4b9f45d70..18333aa19 100644
> --- a/fs/ocfs2/cluster/heartbeat.c
> +++ b/fs/ocfs2/cluster/heartbeat.c
> @@ -3,6 +3,7 @@
>   * Copyright (C) 2004, 2005 Oracle.  All rights reserved.
>   */
>  
> +#include "linux/kstrtox.h"
>  #include <linux/kernel.h>
>  #include <linux/sched.h>
>  #include <linux/jiffies.h>
> @@ -1777,8 +1778,8 @@ static ssize_t o2hb_region_dev_store(struct config_item *item,
>  	if (o2nm_this_node() == O2NM_MAX_NODES)
>  		goto out;
>  
> -	fd = simple_strtol(p, &p, 0);
> -	if (!p || (*p && (*p != '\n')))
> +	ret = kstrtol(p, 0, &fd);
> +	if (ret < 0)
>  		goto out;
>  
>  	if (fd < 0 || fd >= INT_MAX)