[dpdk-dev] [PATCH] bus/dpaa: optimize device name parsing

David Marchand david.marchand at redhat.com
Mon Nov 9 12:58:13 CET 2020


On Mon, Nov 9, 2020 at 12:32 PM Gaetan Rivet <grive at u256.net> wrote:
> +       delta = 0;
> +       if (strncmp(name, "dpaa_bus:", 9) == 0) {
> +               delta = 9;
> +       } else if (strncmp(name, "name=", 5) == 0) {
> +               delta = 5;
> +       }
> +
> +       if (sscanf(&name[delta], "fm%u-mac%u", &i, &j) == 2) {
> +               if (i >= 2 || j >= 16)
> +                       return -EINVAL;
> +               if (out != NULL) {
> +                       char *out_name = out;
> +
> +                       if (rte_strscpy(out_name, &name[delta], 10) < 0)
> +                               return -ENAMETOOLONG;
> +                       /* Because 'i' can only be 0 or 1, fm%u is fixed size ;
> +                        * mac%u needs to be checked for optional end ','.
> +                        */
> +                       if (out_name[9] == ',')
> +                               out_name[9] = '\0';
>                 }
> +               return 0;
> +       } else {
> +               return -EINVAL;
>         }

Mmm, we always return from each of the previous branches?
Then the ENODEV return after is dead code.

Reading again the diff, you could probably return at the sscanf step.
if (sscanf(&name[delta], "fm%u-mac%u", &i, &j) != 2 || i >= 2 || j >= 16)
        return -EINVAL;


>
> -       free(dup_name);
> -       return -EINVAL;
> +       return -ENODEV;
>  }
>
>  #define DPAA_DEV_PATH1 "/sys/devices/platform/soc/soc:fsl,dpaa"


-- 
David Marchand



More information about the dev mailing list