Skip to contentSkip to conversation

net/ice: remove unnecessary variable

PATCH Superseded Qi Zhang 2 participants 3 messages Feb 25, 2020 – Mar 2, 2020 Network drivers

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Qi Zhang

author
#0 lore raw

PATCH 1/1 net/ice: remove unnecessary variable

Remove unnecessary variable "meta" in ice_flow_create and ice_flow_validate, it should be defined when really be needed:
its ice_parse_engine_create and ice_parse_engine_validate.

The patch also move the meta's memory free from each filter engine->create to upper layer, the memory leakage when create a fdir rule is also be fixed.

Fixes f5cafa961fae ("net/ice: add flow director create and destroy")
---
 drivers/net/ice/ice_generic_flow.c  | 28 ++++++++++++++--------------
 drivers/net/ice/ice_hash.c          |  2 --
 drivers/net/ice/ice_switch_filter.c |  3 ---
 3 files changed, 14 insertions(+), 19 deletions(-)
drivers/net/ice/ice_generic_flow.c +14 -14
index 38ac799d8..f22538758 100644
@@ -1375,7 +1375,6 @@ typedef struct ice_flow_engine * (*parse_engine_t)(struct ice_adapter *ad,
 		struct ice_parser_list *parser_list,
 		const struct rte_flow_item pattern[],
 		const struct rte_flow_action actions[],
-		void **meta,
 		struct rte_flow_error *error);
 
 void
@@ -1713,11 +1712,11 @@ ice_parse_engine_create(struct ice_adapter *ad,
 		struct ice_parser_list *parser_list,
 		const struct rte_flow_item pattern[],
 		const struct rte_flow_action actions[],
-		void **meta,
 		struct rte_flow_error *error)
 {
 	struct ice_flow_engine *engine = NULL;
 	struct ice_flow_parser_node *parser_node;
+	void *meta = NULL;
 	void *temp;
 
 	TAILQ_FOREACH_SAFE(parser_node, parser_list, node, temp) {
@@ -1726,7 +1725,7 @@ ice_parse_engine_create(struct ice_adapter *ad,
 		if (parser_node->parser->parse_pattern_action(ad,
 				parser_node->parser->array,
 				parser_node->parser->array_len,
-				pattern, actions, meta, error) < 0)
+				pattern, actions, &meta, error) < 0)
 			continue;
 
 		engine = parser_node->parser->engine;
@@ -1737,7 +1736,9 @@ ice_parse_engine_create(struct ice_adapter *ad,
 			continue;
 		}
 
-		ret = engine->create(ad, flow, *meta, error);
+		ret = engine->create(ad, flow, meta, error);
+		if (meta)
+			rte_free(meta);
 		if (ret == 0)
 			return engine;
 		else if (ret == -EEXIST)
@@ -1752,23 +1753,25 @@ ice_parse_engine_validate(struct ice_adapter *ad,
 		struct ice_parser_list *parser_list,
 		const struct rte_flow_item pattern[],
 		const struct rte_flow_action actions[],
-		void **meta,
 		struct rte_flow_error *error)
 {
 	struct ice_flow_engine *engine = NULL;
 	struct ice_flow_parser_node *parser_node;
+	void *meta = NULL;
 	void *temp;
 
 	TAILQ_FOREACH_SAFE(parser_node, parser_list, node, temp) {
 		if (parser_node->parser->parse_pattern_action(ad,
 				parser_node->parser->array,
 				parser_node->parser->array_len,
-				pattern, actions, meta, error) < 0)
+				pattern, actions, &meta, error) < 0)
 			continue;
 
 		engine = parser_node->parser->engine;
 		break;
 	}
+	if (meta)
+		rte_free(meta);
 	return engine;
 }
 
@@ -1779,7 +1782,6 @@ ice_flow_process_filter(struct rte_eth_dev *dev,
 		const struct rte_flow_item pattern[],
 		const struct rte_flow_action actions[],
 		struct ice_flow_engine **engine,
-		void **meta,
 		parse_engine_t ice_parse_engine,
 		struct rte_flow_error *error)
 {
@@ -1814,7 +1816,7 @@ ice_flow_process_filter(struct rte_eth_dev *dev,
 		return ret;
 
 	*engine = ice_parse_engine(ad, flow, &pf->rss_parser_list,
-			pattern, actions, meta, error);
+			pattern, actions, error);
 	if (*engine != NULL)
 		return 0;
 
@@ -1822,11 +1824,11 @@ ice_flow_process_filter(struct rte_eth_dev *dev,
 	case ICE_FLOW_CLASSIFY_STAGE_DISTRIBUTOR_ONLY:
 	case ICE_FLOW_CLASSIFY_STAGE_DISTRIBUTOR:
 		*engine = ice_parse_engine(ad, flow, &pf->dist_parser_list,
-				pattern, actions, meta, error);
+				pattern, actions, error);
 		break;
 	case ICE_FLOW_CLASSIFY_STAGE_PERMISSION:
 		*engine = ice_parse_engine(ad, flow, &pf->perm_parser_list,
-				pattern, actions, meta, error);
+				pattern, actions, error);
 		break;
 	default:
 		return -EINVAL;
@@ -1845,11 +1847,10 @@ ice_flow_validate(struct rte_eth_dev *dev,
 		const struct rte_flow_action actions[],
 		struct rte_flow_error *error)
 {
-	void *meta;
 	struct ice_flow_engine *engine;
 
 	return ice_flow_process_filter(dev, NULL, attr, pattern, actions,
-			&engine, &meta, ice_parse_engine_validate, error);
+			&engine, ice_parse_engine_validate, error);
 }
 
 static struct rte_flow *
@@ -1863,7 +1864,6 @@ ice_flow_create(struct rte_eth_dev *dev,
 	struct rte_flow *flow = NULL;
 	int ret;
 	struct ice_flow_engine *engine = NULL;
-	void *meta;
 
 	flow = rte_zmalloc("ice_flow", sizeof(struct rte_flow), 0);
 	if (!flow) {
@@ -1874,7 +1874,7 @@ ice_flow_create(struct rte_eth_dev *dev,
 	}
 
 	ret = ice_flow_process_filter(dev, flow, attr, pattern, actions,
-			&engine, &meta, ice_parse_engine_create, error);
+			&engine, ice_parse_engine_create, error);
 	if (ret < 0)
 		goto free_flow;
 	flow->engine = engine;
drivers/net/ice/ice_hash.c +0 -2
index d891538bd..fc3f33ee1 100644
@@ -503,12 +503,10 @@ ice_hash_create(struct ice_adapter *ad,
 
 out:
 	flow->rule = filter_ptr;
-	rte_free(meta);
 	return 0;
 
 error:
 	rte_free(filter_ptr);
-	rte_free(meta);
 	return -rte_errno;
 }
 
drivers/net/ice/ice_switch_filter.c +0 -3
index 4a9356b31..314a9a096 100644
@@ -249,13 +249,10 @@ ice_switch_create(struct ice_adapter *ad,
 	}
 
 	rte_free(list);
-	rte_free(meta);
 	return 0;
 
 error:
 	rte_free(list);
-	rte_free(meta);
-
 	return -rte_errno;
 }
 
Signature · 1 line
2.13.6
#1 lore raw

Hi, Qi

Quoted 5 lines · Qi Zhang

Remove unnecessary variable "meta" in ice_flow_create and ice_flow_validate, it should be defined when really be needed:
its ice_parse_engine_create and ice_parse_engine_validate.

The patch also move the meta's memory free from each filter

s/move/moves

Quoted 48 lines

engine->create to upper layer, the memory leakage when create a fdir rule is also be fixed.

Fixes f5cafa961fae ("net/ice: add flow director create and destroy")

---

drivers/net/ice/ice_generic_flow.c  | 28 ++++++++++++++--------------
drivers/net/ice/ice_hash.c          |  2 --
drivers/net/ice/ice_switch_filter.c |  3 ---
3 files changed, 14 insertions(+), 19 deletions(-)
drivers/net/ice/ice_generic_flow.c +0 -1
index 38ac799d8..f22538758 100644
@@ -1375,7 +1375,6 @@ typedef struct ice_flow_engine * (*parse_engine_t)(struct ice_adapter *ad,
 		struct ice_parser_list *parser_list,
 		const struct rte_flow_item pattern[],
 		const struct rte_flow_action actions[],
-		void **meta,
 		struct rte_flow_error *error);
 

void

drivers/net/ice/ice_generic_flow.c +2 -2
@@ -1713,11 +1712,11 @@ ice_parse_engine_create(struct ice_adapter *ad,
 		struct ice_parser_list *parser_list,
 		const struct rte_flow_item pattern[],
 		const struct rte_flow_action actions[],
-		void **meta,
 		struct rte_flow_error *error)
 {
 	struct ice_flow_engine *engine = NULL;
 	struct ice_flow_parser_node *parser_node;
+	void *meta = NULL;
 	void *temp;
 
 	TAILQ_FOREACH_SAFE(parser_node, parser_list, node, temp) {
@@ -1726,7 +1725,7 @@ ice_parse_engine_create(struct ice_adapter *ad,
 		if (parser_node->parser->parse_pattern_action(ad,
 				parser_node->parser->array,
 				parser_node->parser->array_len,
-				pattern, actions, meta, error) < 0)
+				pattern, actions, &meta, error) < 0)
 			continue;
 
 		engine = parser_node->parser->engine;

drivers/net/ice/ice_generic_flow.c ice_parse_engine_create(struct ice_adapter *ad, · line 1741

Quoted 7 lines
drivers/net/ice/ice_generic_flow.c +3 -1
@@ -1737,7 +1736,9 @@ ice_parse_engine_create(struct ice_adapter *ad,
 			continue;
 		}
 
-		ret = engine->create(ad, flow, *meta, error);
+		ret = engine->create(ad, flow, meta, error);
+		if (meta)
+			rte_free(meta);

Maybe I miss something, I see meta in fdir's parse_pattern_action is assigned as &pf->fdir.conf which is not dynamically allocated like sw_meta_ptr in switch and rss_meta_ptr in hash, is it valid to call rte_free(meta) for fdir? And theoretically, if engine->create is NULL, is there a memory leak for meta?

Thanks,
Xiaolong

#2 lore raw
Quoted 75 lines

-----Original Message-----
From: Ye, Xiaolong <[email protected]>
Sent: Monday, March 2, 2020 4:20 PM
To: Zhang, Qi Z <[email protected]>
Cc: Xing, Beilei <[email protected]>; Cao, Yahui <[email protected]>; [email protected]; [email protected]
Subject: Re: [dpdk-dev] [PATCH] net/ice: remove unnecessary variable

Hi, Qi

Quoted 5 lines · Qi Zhang

Remove unnecessary variable "meta" in ice_flow_create and ice_flow_validate, it should be defined when really be needed:
its ice_parse_engine_create and ice_parse_engine_validate.

The patch also move the meta's memory free from each filter

s/move/moves

drivers/net/ice/ice_generic_flow.c typedef struct ice_flow_engine *

Quoted 19 lines

engine->create to upper layer, the memory leakage when create a fdir rule is also be fixed.

Fixes f5cafa961fae ("net/ice: add flow director create and destroy")

---

drivers/net/ice/ice_generic_flow.c  | 28 ++++++++++++++--------------
drivers/net/ice/ice_hash.c          |  2 --
drivers/net/ice/ice_switch_filter.c |  3 ---
3 files changed, 14 insertions(+), 19 deletions(-)
drivers/net/ice/ice_generic_flow.c +0 -0
index 38ac799d8..f22538758 100644
@@ -1375,7 +1375,6 @@ typedef struct ice_flow_engine *

(*parse_engine_t)(struct ice_adapter *ad,

Quoted 10 lines
drivers/net/ice/ice_generic_flow.c +0 -1
 		struct ice_parser_list *parser_list,
 		const struct rte_flow_item pattern[],
 		const struct rte_flow_action actions[],
-		void **meta,
 		struct rte_flow_error *error);
 

void

drivers/net/ice/ice_generic_flow.c +0 -0
@@ -1713,11 +1712,11 @@ ice_parse_engine_create(struct ice_adapter *ad,
 		struct ice_parser_list *parser_list,
 		const struct rte_flow_item pattern[],

drivers/net/ice/ice_generic_flow.c ice_parse_engine_create(struct ice_adapter *ad, · line 1722

Quoted 10 lines
drivers/net/ice/ice_generic_flow.c +1 -1
 		const struct rte_flow_action actions[],
-		void **meta,
 		struct rte_flow_error *error)
 {
 	struct ice_flow_engine *engine = NULL;
 	struct ice_flow_parser_node *parser_node;
+	void *meta = NULL;
 	void *temp;
 
 	TAILQ_FOREACH_SAFE(parser_node, parser_list, node, temp) { @@

-1726,7

Quoted 13 lines

+1725,7 @@ ice_parse_engine_create(struct ice_adapter *ad,

		if (parser_node->parser->parse_pattern_action(ad,
				parser_node->parser->array,
				parser_node->parser->array_len,
drivers/net/ice/ice_generic_flow.c +1 -1
-				pattern, actions, meta, error) < 0)
+				pattern, actions, &meta, error) < 0)
			continue;

		engine = parser_node->parser->engine; @@ -1737,7 +1736,9 @@
ice_parse_engine_create(struct ice_adapter *ad,
			continue;
		}
Quoted 9 lines

drivers/net/ice/ice_generic_flow.c ice_parse_engine_create(struct ice_adapter *ad, · line 1741

Quoted 4 lines
drivers/net/ice/ice_generic_flow.c +3 -1
-		ret = engine->create(ad, flow, *meta, error);
+		ret = engine->create(ad, flow, meta, error);
+		if (meta)
+			rte_free(meta);

Maybe I miss something, I see meta in fdir's parse_pattern_action is assigned as &pf->fdir.conf which is not dynamically allocated like sw_meta_ptr in switch and rss_meta_ptr in hash, is it valid to call rte_free(meta) for fdir? And theoretically, if engine->create is NULL, is there a memory leak for meta?

Good point, meta release function could be implemented in low level engine and but should be directed by up layer, so I think the missing part is a new op like engine->meta_release.

Thanks
Qi

Quoted 3 lines

Thanks,
Xiaolong