* [PATCH] ocfs2: replace deprecated simple_strtol with kstrtol
@ 2024-11-13 8:09 Daniel Yang
2024-11-15 1:05 ` Joseph Qi
0 siblings, 1 reply; 3+ messages in thread
From: Daniel Yang @ 2024-11-13 8:09 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_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>
---
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..dff18efbc 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,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)
--
2.39.5
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] ocfs2: replace deprecated simple_strtol with kstrtol
2024-11-13 8:09 [PATCH] ocfs2: replace deprecated simple_strtol with kstrtol Daniel Yang
@ 2024-11-15 1:05 ` Joseph Qi
2024-11-15 8:01 ` Daniel Yang
0 siblings, 1 reply; 3+ messages in thread
From: Joseph Qi @ 2024-11-15 1:05 UTC (permalink / raw)
To: Daniel Yang, Mark Fasheh, Joel Becker,
open list:ORACLE CLUSTER FILESYSTEM 2 (OCFS2), open list
On 11/13/24 4:09 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>
> ---
> 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..dff18efbc 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,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
> + if (p_to_long_ret < 0)
> goto out;
>
> if (fd < 0 || fd >= INT_MAX)
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] ocfs2: replace deprecated simple_strtol with kstrtol
2024-11-15 1:05 ` Joseph Qi
@ 2024-11-15 8:01 ` Daniel Yang
0 siblings, 0 replies; 3+ messages in thread
From: Daniel Yang @ 2024-11-15 8:01 UTC (permalink / raw)
To: Joseph Qi
Cc: Mark Fasheh, Joel Becker,
open list:ORACLE CLUSTER FILESYSTEM 2 (OCFS2), open list
On Thu, Nov 14, 2024 at 5:05 PM Joseph Qi <joseph.qi@linux.alibaba.com> wrote:
>
>
>
> On 11/13/24 4:09 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>
> > ---
> > 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..dff18efbc 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,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
>
> > + 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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-11-15 8:02 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-13 8:09 [PATCH] ocfs2: replace deprecated simple_strtol with kstrtol Daniel Yang
2024-11-15 1:05 ` Joseph Qi
2024-11-15 8:01 ` Daniel Yang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox