DPDK patches and discussions
 help / color / mirror / Atom feed
From: Jasvinder Singh <jasvinder.singh@intel.com>
To: dev@dpdk.org
Cc: ferruh.yigit@intel.com, jingjing.wu@intel.com,
	bernard.iremonger@intel.com
Subject: [dpdk-dev] [PATCH v2] testpmd: fix memory alloc for dscp table
Date: Mon,  5 Nov 2018 16:26:54 +0000	[thread overview]
Message-ID: <20181105162654.31505-1-jasvinder.singh@intel.com> (raw)
In-Reply-To: <20181105162202.31346-1-jasvinder.singh@intel.com>

The patch fixes the memory allocation for the meter dscp table.

Fixes: e63b50162aa3 ("app/testpmd: clean metering and policing commands")

Signed-off-by: Jasvinder Singh <jasvinder.singh@intel.com>
---
v2
- fix checkpatch errors

 app/test-pmd/cmdline_mtr.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/app/test-pmd/cmdline_mtr.c b/app/test-pmd/cmdline_mtr.c
index 63f32828f..846de88db 100644
--- a/app/test-pmd/cmdline_mtr.c
+++ b/app/test-pmd/cmdline_mtr.c
@@ -74,7 +74,7 @@ parse_uint(uint64_t *value, const char *str)
 }
 
 static int
-parse_dscp_table_entries(char *str, enum rte_mtr_color *dscp_table)
+parse_dscp_table_entries(char *str, enum rte_mtr_color **dscp_table)
 {
 	char *token;
 	int i = 0;
@@ -84,23 +84,23 @@ parse_dscp_table_entries(char *str, enum rte_mtr_color *dscp_table)
 		return 0;
 
 	/* Allocate memory for dscp table */
-	dscp_table = (enum rte_mtr_color *)malloc(MAX_DSCP_TABLE_ENTRIES *
+	*dscp_table = (enum rte_mtr_color *)malloc(MAX_DSCP_TABLE_ENTRIES *
 		sizeof(enum rte_mtr_color));
-	if (dscp_table == NULL)
+	if (*dscp_table == NULL)
 		return -1;
 
 	while (1) {
 		if (strcmp(token, "G") == 0 ||
 			strcmp(token, "g") == 0)
-			dscp_table[i++] = RTE_MTR_GREEN;
+			*dscp_table[i++] = RTE_MTR_GREEN;
 		else if (strcmp(token, "Y") == 0 ||
 			strcmp(token, "y") == 0)
-			dscp_table[i++] = RTE_MTR_YELLOW;
+			*dscp_table[i++] = RTE_MTR_YELLOW;
 		else if (strcmp(token, "R") == 0 ||
 			strcmp(token, "r") == 0)
-			dscp_table[i++] = RTE_MTR_RED;
+			*dscp_table[i++] = RTE_MTR_RED;
 		else {
-			free(dscp_table);
+			free(*dscp_table);
 			return -1;
 		}
 		if (i == MAX_DSCP_TABLE_ENTRIES)
@@ -108,7 +108,7 @@ parse_dscp_table_entries(char *str, enum rte_mtr_color *dscp_table)
 
 		token = strtok_r(str, PARSE_DELIMITER, &str);
 		if (token == NULL) {
-			free(dscp_table);
+			free(*dscp_table);
 			return -1;
 		}
 	}
@@ -117,7 +117,7 @@ parse_dscp_table_entries(char *str, enum rte_mtr_color *dscp_table)
 
 static int
 parse_meter_color_str(char *c_str, uint32_t *use_prev_meter_color,
-	enum rte_mtr_color *dscp_table)
+	enum rte_mtr_color **dscp_table)
 {
 	char *token;
 	uint64_t previous_mtr_color = 0;
@@ -195,7 +195,7 @@ parse_policer_action_string(char *p_str, uint32_t action_mask,
 
 static int
 parse_multi_token_string(char *t_str, uint16_t *port_id,
-	uint32_t *mtr_id, enum rte_mtr_color *dscp_table)
+	uint32_t *mtr_id, enum rte_mtr_color **dscp_table)
 {
 	char *token;
 	uint64_t val;
@@ -794,7 +794,7 @@ static void cmd_create_port_meter_parsed(void *parsed_result,
 	params.meter_profile_id = res->profile_id;
 
 	/* Parse meter input color string params */
-	ret = parse_meter_color_str(c_str, &use_prev_meter_color, dscp_table);
+	ret = parse_meter_color_str(c_str, &use_prev_meter_color, &dscp_table);
 	if (ret) {
 		printf(" Meter input color params string parse error\n");
 		return;
@@ -1141,7 +1141,7 @@ static void cmd_set_port_meter_dscp_table_parsed(void *parsed_result,
 	int ret;
 
 	/* Parse string */
-	ret = parse_multi_token_string(t_str, &port_id, &mtr_id, dscp_table);
+	ret = parse_multi_token_string(t_str, &port_id, &mtr_id, &dscp_table);
 	if (ret) {
 		printf(" Multi token string parse error\n");
 		return;
-- 
2.17.1

  reply	other threads:[~2018-11-05 16:26 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-05 16:22 [dpdk-dev] [PATCH] app/testpmd: " Jasvinder Singh
2018-11-05 16:26 ` Jasvinder Singh [this message]
2018-11-05 19:26   ` [dpdk-dev] [PATCH v2] testpmd: " Ferruh Yigit
2018-11-06 10:26   ` [dpdk-dev] [PATCH v3] app/testpmd: " Jasvinder Singh
2018-11-12 16:43     ` Dumitrescu, Cristian

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181105162654.31505-1-jasvinder.singh@intel.com \
    --to=jasvinder.singh@intel.com \
    --cc=bernard.iremonger@intel.com \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@intel.com \
    --cc=jingjing.wu@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).