app/testpmd: increase array for fetching supported FEC caps

Message ID 1608504422-29220-2-git-send-email-rahul.lakkireddy@chelsio.com (mailing list archive)
State Superseded, archived
Delegated to: Ferruh Yigit
Headers
Series app/testpmd: increase array for fetching supported FEC caps |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-testing success Testing PASS
ci/Intel-compilation success Compilation OK

Commit Message

Rahul Lakkireddy Dec. 20, 2020, 10:47 p.m. UTC
  From: Karra Satwik <kaara.satwik@chelsio.com>

Request the driver for number of entries in the FEC caps
array and then dynamically allocate the array.

Signed-off-by: Karra Satwik <kaara.satwik@chelsio.com>
Signed-off-by: Rahul Lakkireddy <rahul.lakkireddy@chelsio.com>
---
 app/test-pmd/cmdline.c | 29 ++++++++++++++++++++---------
 1 file changed, 20 insertions(+), 9 deletions(-)
  

Comments

Li, Xiaoyun Dec. 23, 2020, 6:02 a.m. UTC | #1
Hi

> -----Original Message-----
> From: dev <dev-bounces@dpdk.org> On Behalf Of Rahul Lakkireddy
> Sent: Monday, December 21, 2020 06:47
> To: dev@dpdk.org
> Cc: kaara.satwik@chelsio.com
> Subject: [dpdk-dev] [PATCH] app/testpmd: increase array for fetching supported
> FEC caps
> 
> From: Karra Satwik <kaara.satwik@chelsio.com>
> 
> Request the driver for number of entries in the FEC caps array and then
> dynamically allocate the array.
> 
> Signed-off-by: Karra Satwik <kaara.satwik@chelsio.com>
> Signed-off-by: Rahul Lakkireddy <rahul.lakkireddy@chelsio.com>
> ---
>  app/test-pmd/cmdline.c | 29 ++++++++++++++++++++---------
>  1 file changed, 20 insertions(+), 9 deletions(-)
> 
> diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c index
> 2ccbaa039..d7a90d55e 100644
> --- a/app/test-pmd/cmdline.c
> +++ b/app/test-pmd/cmdline.c
> @@ -16263,29 +16263,40 @@ 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;
> -	int ret;
> +	struct rte_eth_fec_capa *speed_fec_capa;
> +	int num, ret;
> 
>  	if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
>  		printf("Invalid port id %u\n", res->cmd_pid);
>  		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 = ret;
> +	speed_fec_capa = calloc(num, sizeof(*speed_fec_capa));
> +	if (!speed_fec_capa) {

if (speed_fec_capa == NULL) {

You can check the DPDK coding style 1.9.1. http://doc.dpdk.org/guides/contributing/coding_style.html
NULL is the preferred null pointer constant. Use NULL instead of (type *)0 or (type *)NULL, except where the compiler does not know the destination type.

Except for this minor issue, Acked-by: Xiaoyun Li <xiaoyun.li@intel.com>

> +		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.24.0
  
humin (Q) Dec. 24, 2020, 7:53 a.m. UTC | #2
在 2020/12/21 6:47, Rahul Lakkireddy 写道:
> From: Karra Satwik <kaara.satwik@chelsio.com>
> 
> Request the driver for number of entries in the FEC caps
> array and then dynamically allocate the array.
> 
> Signed-off-by: Karra Satwik <kaara.satwik@chelsio.com>
> Signed-off-by: Rahul Lakkireddy <rahul.lakkireddy@chelsio.com>
> ---
>   app/test-pmd/cmdline.c | 29 ++++++++++++++++++++---------
>   1 file changed, 20 insertions(+), 9 deletions(-)
> 
> diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
> index 2ccbaa039..d7a90d55e 100644
> --- a/app/test-pmd/cmdline.c
> +++ b/app/test-pmd/cmdline.c
> @@ -16263,29 +16263,40 @@ 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;
> -	int ret;
> +	struct rte_eth_fec_capa *speed_fec_capa;
> +	int num, ret;
>   
>   	if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
>   		printf("Invalid port id %u\n", res->cmd_pid);
>   		return;
>   	}
>   
> -	ret = rte_eth_fec_get_capability(res->cmd_pid, speed_fec_capa, num);
Hi, the type of num is "unsigned int" in rte_eth_fec_get_capability,
please keep in accordance with it.

> +	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 = ret;
> +	speed_fec_capa = calloc(num, sizeof(*speed_fec_capa));
> +	if (!speed_fec_capa) {
> +		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 =
>
  

Patch

diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
index 2ccbaa039..d7a90d55e 100644
--- a/app/test-pmd/cmdline.c
+++ b/app/test-pmd/cmdline.c
@@ -16263,29 +16263,40 @@  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;
-	int ret;
+	struct rte_eth_fec_capa *speed_fec_capa;
+	int num, ret;
 
 	if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
 		printf("Invalid port id %u\n", res->cmd_pid);
 		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 = ret;
+	speed_fec_capa = calloc(num, sizeof(*speed_fec_capa));
+	if (!speed_fec_capa) {
+		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 =