Skip to contentSkip to conversation

net/softnic: fix mixing enum values

PATCH Superseded Jasvinder Singh 2 participants 3 messages Oct 31, 2018 – Nov 2, 2018 Network drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net/softnic: fix mixing enum values

Fix mixing enum types enum rte_table_action_policer and enum rte_mtr_policer_action for dereference of policer action.

Coverity issue 323483, 323511

Fixes 7e30e444c3e4 ("net/softnic: support flow meter action")
Fixes 8a917ef88db7 ("net/softnic: update policer actions")
---
 drivers/net/softnic/rte_eth_softnic_flow.c    |  6 ++---
 .../net/softnic/rte_eth_softnic_internals.h   |  3 +++
 drivers/net/softnic/rte_eth_softnic_meter.c   | 23 ++++++++++++++++++-
 3 files changed, 28 insertions(+), 4 deletions(-)
drivers/net/softnic/rte_eth_softnic_flow.c +3 -3
index 285af462b..b4aaa0696 100644
@@ -1624,11 +1624,11 @@ flow_rule_action_get(struct pmd_internals *softnic,
 			/* RTE_TABLE_ACTION_METER */
 			rule_action->mtr.mtr[0].meter_profile_id = meter_profile_id;
 			rule_action->mtr.mtr[0].policer[e_RTE_METER_GREEN] =
-				(enum rte_table_action_policer)m->params.action[RTE_MTR_GREEN];
+				softnic_table_action_policer(m->params.action[RTE_MTR_GREEN]);
 			rule_action->mtr.mtr[0].policer[e_RTE_METER_YELLOW] =
-				(enum rte_table_action_policer)m->params.action[RTE_MTR_YELLOW];
+				softnic_table_action_policer(m->params.action[RTE_MTR_YELLOW]);
 			rule_action->mtr.mtr[0].policer[e_RTE_METER_RED] =
-				(enum rte_table_action_policer)m->params.action[RTE_MTR_RED];
+				softnic_table_action_policer(m->params.action[RTE_MTR_RED]);
 			rule_action->mtr.tc_mask = 1;
 			rule_action->action_mask |= 1 << RTE_TABLE_ACTION_MTR;
 			break;
drivers/net/softnic/rte_eth_softnic_internals.h +3 -0
index e12b8ae4c..31698b9f0 100644
@@ -828,6 +828,9 @@ softnic_table_action_profile_create(struct pmd_internals *p,
 	const char *name,
 	struct softnic_table_action_profile_params *params);
 
+enum rte_table_action_policer
+softnic_table_action_policer(enum rte_mtr_policer_action action);
+
 /**
  * Pipeline
  */
drivers/net/softnic/rte_eth_softnic_meter.c +22 -1
index 73ecf3b16..f9ae74882 100644
@@ -65,6 +65,27 @@ softnic_mtr_meter_profile_find(struct pmd_internals *p,
 	return NULL;
 }
 
+enum rte_table_action_policer
+softnic_table_action_policer(enum rte_mtr_policer_action action)
+{
+	switch(action) {
+	case MTR_POLICER_ACTION_COLOR_GREEN:
+		return RTE_TABLE_ACTION_POLICER_COLOR_GREEN;
+
+		/* FALLTHROUGH */
+	case MTR_POLICER_ACTION_COLOR_YELLOW:
+		return RTE_TABLE_ACTION_POLICER_COLOR_YELLOW;
+
+		/* FALLTHROUGH */
+	case MTR_POLICER_ACTION_COLOR_RED:
+		return RTE_TABLE_ACTION_POLICER_COLOR_RED;
+
+		/* FALLTHROUGH */
+	default:
+		return RTE_TABLE_ACTION_POLICER_DROP;
+	}
+}
+
 static int
 meter_profile_check(struct rte_eth_dev *dev,
 	uint32_t meter_profile_id,
@@ -542,7 +563,7 @@ pmd_mtr_policer_actions_update(struct rte_eth_dev *dev,
 		for (i = 0; i < RTE_MTR_COLORS; i++)
 			if (action_mask & (1 << i))
 				action.mtr.mtr[0].policer[i] =
-					(enum rte_table_action_policer)actions[i];
+					softnic_table_action_policer(actions[i]);
 
 		/* Re-add the rule */
 		status = softnic_pipeline_table_rule_add(p,
Signature · 1 line
2.17.1
#1 lore raw

PATCH v2 1/1 net/softnic: fix mixing enum values

Fix mixing enum types enum rte_table_action_policer and enum rte_mtr_policer_action for dereference of policer action.

Coverity issue 323483, 323511

Fixes 7e30e444c3e4 ("net/softnic: support flow meter action")
Fixes 8a917ef88db7 ("net/softnic: update policer actions")

---
v2
- fix checkpatch error

 drivers/net/softnic/rte_eth_softnic_flow.c    |  6 ++---
 .../net/softnic/rte_eth_softnic_internals.h   |  3 +++
 drivers/net/softnic/rte_eth_softnic_meter.c   | 23 ++++++++++++++++++-
 3 files changed, 28 insertions(+), 4 deletions(-)
drivers/net/softnic/rte_eth_softnic_flow.c +3 -3
index 285af462b..b4aaa0696 100644
@@ -1624,11 +1624,11 @@ flow_rule_action_get(struct pmd_internals *softnic,
 			/* RTE_TABLE_ACTION_METER */
 			rule_action->mtr.mtr[0].meter_profile_id = meter_profile_id;
 			rule_action->mtr.mtr[0].policer[e_RTE_METER_GREEN] =
-				(enum rte_table_action_policer)m->params.action[RTE_MTR_GREEN];
+				softnic_table_action_policer(m->params.action[RTE_MTR_GREEN]);
 			rule_action->mtr.mtr[0].policer[e_RTE_METER_YELLOW] =
-				(enum rte_table_action_policer)m->params.action[RTE_MTR_YELLOW];
+				softnic_table_action_policer(m->params.action[RTE_MTR_YELLOW]);
 			rule_action->mtr.mtr[0].policer[e_RTE_METER_RED] =
-				(enum rte_table_action_policer)m->params.action[RTE_MTR_RED];
+				softnic_table_action_policer(m->params.action[RTE_MTR_RED]);
 			rule_action->mtr.tc_mask = 1;
 			rule_action->action_mask |= 1 << RTE_TABLE_ACTION_MTR;
 			break;
drivers/net/softnic/rte_eth_softnic_internals.h +3 -0
index e12b8ae4c..31698b9f0 100644
@@ -828,6 +828,9 @@ softnic_table_action_profile_create(struct pmd_internals *p,
 	const char *name,
 	struct softnic_table_action_profile_params *params);
 
+enum rte_table_action_policer
+softnic_table_action_policer(enum rte_mtr_policer_action action);
+
 /**
  * Pipeline
  */
drivers/net/softnic/rte_eth_softnic_meter.c +22 -1
index 73ecf3b16..7b747ba5d 100644
@@ -65,6 +65,27 @@ softnic_mtr_meter_profile_find(struct pmd_internals *p,
 	return NULL;
 }
 
+enum rte_table_action_policer
+softnic_table_action_policer(enum rte_mtr_policer_action action)
+{
+	switch (action) {
+	case MTR_POLICER_ACTION_COLOR_GREEN:
+		return RTE_TABLE_ACTION_POLICER_COLOR_GREEN;
+
+		/* FALLTHROUGH */
+	case MTR_POLICER_ACTION_COLOR_YELLOW:
+		return RTE_TABLE_ACTION_POLICER_COLOR_YELLOW;
+
+		/* FALLTHROUGH */
+	case MTR_POLICER_ACTION_COLOR_RED:
+		return RTE_TABLE_ACTION_POLICER_COLOR_RED;
+
+		/* FALLTHROUGH */
+	default:
+		return RTE_TABLE_ACTION_POLICER_DROP;
+	}
+}
+
 static int
 meter_profile_check(struct rte_eth_dev *dev,
 	uint32_t meter_profile_id,
@@ -542,7 +563,7 @@ pmd_mtr_policer_actions_update(struct rte_eth_dev *dev,
 		for (i = 0; i < RTE_MTR_COLORS; i++)
 			if (action_mask & (1 << i))
 				action.mtr.mtr[0].policer[i] =
-					(enum rte_table_action_policer)actions[i];
+					softnic_table_action_policer(actions[i]);
 
 		/* Re-add the rule */
 		status = softnic_pipeline_table_rule_add(p,
Signature · 1 line
2.17.1
Acked-by on v2 1/1 Applied
#2 lore raw
Quoted 13 lines

-----Original Message-----
From: Singh, Jasvinder
Sent: Wednesday, October 31, 2018 11:58 AM
To: [email protected]
Cc: Dumitrescu, Cristian <[email protected]>
Subject: [PATCH v2] net/softnic: fix mixing enum values

Fix mixing enum types enum rte_table_action_policer and enum rte_mtr_policer_action for dereference of policer action.

Quoted 6 lines

Coverity issue 323483, 323511

Fixes 7e30e444c3e4 ("net/softnic: support flow meter action")
Fixes 8a917ef88db7 ("net/softnic: update policer actions")

---

Applied to next-pipeline tree, thanks!