DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH] net/iavf: fix memory leak in flow subscription
@ 2022-10-08  6:34 Jie Wang
  2022-10-09  5:32 ` Zhang, Qi Z
  0 siblings, 1 reply; 2+ messages in thread
From: Jie Wang @ 2022-10-08  6:34 UTC (permalink / raw)
  To: dev
  Cc: stevex.yang, qi.z.zhang, qiming.yang, jingjing.wu, beilei.xing, Jie Wang

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* RE: [PATCH] net/iavf: fix memory leak in flow subscription
  2022-10-08  6:34 [PATCH] net/iavf: fix memory leak in flow subscription Jie Wang
@ 2022-10-09  5:32 ` Zhang, Qi Z
  0 siblings, 0 replies; 2+ messages in thread
From: Zhang, Qi Z @ 2022-10-09  5:32 UTC (permalink / raw)
  To: Wang, Jie1X, dev; +Cc: Yang, SteveX, Yang, Qiming, Wu, Jingjing, Xing, Beilei



> -----Original Message-----
> From: Wang, Jie1X <jie1x.wang@intel.com>
> Sent: Saturday, October 8, 2022 2:34 PM
> To: dev@dpdk.org
> Cc: Yang, SteveX <stevex.yang@intel.com>; Zhang, Qi Z
> <qi.z.zhang@intel.com>; Yang, Qiming <qiming.yang@intel.com>; Wu,
> Jingjing <jingjing.wu@intel.com>; Xing, Beilei <beilei.xing@intel.com>; Wang,
> Jie1X <jie1x.wang@intel.com>
> Subject: [PATCH] net/iavf: fix memory leak in flow subscription
> 
> 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>

Acked-by: Qi Zhang <qi.z.zhang@intel.com>

Applied to dpdk-next-net-intel.

Thanks
Qi



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-10-09  5:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-08  6:34 [PATCH] net/iavf: fix memory leak in flow subscription Jie Wang
2022-10-09  5:32 ` Zhang, Qi Z

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).