On 10/1/2026 6:40 AM, Stephen Hemminger wrote:
> The lcore argument is converted with atoi(), which validates nothing:
> a malformed value such as "abc" becomes zero, and the range check that
> follows only catches a value which happens to land outside it.
> 
> Use rte_kvargs_to_int() with the lcore range, and log the key and the
> range when it does not fit.
> 
> The parsing function returns void and probe does not fail on a bad
> argument, which is left alone here: an unusable lcore still falls back
> to the default. Only the "Parse lcore_id" message is now skipped when
> the conversion failed, since it reported a value which had not been
> parsed at all.
> 
> Signed-off-by: Stephen Hemminger <[email protected]>
> ---
>  drivers/dma/skeleton/skeleton_dmadev.c | 23 ++++++++++++++---------
>  1 file changed, 14 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/dma/skeleton/skeleton_dmadev.c 
> b/drivers/dma/skeleton/skeleton_dmadev.c
> index e287802eb9..44158d5a7f 100644
> --- a/drivers/dma/skeleton/skeleton_dmadev.c
> +++ b/drivers/dma/skeleton/skeleton_dmadev.c
> @@ -638,19 +638,24 @@ skeldma_destroy(const char *name)
>  }
>  
>  static int
> -skeldma_parse_lcore(const char *key __rte_unused,
> +skeldma_parse_lcore(const char *key,
>                   const char *value,
>                   void *opaque)
>  {
> -     int lcore_id;
> +     int64_t lcore_id;
> +     int ret;
>  
> -     if (value == NULL || opaque == NULL)
> +     if (opaque == NULL)
>               return -EINVAL;
>  
> -     lcore_id = atoi(value);
> -     if (lcore_id >= 0 && lcore_id < RTE_MAX_LCORE)
> -             *(int *)opaque = lcore_id;
> +     ret = rte_kvargs_to_int(value, 0, RTE_MAX_LCORE - 1, &lcore_id);
> +     if (ret < 0) {

Why not if (ret != 0) ?

Thanks

> +             SKELDMA_LOG(ERR, "Invalid %s, must be 0..%u", key,
> +                         RTE_MAX_LCORE - 1);
> +             return ret;
> +     }
>  
> +     *(int *)opaque = lcore_id;
>       return 0;
>  }
>  
> @@ -673,9 +678,9 @@ skeldma_parse_vdev_args(struct rte_vdev_device *vdev, int 
> *lcore_id)
>       if (!kvlist)
>               return;
>  
> -     (void)rte_kvargs_process(kvlist, SKELDMA_ARG_LCORE,
> -                              skeldma_parse_lcore, lcore_id);
> -     SKELDMA_LOG(INFO, "Parse lcore_id = %d", *lcore_id);
> +     if (rte_kvargs_process(kvlist, SKELDMA_ARG_LCORE,
> +                            skeldma_parse_lcore, lcore_id) == 0)
> +             SKELDMA_LOG(INFO, "Parse lcore_id = %d", *lcore_id);
>  
>       rte_kvargs_free(kvlist);
>  }

Reply via email to