Skip to contentSkip to conversation

ocfs2: replace deprecated simple_strtol with kstrtol

PATCH Superseded Daniel Yang 2 participants 3 messages Nov 13, 2024 – Nov 15, 2024 OCFS2

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ocfs2: replace deprecated simple_strtol with kstrtol

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.

---
 fs/ocfs2/cluster/heartbeat.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
fs/ocfs2/cluster/heartbeat.c +4 -2
index 4b9f45d70..dff18efbc 100644
@@ -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,9 @@ 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')))
+	int p_to_long_ret = kstrtol(p, 0, &fd);
+
+	if (p_to_long_ret < 0)
 		goto out;
 
 	if (fd < 0 || fd >= INT_MAX)
Signature · 1 line
2.39.5
maintainer
#1 lore raw
Quoted 22 lines · Daniel Yang

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.

---
 fs/ocfs2/cluster/heartbeat.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
fs/ocfs2/cluster/heartbeat.c +1 -0
index 4b9f45d70..dff18efbc 100644
@@ -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>

fs/ocfs2/cluster/heartbeat.c static ssize_t o2hb_region_dev_store(struct config_item *item, · line 1782

Quoted 7 lines
fs/ocfs2/cluster/heartbeat.c +2 -2
@@ -1777,8 +1778,9 @@ 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')))
+	int p_to_long_ret = kstrtol(p, 0, &fd);
+

Please define at the beginning.
Seems we can just re-use 'ret'.
BTW, the blank line can be eleminated.

Thanks,
Joseph

Quoted 4 lines
fs/ocfs2/cluster/heartbeat.c +1 -0
+	if (p_to_long_ret < 0)
 		goto out;
 
 	if (fd < 0 || fd >= INT_MAX)
#2 lore raw
Quoted 38 lines · Joseph Qi
Quoted 22 lines · Daniel Yang

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.

---
 fs/ocfs2/cluster/heartbeat.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
fs/ocfs2/cluster/heartbeat.c +1 -0
index 4b9f45d70..dff18efbc 100644
@@ -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>

fs/ocfs2/cluster/heartbeat.c static ssize_t o2hb_region_dev_store(struct config_item *item, · line 1782

Quoted 7 lines
fs/ocfs2/cluster/heartbeat.c +2 -2
@@ -1777,8 +1778,9 @@ 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')))
+     int p_to_long_ret = kstrtol(p, 0, &fd);
+

Please define at the beginning.
Seems we can just re-use 'ret'.
BTW, the blank line can be eleminated.

Quoted 8 lines

Thanks,
Joseph

Quoted 4 lines
fs/ocfs2/cluster/heartbeat.c +1 -0
+     if (p_to_long_ret < 0)
              goto out;
 
      if (fd < 0 || fd >= INT_MAX)

Ok. Made the changes and sent PATCH v2. Lmk if there's anything else that needs to be changed.

- Daniel