On Tue, Nov 24, 2020 at 1:33 PM Ibtisam Tariq <ibtisam.ta...@emumba.com> wrote:
>
> Instead of using getopt_long return value, strcmp was used to
> compare the input parameters with the struct option array. This
> patch get rid of all those strcmp by directly binding each longopt
> with an int enum. This is to improve readability and consistency in
> all examples.
>
> Bugzilla ID: 238
> Cc: marko.kovace...@intel.com
>
> Reported-by: David Marchand <david.march...@redhat.com>
> Signed-off-by: Ibtisam Tariq <ibtisam.ta...@emumba.com>
> ---
> v3:
> * None.

We lost the version prefix in the patch title, please do not forget it
in the next revision.

[snip]

> diff --git a/examples/fips_validation/main.c b/examples/fips_validation/main.c
> index cad6bcb18..36ed4b546 100644
> --- a/examples/fips_validation/main.c
> +++ b/examples/fips_validation/main.c
> @@ -15,17 +15,26 @@
>  #include "fips_validation.h"
>  #include "fips_dev_self_test.h"
>
> -#define REQ_FILE_PATH_KEYWORD  "req-file"
> -#define RSP_FILE_PATH_KEYWORD  "rsp-file"
> -#define MBUF_DATAROOM_KEYWORD  "mbuf-dataroom"
> -#define FOLDER_KEYWORD         "path-is-folder"
> -#define CRYPTODEV_KEYWORD      "cryptodev"
> -#define CRYPTODEV_ID_KEYWORD   "cryptodev-id"
> -#define CRYPTODEV_ST_KEYWORD   "self-test"
> -#define CRYPTODEV_BK_ID_KEYWORD        "broken-test-id"
> -#define CRYPTODEV_BK_DIR_KEY   "broken-test-dir"
> -#define CRYPTODEV_ENC_KEYWORD  "enc"
> -#define CRYPTODEV_DEC_KEYWORD  "dec"
> +enum {
> +#define OPT_REQ_FILE_PATH      "req-file"
> +       OPT_REQ_FILE_PATH_NUM = 256,
> +#define OPT_RSP_FILE_PATH      "rsp-file"
> +       OPT_RSP_FILE_PATH_NUM,
> +#define OPT_MBUF_DATAROOM      "mbuf-dataroom"
> +       OPT_MBUF_DATAROOM_NUM,
> +#define OPT_FOLDER                 "path-is-folder"
> +       OPT_FOLDER_NUM,
> +#define OPT_CRYPTODEV      "cryptodev"
> +       OPT_CRYPTODEV_NUM,

Nit: could you realign those two strings?

> +#define OPT_CRYPTODEV_ID       "cryptodev-id"
> +       OPT_CRYPTODEV_ID_NUM,
> +#define OPT_CRYPTODEV_ST       "self-test"
> +       OPT_CRYPTODEV_ST_NUM,
> +#define OPT_CRYPTODEV_BK_ID    "broken-test-id"
> +       OPT_CRYPTODEV_BK_ID_NUM,
> +#define OPT_CRYPTODEV_BK_DIR_KEY       "broken-test-dir"
> +       OPT_CRYPTODEV_BK_DIR_KEY_NUM,
> +};

[snip]

> @@ -248,108 +266,113 @@ cryptodev_fips_validate_parse_args(int argc, char 
> **argv)
>                 return -EINVAL;
>         }
>
> -       while ((opt = getopt_long(argc, argvopt, "s:",
> +       while ((opt = getopt_long(argc, argvopt, "",

Passing "s:" was a bug (since nothing was done with it).
But this was not an issue requiring a separate fix + backport from my pov.
Let's at least mention it in the commitlog.


>                                   lgopts, &option_index)) != EOF) {
>
> +               if (opt == '?') {
> +                       cryptodev_fips_validate_usage(prgname);
> +                       return -1;
> +               }

Why a separate check here?
The default: block below will handle an unknown option fine.

> +
>                 switch (opt) {

[snip]


> +
>                 default:
> -                       return -1;
> +                       cryptodev_fips_validate_usage(prgname);
> +                       return -EINVAL;
>                 }
>         }
>


-- 
David Marchand

Reply via email to