@@ -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. */
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(-)