> -----Original Message-----
> From: Liu, Mingxia <mingxia....@intel.com>
> Sent: Friday, April 21, 2023 3:15 PM
> To: dev@dpdk.org
> Cc: Wu, Jingjing <jingjing...@intel.com>; Xing, Beilei 
> <beilei.x...@intel.com>; Liu, Mingxia
> <mingxia....@intel.com>
> Subject: [PATCH] net/idpf: refine devargs parse functions
> 
> This patch refines devargs parsing functions and use valid
> variable max_vport_nb to replace IDPF_MAX_VPORT_NUM.
> 
> Signed-off-by: Mingxia Liu <mingxia....@intel.com>
> ---
>  drivers/net/idpf/idpf_ethdev.c | 61 +++++++++++++++++-----------------
>  1 file changed, 30 insertions(+), 31 deletions(-)
> 
> diff --git a/drivers/net/idpf/idpf_ethdev.c b/drivers/net/idpf/idpf_ethdev.c
> index e02ec2ec5a..a8dd5a0a80 100644
> --- a/drivers/net/idpf/idpf_ethdev.c
> +++ b/drivers/net/idpf/idpf_ethdev.c
> @@ -857,12 +857,6 @@ insert_value(struct idpf_devargs *devargs, uint16_t id)
>                       return 0;
>       }
> 
> -     if (devargs->req_vport_nb >= RTE_DIM(devargs->req_vports)) {
> -             PMD_INIT_LOG(ERR, "Total vport number can't be > %d",
> -                          IDPF_MAX_VPORT_NUM);
> -             return -EINVAL;
> -     }
> -
>       devargs->req_vports[devargs->req_vport_nb] = id;
>       devargs->req_vport_nb++;
> 
> @@ -879,12 +873,10 @@ parse_range(const char *value, struct idpf_devargs 
> *devargs)
> 
>       result = sscanf(value, "%hu%n-%hu%n", &lo, &n, &hi, &n);
>       if (result == 1) {
> -             if (lo >= IDPF_MAX_VPORT_NUM)
> -                     return NULL;
>               if (insert_value(devargs, lo) != 0)
>                       return NULL;
>       } else if (result == 2) {
> -             if (lo > hi || hi >= IDPF_MAX_VPORT_NUM)
> +             if (lo > hi)
>                       return NULL;
>               for (i = lo; i <= hi; i++) {
>                       if (insert_value(devargs, i) != 0)
> @@ -969,40 +961,46 @@ idpf_parse_devargs(struct rte_pci_device *pci_dev, 
> struct
> idpf_adapter_ext *adap
>               return -EINVAL;
>       }
> 
> +     ret = rte_kvargs_process(kvlist, IDPF_VPORT, &parse_vport,
> +                              idpf_args);
> +     if (ret != 0)
> +             goto fail;
> +
> +     ret = rte_kvargs_process(kvlist, IDPF_TX_SINGLE_Q, &parse_bool,
> +                              &adapter->base.is_tx_singleq);
> +     if (ret != 0)
> +             goto fail;
> +
> +     ret = rte_kvargs_process(kvlist, IDPF_RX_SINGLE_Q, &parse_bool,
> +                              &adapter->base.is_rx_singleq);
> +     if (ret != 0)
> +             goto fail;
> +
>       /* check parsed devargs */
>       if (adapter->cur_vport_nb + idpf_args->req_vport_nb >
> -         IDPF_MAX_VPORT_NUM) {
> +         adapter->max_vport_nb) {
>               PMD_INIT_LOG(ERR, "Total vport number can't be > %d",
> -                          IDPF_MAX_VPORT_NUM);
> +                          adapter->max_vport_nb);
>               ret = -EINVAL;
> -             goto bail;
> +             goto fail;
>       }
> 
>       for (i = 0; i < idpf_args->req_vport_nb; i++) {
> +             if (idpf_args->req_vports[i] > adapter->max_vport_nb - 1) {
> +                     PMD_INIT_LOG(ERR, "Invalid vport id %d, it should be 0 
> ~ %d",
> +                                  idpf_args->req_vports[i], 
> adapter->max_vport_nb - 1);
> +                     ret = -EINVAL;
This verify is not necessary, because we don't limit the vport id specified in 
args need to be less than the number it supports.

Reply via email to