From dc36bd5dfdeb0ec9cee7a6140d7ed14734776756 Mon Sep 17 00:00:00 2001 From: Tao Zhu Date: Thu, 16 Jan 2020 16:38:36 +0000 Subject: [PATCH] net/ice: fix flow FDIR/switch memory leak 1. Fix ice FDIR and hash flow memory leak. 2. Fix the ice definition of LIST_FOR_EACH_ENTRY_SAFE not save tmp which cause list deletion incompletely. Fixes: 5f0978e96220 ("net/ice/base: add OS specific implementation") Fixes: f5cafa961fae ("net/ice: add flow director create and destroy") Fixes: 5ad3db8d4bdd ("net/ice: enable advanced RSS") Cc: stable@dpdk.org Signed-off-by: Tao Zhu Reviewed-by: Simei Su Reviewed-by: Yahui Cao Acked-by: Xiaolong Ye --- drivers/net/ice/base/ice_osdep.h | 17 +++++++++++++++-- drivers/net/ice/ice_fdir_filter.c | 12 +++++++----- drivers/net/ice/ice_hash.c | 12 ++++++------ 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/drivers/net/ice/base/ice_osdep.h b/drivers/net/ice/base/ice_osdep.h index 45b9f36177..a4a2994c76 100644 --- a/drivers/net/ice/base/ice_osdep.h +++ b/drivers/net/ice/base/ice_osdep.h @@ -345,6 +345,21 @@ static inline void list_add_tail(struct ice_list_entry *entry, member) : \ 0) +#define LIST_FOR_EACH_ENTRY_SAFE(pos, tmp, head, type, member) \ + for ((pos) = (head)->lh_first ? \ + container_of((head)->lh_first, struct type, member) : \ + 0, \ + (tmp) = (pos) == 0 ? 0 : ((pos)->member.next.le_next ? \ + container_of((pos)->member.next.le_next, struct type, \ + member) : \ + 0); \ + (pos); \ + (pos) = (tmp), \ + (tmp) = (pos) == 0 ? 0 : ((tmp)->member.next.le_next ? \ + container_of((pos)->member.next.le_next, struct type, \ + member) : \ + 0)) + #define LIST_REPLACE_INIT(list_head, head) do { \ (head)->lh_first = (list_head)->lh_first; \ INIT_LIST_HEAD(list_head); \ @@ -358,8 +373,6 @@ static inline void list_add_tail(struct ice_list_entry *entry, #define HLIST_DEL(entry) LIST_DEL(entry) #define HLIST_FOR_EACH_ENTRY(pos, head, type, member) \ LIST_FOR_EACH_ENTRY(pos, head, type, member) -#define LIST_FOR_EACH_ENTRY_SAFE(pos, tmp, head, type, member) \ - LIST_FOR_EACH_ENTRY(pos, head, type, member) #ifndef ICE_DBG_TRACE #define ICE_DBG_TRACE BIT_ULL(0) diff --git a/drivers/net/ice/ice_fdir_filter.c b/drivers/net/ice/ice_fdir_filter.c index 42b9628630..68af2f2e25 100644 --- a/drivers/net/ice/ice_fdir_filter.c +++ b/drivers/net/ice/ice_fdir_filter.c @@ -1939,23 +1939,25 @@ ice_fdir_parse(struct ice_adapter *ad, ret = ice_fdir_parse_pattern(ad, pattern, error, filter); if (ret) - return ret; + goto error; input_set = filter->input_set; if (!input_set || input_set & ~item->input_set_mask) { rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ITEM_SPEC, pattern, "Invalid input set"); - return -rte_errno; + ret = -rte_errno; + goto error; } ret = ice_fdir_parse_action(ad, actions, error, filter); if (ret) - return ret; + goto error; *meta = filter; - - return 0; +error: + rte_free(item); + return ret; } static struct ice_flow_parser ice_fdir_parser_os = { diff --git a/drivers/net/ice/ice_hash.c b/drivers/net/ice/ice_hash.c index b145a3f0d5..d891538bd4 100644 --- a/drivers/net/ice/ice_hash.c +++ b/drivers/net/ice/ice_hash.c @@ -409,7 +409,7 @@ ice_hash_parse_pattern_action(__rte_unused struct ice_adapter *ad, void **meta, struct rte_flow_error *error) { - int ret = 0; + int ret = -rte_errno; struct ice_pattern_match_item *pattern_match_item; struct rss_meta *rss_meta_ptr; @@ -425,11 +425,11 @@ ice_hash_parse_pattern_action(__rte_unused struct ice_adapter *ad, pattern_match_item = ice_search_pattern_match_item(pattern, array, array_len, error); if (!pattern_match_item) - return -rte_errno; + goto error; ret = ice_hash_check_inset(pattern, error); if (ret) - return -rte_errno; + goto error; /* Save protocol header to rss_meta. */ *meta = rss_meta_ptr; @@ -438,12 +438,12 @@ ice_hash_parse_pattern_action(__rte_unused struct ice_adapter *ad, /* Check rss action. */ ret = ice_hash_parse_action(pattern_match_item, actions, meta, error); +error: if (ret) - return -rte_errno; - + rte_free(rss_meta_ptr); rte_free(pattern_match_item); - return 0; + return ret; } static int -- 2.20.1