diff mbox series

[6/7] net/dpaa2: add input validation

Message ID 20210719135917.26241-7-hemant.agrawal@nxp.com
State New
Headers show
Series NXP DPAAx fixes and improvements | expand

Commit Message

Hemant Agrawal July 19, 2021, 1:59 p.m. UTC
From: Vanshika Shukla <vanshika.shukla@nxp.com>


This patch adds validation of the port id for
rte_pmd_dpaa2_set_custom_hash API to check if the
port is a valid DPAA2 port. Also handles some
edge cases in the rte_pmd_dpaa2_mux_flow_create API.

Signed-off-by: Vanshika Shukla <vanshika.shukla@nxp.com>

Acked-by: Hemant Agrawal <hemant.agrawal@nxp.com>

---
 drivers/net/dpaa2/base/dpaa2_hw_dpni.c | 11 +++++++++++
 drivers/net/dpaa2/dpaa2_ethdev.c       |  4 ++--
 drivers/net/dpaa2/dpaa2_ethdev.h       |  1 +
 drivers/net/dpaa2/dpaa2_mux.c          |  3 +++
 4 files changed, 17 insertions(+), 2 deletions(-)

-- 
2.17.1
diff mbox series

Patch

diff --git a/drivers/net/dpaa2/base/dpaa2_hw_dpni.c b/drivers/net/dpaa2/base/dpaa2_hw_dpni.c
index b901b4342f..641e7027f1 100644
--- a/drivers/net/dpaa2/base/dpaa2_hw_dpni.c
+++ b/drivers/net/dpaa2/base/dpaa2_hw_dpni.c
@@ -41,6 +41,17 @@  rte_pmd_dpaa2_set_custom_hash(uint16_t port_id,
 	void *p_params;
 	int ret, tc_index = 0;
 
+	if (!rte_eth_dev_is_valid_port(port_id)) {
+		DPAA2_PMD_WARN("Invalid port id %u", port_id);
+		return -EINVAL;
+	}
+
+	if (strcmp(eth_dev->device->driver->name,
+			RTE_STR(NET_DPAA2_PMD_DRIVER_NAME))) {
+		DPAA2_PMD_WARN("Not a valid dpaa2 port");
+		return -EINVAL;
+	}
+
 	p_params = rte_zmalloc(
 		NULL, DIST_PARAM_IOVA_SIZE, RTE_CACHE_LINE_SIZE);
 	if (!p_params) {
diff --git a/drivers/net/dpaa2/dpaa2_ethdev.c b/drivers/net/dpaa2/dpaa2_ethdev.c
index d892819a7e..c12169578e 100644
--- a/drivers/net/dpaa2/dpaa2_ethdev.c
+++ b/drivers/net/dpaa2/dpaa2_ethdev.c
@@ -2905,8 +2905,8 @@  static struct rte_dpaa2_driver rte_dpaa2_pmd = {
 	.remove = rte_dpaa2_remove,
 };
 
-RTE_PMD_REGISTER_DPAA2(net_dpaa2, rte_dpaa2_pmd);
-RTE_PMD_REGISTER_PARAM_STRING(net_dpaa2,
+RTE_PMD_REGISTER_DPAA2(NET_DPAA2_PMD_DRIVER_NAME, rte_dpaa2_pmd);
+RTE_PMD_REGISTER_PARAM_STRING(NET_DPAA2_PMD_DRIVER_NAME,
 		DRIVER_LOOPBACK_MODE "=<int> "
 		DRIVER_NO_PREFETCH_MODE "=<int>"
 		DRIVER_TX_CONF "=<int>"
diff --git a/drivers/net/dpaa2/dpaa2_ethdev.h b/drivers/net/dpaa2/dpaa2_ethdev.h
index 7b76ca7b2d..b9c729f6cd 100644
--- a/drivers/net/dpaa2/dpaa2_ethdev.h
+++ b/drivers/net/dpaa2/dpaa2_ethdev.h
@@ -19,6 +19,7 @@ 
 
 #define DPAA2_MIN_RX_BUF_SIZE 512
 #define DPAA2_MAX_RX_PKT_LEN  10240 /*WRIOP support*/
+#define NET_DPAA2_PMD_DRIVER_NAME net_dpaa2
 
 #define MAX_TCS			DPNI_MAX_TC
 #define MAX_RX_QUEUES		128
diff --git a/drivers/net/dpaa2/dpaa2_mux.c b/drivers/net/dpaa2/dpaa2_mux.c
index 811f417491..d347f4df51 100644
--- a/drivers/net/dpaa2/dpaa2_mux.c
+++ b/drivers/net/dpaa2/dpaa2_mux.c
@@ -68,6 +68,9 @@  rte_pmd_dpaa2_mux_flow_create(uint32_t dpdmux_id,
 	int ret;
 	static int i;
 
+	if (!pattern || !actions || !pattern[0] || !actions[0])
+		return NULL;
+
 	/* Find the DPDMUX from dpdmux_id in our list */
 	dpdmux_dev = get_dpdmux_from_id(dpdmux_id);
 	if (!dpdmux_dev) {