staging: lustre: Replace sscanf with kstrtoint
PATCH 1/1 staging: lustre: Replace sscanf with kstrtoint
Replace single variable sscanf with specialized function kstrtoint at the suggestion of checkpatch.pl, to fix 'WARNING: Prefer kstrto<type> to single variable sscanf'
--- drivers/staging/lustre/lustre/lov/lov_obd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/lustre/lustre/lov/lov_obd.c +2 -2
@@ -914,11 +914,11 @@ int lov_process_config_base(struct obd_device *obd, struct lustre_cfg *lcfg,obd_str2uuid (&obd_uuid,lustre_cfg_buf (lcfg,1 )); -if (sscanf (lustre_cfg_buf (lcfg,2 ),"%d" , indexp) !=1 ) { +if (kstrtoint (lustre_cfg_buf (lcfg,2 ),10 , indexp)) { rc = -EINVAL ; goto out; } -if (sscanf (lustre_cfg_buf (lcfg,3 ),"%d" , genp) !=1 ) { +if (kstrtoint (lustre_cfg_buf (lcfg,3 ),10 , genp)) { rc = -EINVAL ; goto out; }
Signature · 1 line
1.9.1
Quoted 14 lines · Cristina Moraru
Replace single variable sscanf with specialized function kstrtoint at the suggestion of checkpatch.pl, to fix 'WARNING: Prefer kstrto<type> to single variable sscanf'
Signed-off-by Cristina Moraru <[email protected]>--- drivers/staging/lustre/lustre/lov/lov_obd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/staging/lustre/lustre/lov/lov_obd.c +0
-0
drivers/staging/lustre/lustre/lov/lov_obd.c int lov_process_config_base(struct obd_device *obd, struct lustre_cfg *lcfg, · line 920
Quoted 8 lines
drivers/staging/lustre/lustre/lov/lov_obd.c +1
-1@@ -914,11 +914,11 @@ int lov_process_config_base(struct obd_device *obd, struct lustre_cfg *lcfg,obd_str2uuid (&obd_uuid,lustre_cfg_buf (lcfg,1 )); -if (sscanf (lustre_cfg_buf (lcfg,2 ),"%d" , indexp) !=1 ) { +if (kstrtoint (lustre_cfg_buf (lcfg,2 ),10 , indexp)) { rc = -EINVAL ; goto out; }
kstrtoint can also return -ERANGE, see [1].
So, here it's better to do something like this:
rc = kstrtoint(lustre_cfg_buf(lcfg, 2), 10, indexp); if (rc < 0)
goto out;
drivers/staging/lustre/lustre/lov/lov_obd.c int lov_process_config_base(struct obd_device *obd, struct lustre_cfg *lcfg, · line 924
Quoted 5 lines
drivers/staging/lustre/lustre/lov/lov_obd.c +1
-1-if (sscanf (lustre_cfg_buf (lcfg,3 ),"%d" , genp) !=1 ) { +if (kstrtoint (lustre_cfg_buf (lcfg,3 ),10 , genp)) { rc = -EINVAL ; goto out; }
The same here.
thanks,
Daniel.
[1]https://www.kernel.org/doc/htmldocs/kernel-api/API-kstrtoint.html
PATCH v2 1/1 staging: lustre: Replace sscanf with kstrtoint
In reply to Cristina MoraruReplace single variable sscanf with specialized function kstrtoint at the suggestion of checkpatch.pl, to fix 'WARNING: Prefer kstrto<type> to single variable sscanf'
Changes in v2:
- Change error code handling.
--- drivers/staging/lustre/lustre/lov/lov_obd.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/staging/lustre/lustre/lov/lov_obd.c +4 -4
@@ -914,12 +914,12 @@ int lov_process_config_base(struct obd_device *obd, struct lustre_cfg *lcfg,obd_str2uuid (&obd_uuid,lustre_cfg_buf (lcfg,1 )); -if (sscanf (lustre_cfg_buf (lcfg,2 ),"%d" , indexp) !=1 ) { - rc = -EINVAL ; + rc =kstrtoint (lustre_cfg_buf (lcfg,2 ),10 , indexp); +if (rc <0 ) { goto out; } -if (sscanf (lustre_cfg_buf (lcfg,3 ),"%d" , genp) !=1 ) { - rc = -EINVAL ; + rc =kstrtoint (lustre_cfg_buf (lcfg,3 ),10 , genp); +if (rc <0 ) { goto out; } index = *indexp;
Signature · 1 line
1.9.1
Quoted 17 lines · Cristina Moraru
Replace single variable sscanf with specialized function kstrtoint at the suggestion of checkpatch.pl, to fix 'WARNING: Prefer kstrto<type> to single variable sscanf'
Signed-off-by Cristina Moraru <[email protected]>Changes in v2:
- Change error code handling.--- drivers/staging/lustre/lustre/lov/lov_obd.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)drivers/staging/lustre/lustre/lov/lov_obd.c +0
-0
drivers/staging/lustre/lustre/lov/lov_obd.c int lov_process_config_base(struct obd_device *obd, struct lustre_cfg *lcfg, · line 920
Quoted 9 lines
drivers/staging/lustre/lustre/lov/lov_obd.c +2
-2@@ -914,12 +914,12 @@ int lov_process_config_base(struct obd_device *obd, struct lustre_cfg *lcfg,obd_str2uuid (&obd_uuid,lustre_cfg_buf (lcfg,1 )); -if (sscanf (lustre_cfg_buf (lcfg,2 ),"%d" , indexp) !=1 ) { - rc = -EINVAL ; + rc =kstrtoint (lustre_cfg_buf (lcfg,2 ),10 , indexp); +if (rc <0 ) { goto out; }
An if branch with only one statement shouldn't have braces. Checkpatch should have complained.
julia
Quoted 17 lines
drivers/staging/lustre/lustre/lov/lov_obd.c +2
-2-if (sscanf (lustre_cfg_buf (lcfg,3 ),"%d" , genp) !=1 ) { - rc = -EINVAL ; + rc =kstrtoint (lustre_cfg_buf (lcfg,3 ),10 , genp); +if (rc <0 ) { goto out; } index = *indexp;Signature · 8 lines
1.9.1 -- You received this message because you are subscribed to the Google Groups "outreachy-kernel" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/1445204493-9563-1-git-send-email-cristina.moraru09%40gmail.com. For more options, visit https://groups.google.com/d/optout.
PATCH v3 1/1 staging: lustre: Replace sscanf with kstrtoint
In reply to Cristina MoraruReplace single variable sscanf with specialized function kstrtoint at the suggestion of checkpatch.pl, to fix 'WARNING: Prefer kstrto<type> to single variable sscanf'
Changes in v2:
- Change error code handling.
Changes in v3:
- Remove unnecessary braces
--- drivers/staging/lustre/lustre/lov/lov_obd.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/staging/lustre/lustre/lov/lov_obd.c +4 -6
@@ -914,14 +914,12 @@ int lov_process_config_base(struct obd_device *obd, struct lustre_cfg *lcfg,obd_str2uuid (&obd_uuid,lustre_cfg_buf (lcfg,1 )); -if (sscanf (lustre_cfg_buf (lcfg,2 ),"%d" , indexp) !=1 ) { - rc = -EINVAL ; + rc =kstrtoint (lustre_cfg_buf (lcfg,2 ),10 , indexp); +if (rc <0 ) goto out; - } -if (sscanf (lustre_cfg_buf (lcfg,3 ),"%d" , genp) !=1 ) { - rc = -EINVAL ; + rc =kstrtoint (lustre_cfg_buf (lcfg,3 ),10 , genp); +if (rc <0 ) goto out; - } index = *indexp; gen = *genp;if (cmd ==LCFG_LOV_ADD_OBD )
Signature · 1 line
1.9.1
Greg KH
maintainerQuoted 11 lines · Cristina Moraru
Replace single variable sscanf with specialized function kstrtoint at the suggestion of checkpatch.pl, to fix 'WARNING: Prefer kstrto<type> to single variable sscanf'
Signed-off-by Cristina Moraru <[email protected]>Changes in v2:
- Change error code handling.
Changes in v3:
- Remove unnecessary braces
---
The "Changes..." lines need to go below the --- line, otherwise git will add them to the changelog, which we don't want.
Can you fix this and resend?
thanks,
greg k-h
PATCH v3 1/1 staging: lustre: Replace sscanf with kstrtoint
In reply to Cristina MoraruReplace single variable sscanf with specialized function kstrtoint at the suggestion of checkpatch.pl, to fix 'WARNING: Prefer kstrto<type> to single variable sscanf'
---
Changes in v2:
- Change error code handling.
Changes in v3:
- Remove unnecessary braces
drivers/staging/lustre/lustre/lov/lov_obd.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/staging/lustre/lustre/lov/lov_obd.c +4 -6
@@ -914,14 +914,12 @@ int lov_process_config_base(struct obd_device *obd, struct lustre_cfg *lcfg,obd_str2uuid (&obd_uuid,lustre_cfg_buf (lcfg,1 )); -if (sscanf (lustre_cfg_buf (lcfg,2 ),"%d" , indexp) !=1 ) { - rc = -EINVAL ; + rc =kstrtoint (lustre_cfg_buf (lcfg,2 ),10 , indexp); +if (rc <0 ) goto out; - } -if (sscanf (lustre_cfg_buf (lcfg,3 ),"%d" , genp) !=1 ) { - rc = -EINVAL ; + rc =kstrtoint (lustre_cfg_buf (lcfg,3 ),10 , genp); +if (rc <0 ) goto out; - } index = *indexp; gen = *genp;if (cmd ==LCFG_LOV_ADD_OBD )
Signature · 1 line
1.9.1