ocfs2: heartbeat: replace simple_strtoul with kstrtoul
authorDaniel Yang <danielyangkang@gmail.com>
Sun, 17 Nov 2024 21:52:18 +0000 (13:52 -0800)
committerAndrew Morton <akpm@linux-foundation.org>
Mon, 13 Jan 2025 04:21:07 +0000 (20:21 -0800)
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.

Link: https://lkml.kernel.org/r/20241117215219.4012-1-danielyangkang@gmail.com
Signed-off-by: Daniel Yang <danielyangkang@gmail.com>
Reviewed-by: Joseph Qi <joseph.qi@linux.alibaba.com>
Cc: Mark Fasheh <mark@fasheh.com>
Cc: Joel Becker <jlbec@evilplan.org>
Cc: Junxiao Bi <junxiao.bi@oracle.com>
Cc: Changwei Ge <gechangwei@live.cn>
Cc: Jun Piao <piaojun@huawei.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
fs/ocfs2/cluster/heartbeat.c

index 4200a0341343087b7e82eb74136abb35051cd4df..a67817e0e66378726cb819cd9ffe53002ce3d4e8 100644 (file)
@@ -1535,10 +1535,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)
@@ -1622,13 +1623,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;
@@ -2136,10 +2138,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);