[PATCH] staging: lustre: Replace sscanf with kstrtoint

Daniel Baluta daniel.baluta at gmail.com
Sun Oct 18 12:51:22 EEST 2015


On Sun, Oct 18, 2015 at 2:00 AM, Cristina Moraru
<cristina.moraru09 at 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 at gmail.com>
> ---
>  drivers/staging/lustre/lustre/lov/lov_obd.c | 6 ++++--
>  1 file changed, 4 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..59445fc 100644
> --- a/drivers/staging/lustre/lustre/lov/lov_obd.c
> +++ b/drivers/staging/lustre/lustre/lov/lov_obd.c
> @@ -914,11 +914,13 @@ 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) ||
> +                               *indexp != 1) {

The initial sscan() != 1, checked to see if 1 element was correctly converted.

Now, indexp holds the result of conversion. I think checking *indexp
!= 1 is wrong.

You should check only the result returned by kstrtoint, thus use
something like this

rc = kstrtoint();

if (rc)
    goto out;

Like here: http://marc.info/?l=linux-mm&m=139284808601343&w=2

thanks,
Daniel.


>                         rc = -EINVAL;
>                         goto out;
>                 }
> -               if (sscanf(lustre_cfg_buf(lcfg, 3), "%d", genp) != 1) {
> +               if (kstrtoint(lustre_cfg_buf(lcfg, 3), 10, genp) ||
> +                               *genp != 1) {
>                         rc = -EINVAL;
>                         goto out;
>                 }
> --
> 1.9.1
>


More information about the firefly mailing list