From e53562d7abbce63943351f35f906c6e2fe2a0acc Mon Sep 17 00:00:00 2001 From: Karra Satwik Date: Thu, 24 Dec 2020 16:48:49 +0530 Subject: [PATCH] app/testpmd: allocate FEC capability array dynamically Request the driver for number of entries in the FEC caps array and then dynamically allocate the array. Signed-off-by: Karra Satwik Signed-off-by: Rahul Lakkireddy Acked-by: Xiaoyun Li Acked-by: Min Hu (Connor) Reviewed-by: Ferruh Yigit --- app/test-pmd/cmdline.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c index 596dd239fe..855dbc2dec 100644 --- a/app/test-pmd/cmdline.c +++ b/app/test-pmd/cmdline.c @@ -16266,11 +16266,9 @@ cmd_show_fec_capability_parsed(void *parsed_result, __rte_unused struct cmdline *cl, __rte_unused void *data) { -#define FEC_CAP_NUM 2 struct cmd_show_fec_capability_result *res = parsed_result; - struct rte_eth_fec_capa speed_fec_capa[FEC_CAP_NUM]; - unsigned int num = FEC_CAP_NUM; - unsigned int ret_num; + struct rte_eth_fec_capa *speed_fec_capa; + unsigned int num; int ret; if (!rte_eth_dev_is_valid_port(res->cmd_pid)) { @@ -16278,17 +16276,31 @@ cmd_show_fec_capability_parsed(void *parsed_result, return; } - ret = rte_eth_fec_get_capability(res->cmd_pid, speed_fec_capa, num); + ret = rte_eth_fec_get_capability(res->cmd_pid, NULL, 0); if (ret == -ENOTSUP) { printf("Function not implemented\n"); return; } else if (ret < 0) { - printf("Get FEC capability failed\n"); + printf("Get FEC capability failed: %d\n", ret); + return; + } + + num = (unsigned int)ret; + speed_fec_capa = calloc(num, sizeof(*speed_fec_capa)); + if (speed_fec_capa == NULL) { + printf("Failed to alloc FEC capability buffer\n"); return; } - ret_num = (unsigned int)ret; - show_fec_capability(ret_num, speed_fec_capa); + ret = rte_eth_fec_get_capability(res->cmd_pid, speed_fec_capa, num); + if (ret < 0) { + printf("Error getting FEC capability: %d\n", ret); + goto out; + } + + show_fec_capability(num, speed_fec_capa); +out: + free(speed_fec_capa); } cmdline_parse_token_string_t cmd_show_fec_capability_show = -- 2.20.1