* Re: [Outreachy kernel] [PATCH] staging: lustre: Replace sscanf with kstrtoint
2015-10-18 13:02 [PATCH] staging: lustre: Replace sscanf with kstrtoint Cristina Moraru
@ 2015-10-18 16:51 ` Daniel Baluta
2015-10-18 21:41 ` [PATCH v2] " Cristina Moraru
` (2 subsequent siblings)
3 siblings, 0 replies; 7+ messages in thread
From: Daniel Baluta @ 2015-10-18 16:51 UTC (permalink / raw)
To: Cristina Moraru; +Cc: outreachy-kernel
On Sun, Oct 18, 2015 at 4:02 PM, Cristina Moraru
<cristina.moraru09@gmail.com> wrote:
> 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 <cristina.moraru09@gmail.com>
> ---
> drivers/staging/lustre/lustre/lov/lov_obd.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/staging/lustre/lustre/lov/lov_obd.c b/drivers/staging/lustre/lustre/lov/lov_obd.c
> index c3be0b5..725bcf6 100644
> --- a/drivers/staging/lustre/lustre/lov/lov_obd.c
> +++ b/drivers/staging/lustre/lustre/lov/lov_obd.c
> @@ -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;
> - 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
^ permalink raw reply [flat|nested] 7+ messages in thread* [PATCH v2] staging: lustre: Replace sscanf with kstrtoint
2015-10-18 13:02 [PATCH] staging: lustre: Replace sscanf with kstrtoint Cristina Moraru
2015-10-18 16:51 ` [Outreachy kernel] " Daniel Baluta
@ 2015-10-18 21:41 ` Cristina Moraru
2015-10-19 5:26 ` [Outreachy kernel] " Julia Lawall
2015-10-19 20:48 ` [PATCH v3] " Cristina Moraru
2015-10-26 22:30 ` Cristina Moraru
3 siblings, 1 reply; 7+ messages in thread
From: Cristina Moraru @ 2015-10-18 21:41 UTC (permalink / raw)
To: outreachy-kernel; +Cc: 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 <cristina.moraru09@gmail.com>
Changes in v2:
- Change error code handling.
---
drivers/staging/lustre/lustre/lov/lov_obd.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/staging/lustre/lustre/lov/lov_obd.c b/drivers/staging/lustre/lustre/lov/lov_obd.c
index c3be0b5..55b8a91 100644
--- a/drivers/staging/lustre/lustre/lov/lov_obd.c
+++ b/drivers/staging/lustre/lustre/lov/lov_obd.c
@@ -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;
--
1.9.1
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [Outreachy kernel] [PATCH v2] staging: lustre: Replace sscanf with kstrtoint
2015-10-18 21:41 ` [PATCH v2] " Cristina Moraru
@ 2015-10-19 5:26 ` Julia Lawall
0 siblings, 0 replies; 7+ messages in thread
From: Julia Lawall @ 2015-10-19 5:26 UTC (permalink / raw)
To: Cristina Moraru; +Cc: outreachy-kernel
On Mon, 19 Oct 2015, Cristina Moraru wrote:
> 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 <cristina.moraru09@gmail.com>
>
> Changes in v2:
> - Change error code handling.
> ---
> drivers/staging/lustre/lustre/lov/lov_obd.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/staging/lustre/lustre/lov/lov_obd.c b/drivers/staging/lustre/lustre/lov/lov_obd.c
> index c3be0b5..55b8a91 100644
> --- a/drivers/staging/lustre/lustre/lov/lov_obd.c
> +++ b/drivers/staging/lustre/lustre/lov/lov_obd.c
> @@ -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
> - 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;
> --
> 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 outreachy-kernel+unsubscribe@googlegroups.com.
> To post to this group, send email to outreachy-kernel@googlegroups.com.
> 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.
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v3] staging: lustre: Replace sscanf with kstrtoint
2015-10-18 13:02 [PATCH] staging: lustre: Replace sscanf with kstrtoint Cristina Moraru
2015-10-18 16:51 ` [Outreachy kernel] " Daniel Baluta
2015-10-18 21:41 ` [PATCH v2] " Cristina Moraru
@ 2015-10-19 20:48 ` Cristina Moraru
2015-10-25 1:40 ` [Outreachy kernel] " Greg KH
2015-10-26 22:30 ` Cristina Moraru
3 siblings, 1 reply; 7+ messages in thread
From: Cristina Moraru @ 2015-10-19 20:48 UTC (permalink / raw)
To: outreachy-kernel; +Cc: 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 <cristina.moraru09@gmail.com>
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(-)
diff --git a/drivers/staging/lustre/lustre/lov/lov_obd.c b/drivers/staging/lustre/lustre/lov/lov_obd.c
index c3be0b5..220a919 100644
--- a/drivers/staging/lustre/lustre/lov/lov_obd.c
+++ b/drivers/staging/lustre/lustre/lov/lov_obd.c
@@ -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)
--
1.9.1
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [Outreachy kernel] [PATCH v3] staging: lustre: Replace sscanf with kstrtoint
2015-10-19 20:48 ` [PATCH v3] " Cristina Moraru
@ 2015-10-25 1:40 ` Greg KH
0 siblings, 0 replies; 7+ messages in thread
From: Greg KH @ 2015-10-25 1:40 UTC (permalink / raw)
To: Cristina Moraru; +Cc: outreachy-kernel
On Mon, Oct 19, 2015 at 11:48:53PM +0300, Cristina Moraru wrote:
> 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 <cristina.moraru09@gmail.com>
>
> 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
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v3] staging: lustre: Replace sscanf with kstrtoint
2015-10-18 13:02 [PATCH] staging: lustre: Replace sscanf with kstrtoint Cristina Moraru
` (2 preceding siblings ...)
2015-10-19 20:48 ` [PATCH v3] " Cristina Moraru
@ 2015-10-26 22:30 ` Cristina Moraru
3 siblings, 0 replies; 7+ messages in thread
From: Cristina Moraru @ 2015-10-26 22:30 UTC (permalink / raw)
To: outreachy-kernel; +Cc: 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 <cristina.moraru09@gmail.com>
---
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(-)
diff --git a/drivers/staging/lustre/lustre/lov/lov_obd.c b/drivers/staging/lustre/lustre/lov/lov_obd.c
index c3be0b5..220a919 100644
--- a/drivers/staging/lustre/lustre/lov/lov_obd.c
+++ b/drivers/staging/lustre/lustre/lov/lov_obd.c
@@ -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)
--
1.9.1
^ permalink raw reply related [flat|nested] 7+ messages in thread