Skip to contentSkip to conversation

staging: lustre: Replace sscanf with kstrtoint

PATCH Superseded Cristina Moraru 4 participants 7 messages Oct 18, 2015 – Oct 26, 2015 Staging

lore
Share & tools
lore
#0 lore raw

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
index c3be0b5..725bcf6 100644
@@ -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
#1 lore raw
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'

---
 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
index c3be0b5..725bcf6 100644

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

#2 lore raw

PATCH v2 1/1 staging: lustre: Replace sscanf with kstrtoint

In reply to 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'

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
index c3be0b5..55b8a91 100644
@@ -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
#3 lore raw
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'

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
index c3be0b5..55b8a91 100644

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.
#4 lore raw

PATCH v3 1/1 staging: lustre: Replace sscanf with kstrtoint

In reply to 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'

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
index c3be0b5..220a919 100644
@@ -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
maintainer
#5 lore raw
Quoted 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'

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

#6 lore raw

PATCH v3 1/1 staging: lustre: Replace sscanf with kstrtoint

In reply to 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'

---
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
index c3be0b5..220a919 100644
@@ -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