DPDK patches and discussions
 help / color / mirror / Atom feed
From: Jie Wang <jie1x.wang@intel.com>
To: dev@dpdk.org
Cc: stevex.yang@intel.com, qi.z.zhang@intel.com,
	qiming.yang@intel.com, jingjing.wu@intel.com,
	beilei.xing@intel.com, Jie Wang <jie1x.wang@intel.com>
Subject: [PATCH] net/iavf: fix memory leak in flow subscription
Date: Sat,  8 Oct 2022 14:34:01 +0800	[thread overview]
Message-ID: <20221008063401.10060-1-jie1x.wang@intel.com> (raw)

When creating flow subscription pattern that it might cause a
memory leak.

This patch fix the error by adding a free memory code.

And some typos have also been fixed.

Coverity issue: 381130
Fixes: b110b2f63e50 ("net/iavf: add flow subscrption supported pattern")
Fixes: 6416f63aae8b ("net/iavf: support flow subscription rule")

Signed-off-by: Jie Wang <jie1x.wang@intel.com>
---
 drivers/net/iavf/iavf_fsub.c  | 22 ++++++++++++----------
 drivers/net/iavf/iavf_vchnl.c | 16 ++++++++++------
 2 files changed, 22 insertions(+), 16 deletions(-)

diff --git a/drivers/net/iavf/iavf_fsub.c b/drivers/net/iavf/iavf_fsub.c
index 3bb6c30d3c..3be75923a5 100644
--- a/drivers/net/iavf/iavf_fsub.c
+++ b/drivers/net/iavf/iavf_fsub.c
@@ -21,7 +21,6 @@
 #include <iavf.h>
 #include "iavf_generic_flow.h"
 
-
 #define MAX_QGRP_NUM_TYPE      7
 #define IAVF_IPV6_ADDR_LENGTH  16
 #define MAX_INPUT_SET_BYTE     32
@@ -95,6 +94,7 @@ iavf_fsub_create(struct iavf_adapter *ad, struct rte_flow *flow,
 	rte_memcpy(rule, filter, sizeof(*rule));
 	flow->rule = rule;
 
+	rte_free(meta);
 	return ret;
 
 free_entry:
@@ -414,7 +414,7 @@ iavf_fsub_parse_pattern(const struct rte_flow_item pattern[],
 
 			VIRTCHNL_SET_PROTO_HDR_TYPE(hdr, S_VLAN);
 
-			if (vlan_spec && vlan_spec) {
+			if (vlan_spec && vlan_mask) {
 				input = &outer_input_set;
 
 				*input |= IAVF_INSET_VLAN_OUTER;
@@ -578,7 +578,7 @@ iavf_fsub_parse_action(struct iavf_adapter *ad,
 
 error1:
 	rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION, actions,
-			   "Invalid ethdev_port_id");
+			   "Invalid port id");
 	return -rte_errno;
 
 error2:
@@ -662,14 +662,16 @@ iavf_fsub_parse(struct iavf_adapter *ad,
 		rte_flow_error_set(error, EINVAL,
 				   RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
 				   "No memory for iavf_fsub_conf_ptr");
-		goto error;
+		return -ENOMEM;
 	}
 
 	/* search flow subscribe pattern */
 	pattern_match_item = iavf_search_pattern_match_item(pattern, array,
 							    array_len, error);
-	if (!pattern_match_item)
-		return -rte_errno;
+	if (!pattern_match_item) {
+		ret = -rte_errno;
+		goto error;
+	}
 
 	/* parse flow subscribe pattern */
 	ret = iavf_fsub_parse_pattern(pattern,
@@ -686,13 +688,13 @@ iavf_fsub_parse(struct iavf_adapter *ad,
 	/* parse flow subscribe pattern action */
 	ret = iavf_fsub_parse_action((void *)ad, actions, priority,
 				     error, filter);
-	if (ret)
-		goto error;
 
-	if (meta)
+error:
+	if (!ret && meta)
 		*meta = filter;
+	else
+		rte_free(filter);
 
-error:
 	rte_free(pattern_match_item);
 	return ret;
 }
diff --git a/drivers/net/iavf/iavf_vchnl.c b/drivers/net/iavf/iavf_vchnl.c
index cc0db8d093..30567ea6e9 100644
--- a/drivers/net/iavf/iavf_vchnl.c
+++ b/drivers/net/iavf/iavf_vchnl.c
@@ -1524,14 +1524,14 @@ iavf_fdir_check(struct iavf_adapter *adapter,
 		PMD_DRV_LOG(ERR,
 			"Failed to check rule request due to parameters validation"
 			" or HW doesn't support");
-		return -1;
+		err = -1;
 	} else {
 		PMD_DRV_LOG(ERR,
 			"Failed to check rule request due to other reasons");
-		return -1;
+		err =  -1;
 	}
 
-	return 0;
+	return err;
 }
 
 int
@@ -1553,9 +1553,11 @@ iavf_flow_sub(struct iavf_adapter *adapter, struct iavf_fsub_conf *filter)
 	args.out_size = IAVF_AQ_BUF_SZ;
 
 	err = iavf_execute_vf_cmd(adapter, &args, 0);
-	if (err)
+	if (err) {
 		PMD_DRV_LOG(ERR, "Failed to execute command of "
 				 "OP_FLOW_SUBSCRIBE");
+		return err;
+	}
 
 	fsub_cfg = (struct virtchnl_flow_sub *)args.out_buffer;
 	filter->flow_id = fsub_cfg->flow_id;
@@ -1602,9 +1604,11 @@ iavf_flow_unsub(struct iavf_adapter *adapter, struct iavf_fsub_conf *filter)
 	args.out_size = IAVF_AQ_BUF_SZ;
 
 	err = iavf_execute_vf_cmd(adapter, &args, 0);
-	if (err)
+	if (err) {
 		PMD_DRV_LOG(ERR, "Failed to execute command of "
 				 "OP_FLOW_UNSUBSCRIBE");
+		return err;
+	}
 
 	unsub_cfg = (struct virtchnl_flow_unsub *)args.out_buffer;
 
@@ -1644,7 +1648,7 @@ iavf_flow_sub_check(struct iavf_adapter *adapter,
 
 	err = iavf_execute_vf_cmd(adapter, &args, 0);
 	if (err) {
-		PMD_DRV_LOG(ERR, "fail to check flow director rule");
+		PMD_DRV_LOG(ERR, "Failed to check flow subscription rule");
 		return err;
 	}
 
-- 
2.25.1


             reply	other threads:[~2022-10-08  6:35 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-08  6:34 Jie Wang [this message]
2022-10-09  5:32 ` Zhang, Qi Z

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=20221008063401.10060-1-jie1x.wang@intel.com \
    --to=jie1x.wang@intel.com \
    --cc=beilei.xing@intel.com \
    --cc=dev@dpdk.org \
    --cc=jingjing.wu@intel.com \
    --cc=qi.z.zhang@intel.com \
    --cc=qiming.yang@intel.com \
    --cc=stevex.yang@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).