net/iavf: fix memory leak in flow subscription
PATCH 1/1 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
--- drivers/net/iavf/iavf_fsub.c | 22 ++++++++++++---------- drivers/net/iavf/iavf_vchnl.c | 16 ++++++++++------ 2 files changed, 22 insertions(+), 16 deletions(-)
drivers/net/iavf/iavf_fsub.c +12 -10
@@ -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; }
drivers/net/iavf/iavf_vchnl.c +10 -6
@@ -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; }
Signature · 1 line
2.25.1
Quoted 16 lines
-----Original Message-----
From: Wang, Jie1X <[email protected]>
Sent: Saturday, October 8, 2022 2:34 PM
To: [email protected]
Cc: Yang, SteveX <[email protected]>; Zhang, Qi Z <[email protected]>; Yang, Qiming <[email protected]>; Wu, Jingjing <[email protected]>; Xing, Beilei <[email protected]>; Wang, Jie1X <[email protected]>
Subject: [PATCH] net/iavf: fix memory leak in flow subscriptionWhen creating flow subscription pattern that it might cause a memory leak.
This patch fix the error by adding a free memory code.
Quoted 7 lines
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 <[email protected]>
Applied to dpdk-next-net-intel.
Thanks
Qi