Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1596124 > unrolled thread

[PATCH] staging: lustre: replace simple_strtoul with kstrtoint

Started byMarcin Ciupak <marcin.s.ciupak@gmail.com>
First post2017-03-09 16:00 +0100
Last post2017-03-12 17:00 +0100
Articles 3 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] staging: lustre: replace simple_strtoul with kstrtoint Marcin Ciupak <marcin.s.ciupak@gmail.com> - 2017-03-09 16:00 +0100
    Re: [PATCH] staging: lustre: replace simple_strtoul with kstrtoint Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-03-12 14:40 +0100
      Re: [PATCH] staging: lustre: replace simple_strtoul with kstrtoint Marcin Ciupak <marcin.s.ciupak@gmail.com> - 2017-03-12 17:00 +0100

#1596124 — [PATCH] staging: lustre: replace simple_strtoul with kstrtoint

FromMarcin Ciupak <marcin.s.ciupak@gmail.com>
Date2017-03-09 16:00 +0100
Subject[PATCH] staging: lustre: replace simple_strtoul with kstrtoint
Message-ID<tj7HQ-6AN-5@gated-at.bofh.it>
Replace simple_strtoul with kstrtoint.
simple_strtoul is marked for obsoletion.

Signed-off-by: Marcin Ciupak <marcin.s.ciupak@gmail.com>
---
 drivers/staging/lustre/lustre/obdclass/obd_mount.c | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/lustre/lustre/obdclass/obd_mount.c b/drivers/staging/lustre/lustre/obdclass/obd_mount.c
index 8e0d4b1d86dc..4a604e9b3e49 100644
--- a/drivers/staging/lustre/lustre/obdclass/obd_mount.c
+++ b/drivers/staging/lustre/lustre/obdclass/obd_mount.c
@@ -924,12 +924,24 @@ static int lmd_parse(char *options, struct lustre_mount_data *lmd)
 			lmd->lmd_flags |= LMD_FLG_ABORT_RECOV;
 			clear++;
 		} else if (strncmp(s1, "recovery_time_soft=", 19) == 0) {
-			lmd->lmd_recovery_time_soft = max_t(int,
-				simple_strtoul(s1 + 19, NULL, 10), time_min);
+			int res;
+
+			rc = kstrtoint(s1 + 19, 10, &res);
+			if (rc)
+				lmd->lmd_recovery_time_soft = time_min;
+			else
+				lmd->lmd_recovery_time_soft = max_t(int, res,
+								    time_min);
 			clear++;
 		} else if (strncmp(s1, "recovery_time_hard=", 19) == 0) {
-			lmd->lmd_recovery_time_hard = max_t(int,
-				simple_strtoul(s1 + 19, NULL, 10), time_min);
+			int res;
+
+			rc = kstrtoint(s1 + 19, 10, &res);
+			if (rc)
+				lmd->lmd_recovery_time_hard = time_min;
+			else
+				lmd->lmd_recovery_time_hard = max_t(int, res,
+								    time_min);
 			clear++;
 		} else if (strncmp(s1, "noir", 4) == 0) {
 			lmd->lmd_flags |= LMD_FLG_NOIR; /* test purpose only. */
-- 
2.11.1

[toc] | [next] | [standalone]


#1598614

FromGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Date2017-03-12 14:40 +0100
Message-ID<tkbT3-294-1@gated-at.bofh.it>
In reply to#1596124
On Thu, Mar 09, 2017 at 03:53:00PM +0100, Marcin Ciupak wrote:
> Replace simple_strtoul with kstrtoint.

Why?

> simple_strtoul is marked for obsoletion.
> 
> Signed-off-by: Marcin Ciupak <marcin.s.ciupak@gmail.com>
> ---
>  drivers/staging/lustre/lustre/obdclass/obd_mount.c | 20 ++++++++++++++++----
>  1 file changed, 16 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/staging/lustre/lustre/obdclass/obd_mount.c b/drivers/staging/lustre/lustre/obdclass/obd_mount.c
> index 8e0d4b1d86dc..4a604e9b3e49 100644
> --- a/drivers/staging/lustre/lustre/obdclass/obd_mount.c
> +++ b/drivers/staging/lustre/lustre/obdclass/obd_mount.c
> @@ -924,12 +924,24 @@ static int lmd_parse(char *options, struct lustre_mount_data *lmd)
>  			lmd->lmd_flags |= LMD_FLG_ABORT_RECOV;
>  			clear++;
>  		} else if (strncmp(s1, "recovery_time_soft=", 19) == 0) {
> -			lmd->lmd_recovery_time_soft = max_t(int,
> -				simple_strtoul(s1 + 19, NULL, 10), time_min);
> +			int res;
> +
> +			rc = kstrtoint(s1 + 19, 10, &res);
> +			if (rc)
> +				lmd->lmd_recovery_time_soft = time_min;
> +			else
> +				lmd->lmd_recovery_time_soft = max_t(int, res,
> +								    time_min);

Are you sure this is correct?  Do you really want to use max_t()?  Why
is time_min used if there is an error?  Can't this all be written a lot
simpler to actually make it semi-sane?

thanks,

greg k-h

[toc] | [prev] | [next] | [standalone]


#1598665

FromMarcin Ciupak <marcin.s.ciupak@gmail.com>
Date2017-03-12 17:00 +0100
Message-ID<tke4y-3AZ-5@gated-at.bofh.it>
In reply to#1598614
On Sun, Mar 12, 2017 at 02:36:47PM +0100, Greg Kroah-Hartman wrote:
> On Thu, Mar 09, 2017 at 03:53:00PM +0100, Marcin Ciupak wrote:
> > Replace simple_strtoul with kstrtoint.
> 
> Why?
Because  
> > simple_strtoul is marked for obsoletion.
as reported by checkpatch.pl.
> > 
> > Signed-off-by: Marcin Ciupak <marcin.s.ciupak@gmail.com>
> > ---
> >  drivers/staging/lustre/lustre/obdclass/obd_mount.c | 20 ++++++++++++++++----
> >  1 file changed, 16 insertions(+), 4 deletions(-)
> > 
> > diff --git a/drivers/staging/lustre/lustre/obdclass/obd_mount.c b/drivers/staging/lustre/lustre/obdclass/obd_mount.c
> > index 8e0d4b1d86dc..4a604e9b3e49 100644
> > --- a/drivers/staging/lustre/lustre/obdclass/obd_mount.c
> > +++ b/drivers/staging/lustre/lustre/obdclass/obd_mount.c
> > @@ -924,12 +924,24 @@ static int lmd_parse(char *options, struct lustre_mount_data *lmd)
> >  			lmd->lmd_flags |= LMD_FLG_ABORT_RECOV;
> >  			clear++;
> >  		} else if (strncmp(s1, "recovery_time_soft=", 19) == 0) {
> > -			lmd->lmd_recovery_time_soft = max_t(int,
> > -				simple_strtoul(s1 + 19, NULL, 10), time_min);
> > +			int res;
> > +
> > +			rc = kstrtoint(s1 + 19, 10, &res);
> > +			if (rc)
> > +				lmd->lmd_recovery_time_soft = time_min;
> > +			else
> > +				lmd->lmd_recovery_time_soft = max_t(int, res,
> > +								    time_min);
> 
> Are you sure this is correct?  Do you really want to use max_t()?  Why
> is time_min used if there is an error?  Can't this all be written a lot
> simpler to actually make it semi-sane?
> 
> thanks,
> 
> greg k-h

max_t() and time_min were already used in the original code, I did not want to change
that.

Regarding error handling, I saw two options here:
1. update variable with some fail-safe value and time_min looked good
for that or,
2. do not update anything and do nothing or "goto invalid:" but I was not sure
about that, so selected first option.

If first option is not the best one, what would be better in case of error handling?

Thanks,
Marcin

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web