[PATCH v2 03/13] ethdev: extract codes parsing port ID as a function
Ferruh Yigit
ferruh.yigit at amd.com
Wed Jun 7 13:37:52 CEST 2023
On 6/7/2023 8:41 AM, Jie Hai wrote:
> This patch extracts codes parsing port_id as a function.
> The port id of 'int' or 'unsigned long' type passing as
> 'uint16_t' may cause truncation, fix it.
>
> Signed-off-by: Jie Hai <haijie1 at huawei.com>
> ---
> lib/ethdev/rte_ethdev_telemetry.c | 95 ++++++++++++++++---------------
> lib/ethdev/sff_telemetry.c | 4 +-
> 2 files changed, 52 insertions(+), 47 deletions(-)
>
> diff --git a/lib/ethdev/rte_ethdev_telemetry.c b/lib/ethdev/rte_ethdev_telemetry.c
> index ec8e48877187..5e70d0c2a66a 100644
> --- a/lib/ethdev/rte_ethdev_telemetry.c
> +++ b/lib/ethdev/rte_ethdev_telemetry.c
> @@ -11,6 +11,29 @@
> #include "ethdev_driver.h"
> #include "sff_telemetry.h"
>
> +static int
> +eth_dev_parse_port_params(const char *params __rte_unused, uint16_t *port_id,
> + char **end_param, bool has_next)
>
'__rte_unused' is not required for 'params'
> +{
> + uint64_t pi;
> +
> + if (params == NULL || strlen(params) == 0 ||
> + !isdigit(*params) || port_id == NULL)
> + return -EINVAL;
> +
> + pi = strtoul(params, end_param, 0);
> + if (**end_param != '\0' && !has_next)
> + RTE_ETHDEV_LOG(NOTICE,
> + "Extra parameters passed to ethdev telemetry command, ignoring\n");
> +
> + if (pi >= UINT16_MAX || !rte_eth_dev_is_valid_port(pi))
> + return -EINVAL;
> +
> + *port_id = pi;
>
there is 64 -> 16 bit conversion, there is a "pi >= UINT16_MAX" check
already but not sure if all compilers get it, better to add explicit
cast for any case.
More information about the dev
mailing list