patches for DPDK stable branches
 help / color / mirror / Atom feed
* [dpdk-stable] [PATCH v9] ethdev: add sanity checks in control APIs
       [not found] <1618645179-11582-1-git-send-email-humin29@huawei.com>
@ 2021-04-21  2:36 ` Ferruh Yigit
  2021-04-21 10:48   ` Thomas Monjalon
  2021-04-21 11:28   ` Andrew Rybchenko
  0 siblings, 2 replies; 10+ messages in thread
From: Ferruh Yigit @ 2021-04-21  2:36 UTC (permalink / raw)
  To: Thomas Monjalon, Andrew Rybchenko, Gaetan Rivet,
	Stephen Hemminger, Qi Zhang, Ali Alnubani, Yuanhan Liu,
	Matan Azrad, Konstantin Ananyev, Zhiyong Yang, Adrien Mazarguil
  Cc: Ferruh Yigit, dev, Min Hu (Connor), stable, Kevin Traynor

From: "Min Hu (Connor)" <humin29@huawei.com>

This patch adds more sanity checks in control path APIs.

Fixes: 214ed1acd125 ("ethdev: add iterator to match devargs input")
Fixes: 3d98f921fbe9 ("ethdev: unify prefix for static functions and variables")
Fixes: 0366137722a0 ("ethdev: check for invalid device name")
Fixes: d948f596fee2 ("ethdev: fix port data mismatched in multiple process model")
Fixes: 5b7ba31148a8 ("ethdev: add port ownership")
Fixes: f8244c6399d9 ("ethdev: increase port id range")
Cc: stable@dpdk.org

Signed-off-by: Min Hu (Connor) <humin29@huawei.com>
Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
Reviewed-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
Acked-by: Kevin Traynor <ktraynor@redhat.com>
---

It seems I underestimated finding good log messages ;), not sure if they
are complete, please comment, we can have more versions until they are
good.

v9
* Updated more functions that were missing log messages
  - rte_eth_hairpin_get_peer_ports
  - rte_eth_tx_buffer_init
  - rte_eth_xstats_get_id_by_name
  - rte_eth_dev_set_ptypes
  - rte_eth_dev_udp_tunnel_port_add
  - rte_eth_fec_get_capability
  - rte_eth_fec_get
  - rte_eth_dev_get_reg_info

* Updated log messages

* Change order of verification for some functions to be sure
  verification order is parameter order

* Remove empty line between port_id check and ethdev assignment

* Joined some lines barely above 80 columns for code readability
---
 lib/librte_ethdev/rte_ethdev.c | 677 +++++++++++++++++++++++++--------
 lib/librte_ethdev/rte_ethdev.h |  22 +-
 2 files changed, 544 insertions(+), 155 deletions(-)

diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c
index d5adf4ff0575..9c0df59464be 100644
--- a/lib/librte_ethdev/rte_ethdev.c
+++ b/lib/librte_ethdev/rte_ethdev.c
@@ -195,6 +195,17 @@ rte_eth_iterator_init(struct rte_dev_iterator *iter, const char *devargs_str)
 	char *cls_str = NULL;
 	int str_size;
 
+	if (iter == NULL) {
+		RTE_ETHDEV_LOG(ERR, "Cannot initialize NULL iterator\n");
+		return -EINVAL;
+	}
+
+	if (devargs_str == NULL) {
+		RTE_ETHDEV_LOG(ERR,
+			"Cannot initialize iterator from NULL device description string\n");
+		return -EINVAL;
+	}
+
 	memset(iter, 0, sizeof(*iter));
 	memset(&devargs, 0, sizeof(devargs));
 
@@ -289,6 +300,12 @@ rte_eth_iterator_init(struct rte_dev_iterator *iter, const char *devargs_str)
 uint16_t
 rte_eth_iterator_next(struct rte_dev_iterator *iter)
 {
+	if (iter == NULL) {
+		RTE_ETHDEV_LOG(ERR,
+			"Cannot get next device from NULL iterator\n");
+		return RTE_MAX_ETHPORTS;
+	}
+
 	if (iter->cls == NULL) /* invalid ethdev iterator */
 		return RTE_MAX_ETHPORTS;
 
@@ -318,6 +335,11 @@ rte_eth_iterator_next(struct rte_dev_iterator *iter)
 void
 rte_eth_iterator_cleanup(struct rte_dev_iterator *iter)
 {
+	if (iter == NULL) {
+		RTE_ETHDEV_LOG(ERR, "Cannot do clean up from NULL iterator\n");
+		return;
+	}
+
 	if (iter->bus_str == NULL)
 		return; /* nothing to free in pure class filter */
 	free(RTE_CAST_FIELD(iter, bus_str, char *)); /* workaround const */
@@ -618,6 +640,11 @@ rte_eth_find_next_owned_by(uint16_t port_id, const uint64_t owner_id)
 int
 rte_eth_dev_owner_new(uint64_t *owner_id)
 {
+	if (owner_id == NULL) {
+		RTE_ETHDEV_LOG(ERR, "Cannot get new owner ID to NULL\n");
+		return -EINVAL;
+	}
+
 	eth_dev_shared_data_prepare();
 
 	rte_spinlock_lock(&eth_dev_shared_data->ownership_lock);
@@ -641,6 +668,13 @@ eth_dev_owner_set(const uint16_t port_id, const uint64_t old_owner_id,
 		return -ENODEV;
 	}
 
+	if (new_owner == NULL) {
+		RTE_ETHDEV_LOG(ERR,
+			"Cannot set ethdev port %u owner from NULL owner\n",
+			port_id);
+		return -EINVAL;
+	}
+
 	if (!eth_is_valid_owner_id(new_owner->id) &&
 	    !eth_is_valid_owner_id(old_owner_id)) {
 		RTE_ETHDEV_LOG(ERR,
@@ -734,23 +768,30 @@ rte_eth_dev_owner_delete(const uint64_t owner_id)
 int
 rte_eth_dev_owner_get(const uint16_t port_id, struct rte_eth_dev_owner *owner)
 {
-	int ret = 0;
-	struct rte_eth_dev *ethdev = &rte_eth_devices[port_id];
-
-	eth_dev_shared_data_prepare();
+	struct rte_eth_dev *ethdev;
 
-	rte_spinlock_lock(&eth_dev_shared_data->ownership_lock);
+	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
+	ethdev = &rte_eth_devices[port_id];
 
-	if (port_id >= RTE_MAX_ETHPORTS || !eth_dev_is_allocated(ethdev)) {
+	if (!eth_dev_is_allocated(ethdev)) {
 		RTE_ETHDEV_LOG(ERR, "Port id %"PRIu16" is not allocated\n",
 			port_id);
-		ret = -ENODEV;
-	} else {
-		rte_memcpy(owner, &ethdev->data->owner, sizeof(*owner));
+		return -ENODEV;
+	}
+
+	if (owner == NULL) {
+		RTE_ETHDEV_LOG(ERR, "Cannot get ethdev port %u owner to NULL\n",
+			port_id);
+		return -EINVAL;
 	}
 
+	eth_dev_shared_data_prepare();
+
+	rte_spinlock_lock(&eth_dev_shared_data->ownership_lock);
+	rte_memcpy(owner, &ethdev->data->owner, sizeof(*owner));
 	rte_spinlock_unlock(&eth_dev_shared_data->ownership_lock);
-	return ret;
+
+	return 0;
 }
 
 int
@@ -800,7 +841,8 @@ rte_eth_dev_get_name_by_port(uint16_t port_id, char *name)
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
 
 	if (name == NULL) {
-		RTE_ETHDEV_LOG(ERR, "Null pointer is specified\n");
+		RTE_ETHDEV_LOG(ERR, "Cannot get ethdev port %u name to NULL\n",
+			port_id);
 		return -EINVAL;
 	}
 
@@ -817,7 +859,12 @@ rte_eth_dev_get_port_by_name(const char *name, uint16_t *port_id)
 	uint16_t pid;
 
 	if (name == NULL) {
-		RTE_ETHDEV_LOG(ERR, "Null pointer is specified\n");
+		RTE_ETHDEV_LOG(ERR, "Cannot get port ID from NULL name");
+		return -EINVAL;
+	}
+
+	if (port_id == NULL) {
+		RTE_ETHDEV_LOG(ERR, "Cannot get port ID to NULL\n");
 		return -EINVAL;
 	}
 
@@ -945,8 +992,8 @@ rte_eth_dev_rx_queue_start(uint16_t port_id, uint16_t rx_queue_id)
 	int ret;
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
-
 	dev = &rte_eth_devices[port_id];
+
 	if (!dev->data->dev_started) {
 		RTE_ETHDEV_LOG(ERR,
 			"Port %u must be started before start any queue\n",
@@ -974,9 +1021,7 @@ rte_eth_dev_rx_queue_start(uint16_t port_id, uint16_t rx_queue_id)
 		return 0;
 	}
 
-	return eth_err(port_id, dev->dev_ops->rx_queue_start(dev,
-							     rx_queue_id));
-
+	return eth_err(port_id, dev->dev_ops->rx_queue_start(dev, rx_queue_id));
 }
 
 int
@@ -986,7 +1031,6 @@ rte_eth_dev_rx_queue_stop(uint16_t port_id, uint16_t rx_queue_id)
 	int ret;
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
-
 	dev = &rte_eth_devices[port_id];
 
 	ret = eth_dev_validate_rx_queue(dev, rx_queue_id);
@@ -1010,7 +1054,6 @@ rte_eth_dev_rx_queue_stop(uint16_t port_id, uint16_t rx_queue_id)
 	}
 
 	return eth_err(port_id, dev->dev_ops->rx_queue_stop(dev, rx_queue_id));
-
 }
 
 int
@@ -1020,8 +1063,8 @@ rte_eth_dev_tx_queue_start(uint16_t port_id, uint16_t tx_queue_id)
 	int ret;
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
-
 	dev = &rte_eth_devices[port_id];
+
 	if (!dev->data->dev_started) {
 		RTE_ETHDEV_LOG(ERR,
 			"Port %u must be started before start any queue\n",
@@ -1059,7 +1102,6 @@ rte_eth_dev_tx_queue_stop(uint16_t port_id, uint16_t tx_queue_id)
 	int ret;
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
-
 	dev = &rte_eth_devices[port_id];
 
 	ret = eth_dev_validate_tx_queue(dev, tx_queue_id);
@@ -1083,7 +1125,6 @@ rte_eth_dev_tx_queue_stop(uint16_t port_id, uint16_t tx_queue_id)
 	}
 
 	return eth_err(port_id, dev->dev_ops->tx_queue_stop(dev, tx_queue_id));
-
 }
 
 static int
@@ -1294,9 +1335,15 @@ rte_eth_dev_configure(uint16_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
 	uint16_t old_mtu;
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
-
 	dev = &rte_eth_devices[port_id];
 
+	if (dev_conf == NULL) {
+		RTE_ETHDEV_LOG(ERR,
+			"Cannot configure ethdev port %u from NULL config\n",
+			port_id);
+		return -EINVAL;
+	}
+
 	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_configure, -ENOTSUP);
 
 	if (dev->data->dev_started) {
@@ -1697,7 +1744,6 @@ rte_eth_dev_start(uint16_t port_id)
 	int ret, ret_stop;
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
-
 	dev = &rte_eth_devices[port_id];
 
 	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_start, -ENOTSUP);
@@ -1778,7 +1824,6 @@ rte_eth_dev_set_link_up(uint16_t port_id)
 	struct rte_eth_dev *dev;
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
-
 	dev = &rte_eth_devices[port_id];
 
 	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_up, -ENOTSUP);
@@ -1791,7 +1836,6 @@ rte_eth_dev_set_link_down(uint16_t port_id)
 	struct rte_eth_dev *dev;
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
-
 	dev = &rte_eth_devices[port_id];
 
 	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_down, -ENOTSUP);
@@ -1848,7 +1892,6 @@ rte_eth_dev_is_removed(uint16_t port_id)
 	int ret;
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, 0);
-
 	dev = &rte_eth_devices[port_id];
 
 	if (dev->state == RTE_ETH_DEV_REMOVED)
@@ -1949,8 +1992,8 @@ rte_eth_rx_queue_setup(uint16_t port_id, uint16_t rx_queue_id,
 	void **rxq;
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
-
 	dev = &rte_eth_devices[port_id];
+
 	if (rx_queue_id >= dev->data->nb_rx_queues) {
 		RTE_ETHDEV_LOG(ERR, "Invalid RX queue_id=%u\n", rx_queue_id);
 		return -EINVAL;
@@ -2134,12 +2177,20 @@ rte_eth_rx_hairpin_queue_setup(uint16_t port_id, uint16_t rx_queue_id,
 	int count;
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
-
 	dev = &rte_eth_devices[port_id];
+
 	if (rx_queue_id >= dev->data->nb_rx_queues) {
 		RTE_ETHDEV_LOG(ERR, "Invalid RX queue_id=%u\n", rx_queue_id);
 		return -EINVAL;
 	}
+
+	if (conf == NULL) {
+		RTE_ETHDEV_LOG(ERR,
+			"Cannot setup ethdev port %u Rx hairpin queue from NULL config\n",
+			port_id);
+		return -EINVAL;
+	}
+
 	ret = rte_eth_dev_hairpin_capability_get(port_id, &cap);
 	if (ret != 0)
 		return ret;
@@ -2205,8 +2256,8 @@ rte_eth_tx_queue_setup(uint16_t port_id, uint16_t tx_queue_id,
 	int ret;
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
-
 	dev = &rte_eth_devices[port_id];
+
 	if (tx_queue_id >= dev->data->nb_tx_queues) {
 		RTE_ETHDEV_LOG(ERR, "Invalid TX queue_id=%u\n", tx_queue_id);
 		return -EINVAL;
@@ -2307,10 +2358,19 @@ rte_eth_tx_hairpin_queue_setup(uint16_t port_id, uint16_t tx_queue_id,
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
 	dev = &rte_eth_devices[port_id];
+
 	if (tx_queue_id >= dev->data->nb_tx_queues) {
 		RTE_ETHDEV_LOG(ERR, "Invalid TX queue_id=%u\n", tx_queue_id);
 		return -EINVAL;
 	}
+
+	if (conf == NULL) {
+		RTE_ETHDEV_LOG(ERR,
+			"Cannot setup ethdev port %u Tx hairpin queue from NULL config\n",
+			port_id);
+		return -EINVAL;
+	}
+
 	ret = rte_eth_dev_hairpin_capability_get(port_id, &cap);
 	if (ret != 0)
 		return ret;
@@ -2372,6 +2432,7 @@ rte_eth_hairpin_bind(uint16_t tx_port, uint16_t rx_port)
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(tx_port, -ENODEV);
 	dev = &rte_eth_devices[tx_port];
+
 	if (dev->data->dev_started == 0) {
 		RTE_ETHDEV_LOG(ERR, "Tx port %d is not started\n", tx_port);
 		return -EBUSY;
@@ -2395,6 +2456,7 @@ rte_eth_hairpin_unbind(uint16_t tx_port, uint16_t rx_port)
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(tx_port, -ENODEV);
 	dev = &rte_eth_devices[tx_port];
+
 	if (dev->data->dev_started == 0) {
 		RTE_ETHDEV_LOG(ERR, "Tx port %d is already stopped\n", tx_port);
 		return -EBUSY;
@@ -2417,11 +2479,23 @@ rte_eth_hairpin_get_peer_ports(uint16_t port_id, uint16_t *peer_ports,
 	struct rte_eth_dev *dev;
 	int ret;
 
-	if (peer_ports == NULL || len == 0)
-		return -EINVAL;
-
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
 	dev = &rte_eth_devices[port_id];
+
+	if (peer_ports == NULL) {
+		RTE_ETHDEV_LOG(ERR,
+			"Cannot get ethdev port %u hairpin peer ports to NULL\n",
+			port_id);
+		return -EINVAL;
+	}
+
+	if (len == 0) {
+		RTE_ETHDEV_LOG(ERR,
+			"Cannot get ethdev port %u hairpin peer ports to array with zero size\n",
+			port_id);
+		return -EINVAL;
+	}
+
 	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->hairpin_get_peer_ports,
 				-ENOTSUP);
 
@@ -2455,6 +2529,12 @@ int
 rte_eth_tx_buffer_set_err_callback(struct rte_eth_dev_tx_buffer *buffer,
 		buffer_tx_error_fn cbfn, void *userdata)
 {
+	if (buffer == NULL) {
+		RTE_ETHDEV_LOG(ERR,
+			"Cannot set Tx buffer error callback to NULL buffer\n");
+		return -EINVAL;
+	}
+
 	buffer->error_callback = cbfn;
 	buffer->error_userdata = userdata;
 	return 0;
@@ -2465,8 +2545,10 @@ rte_eth_tx_buffer_init(struct rte_eth_dev_tx_buffer *buffer, uint16_t size)
 {
 	int ret = 0;
 
-	if (buffer == NULL)
+	if (buffer == NULL) {
+		RTE_ETHDEV_LOG(ERR, "Cannot initialize NULL buffer\n");
 		return -EINVAL;
+	}
 
 	buffer->size = size;
 	if (buffer->error_callback == NULL) {
@@ -2480,11 +2562,12 @@ rte_eth_tx_buffer_init(struct rte_eth_dev_tx_buffer *buffer, uint16_t size)
 int
 rte_eth_tx_done_cleanup(uint16_t port_id, uint16_t queue_id, uint32_t free_cnt)
 {
-	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
+	struct rte_eth_dev *dev;
 	int ret;
 
-	/* Validate Input Data. Bail if not valid or not supported. */
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
+	dev = &rte_eth_devices[port_id];
+
 	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_done_cleanup, -ENOTSUP);
 
 	/* Call driver to free pending mbufs. */
@@ -2541,8 +2624,8 @@ rte_eth_promiscuous_get(uint16_t port_id)
 	struct rte_eth_dev *dev;
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
-
 	dev = &rte_eth_devices[port_id];
+
 	return dev->data->promiscuous;
 }
 
@@ -2592,8 +2675,8 @@ rte_eth_allmulticast_get(uint16_t port_id)
 	struct rte_eth_dev *dev;
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
-
 	dev = &rte_eth_devices[port_id];
+
 	return dev->data->all_multicast;
 }
 
@@ -2605,8 +2688,13 @@ rte_eth_link_get(uint16_t port_id, struct rte_eth_link *eth_link)
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
 	dev = &rte_eth_devices[port_id];
 
-	if (dev->data->dev_conf.intr_conf.lsc &&
-	    dev->data->dev_started)
+	if (eth_link == NULL) {
+		RTE_ETHDEV_LOG(ERR, "Cannot get ethdev port %u link to NULL\n",
+			port_id);
+		return -EINVAL;
+	}
+
+	if (dev->data->dev_conf.intr_conf.lsc && dev->data->dev_started)
 		rte_eth_linkstatus_get(dev, eth_link);
 	else {
 		RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->link_update, -ENOTSUP);
@@ -2625,8 +2713,13 @@ rte_eth_link_get_nowait(uint16_t port_id, struct rte_eth_link *eth_link)
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
 	dev = &rte_eth_devices[port_id];
 
-	if (dev->data->dev_conf.intr_conf.lsc &&
-	    dev->data->dev_started)
+	if (eth_link == NULL) {
+		RTE_ETHDEV_LOG(ERR, "Cannot get ethdev port %u link to NULL\n",
+			port_id);
+		return -EINVAL;
+	}
+
+	if (dev->data->dev_conf.intr_conf.lsc && dev->data->dev_started)
 		rte_eth_linkstatus_get(dev, eth_link);
 	else {
 		RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->link_update, -ENOTSUP);
@@ -2663,6 +2756,22 @@ rte_eth_link_speed_to_str(uint32_t link_speed)
 int
 rte_eth_link_to_str(char *str, size_t len, const struct rte_eth_link *eth_link)
 {
+	if (str == NULL) {
+		RTE_ETHDEV_LOG(ERR, "Cannot convert link to NULL string\n");
+		return -EINVAL;
+	}
+
+	if (len == 0) {
+		RTE_ETHDEV_LOG(ERR,
+			"Cannot convert link to string with zero size\n");
+		return -EINVAL;
+	}
+
+	if (eth_link == NULL) {
+		RTE_ETHDEV_LOG(ERR, "Cannot convert to string from NULL link\n");
+		return -EINVAL;
+	}
+
 	if (eth_link->link_status == ETH_LINK_DOWN)
 		return snprintf(str, len, "Link down");
 	else
@@ -2680,8 +2789,14 @@ rte_eth_stats_get(uint16_t port_id, struct rte_eth_stats *stats)
 	struct rte_eth_dev *dev;
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
-
 	dev = &rte_eth_devices[port_id];
+
+	if (stats == NULL) {
+		RTE_ETHDEV_LOG(ERR, "Cannot get ethdev port %u stats to NULL\n",
+			port_id);
+		return -EINVAL;
+	}
+
 	memset(stats, 0, sizeof(*stats));
 
 	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->stats_get, -ENOTSUP);
@@ -2761,13 +2876,17 @@ rte_eth_xstats_get_id_by_name(uint16_t port_id, const char *xstat_name,
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
 
-	if (!id) {
-		RTE_ETHDEV_LOG(ERR, "Id pointer is NULL\n");
+	if (xstat_name == NULL) {
+		RTE_ETHDEV_LOG(ERR,
+			"Cannot get ethdev port %u xstats ID from NULL xstat name\n",
+			port_id);
 		return -ENOMEM;
 	}
 
-	if (!xstat_name) {
-		RTE_ETHDEV_LOG(ERR, "xstat_name pointer is NULL\n");
+	if (id == NULL) {
+		RTE_ETHDEV_LOG(ERR,
+			"Cannot get ethdev port %u xstats ID to NULL\n",
+			port_id);
 		return -ENOMEM;
 	}
 
@@ -3055,12 +3174,13 @@ rte_eth_xstats_get_by_id(uint16_t port_id, const uint64_t *ids,
 	int ret;
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
+	dev = &rte_eth_devices[port_id];
+
 	ret = eth_dev_get_xstats_count(port_id);
 	if (ret < 0)
 		return ret;
 	expected_entries = (uint16_t)ret;
 	struct rte_eth_xstat xstats[expected_entries];
-	dev = &rte_eth_devices[port_id];
 	basic_count = eth_dev_get_xstats_basic_count(dev);
 
 	/* Return max number of stats if no ids given */
@@ -3144,7 +3264,6 @@ rte_eth_xstats_get(uint16_t port_id, struct rte_eth_xstat *xstats,
 	int ret;
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
-
 	dev = &rte_eth_devices[port_id];
 
 	nb_rxqs = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
@@ -3210,11 +3329,8 @@ eth_dev_set_queue_stats_mapping(uint16_t port_id, uint16_t queue_id,
 	struct rte_eth_dev *dev;
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
-
 	dev = &rte_eth_devices[port_id];
 
-	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_stats_mapping_set, -ENOTSUP);
-
 	if (is_rx && (queue_id >= dev->data->nb_rx_queues))
 		return -EINVAL;
 
@@ -3224,11 +3340,10 @@ eth_dev_set_queue_stats_mapping(uint16_t port_id, uint16_t queue_id,
 	if (stat_idx >= RTE_ETHDEV_QUEUE_STAT_CNTRS)
 		return -EINVAL;
 
-	return (*dev->dev_ops->queue_stats_mapping_set)
-			(dev, queue_id, stat_idx, is_rx);
+	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_stats_mapping_set, -ENOTSUP);
+	return (*dev->dev_ops->queue_stats_mapping_set) (dev, queue_id, stat_idx, is_rx);
 }
 
-
 int
 rte_eth_dev_set_tx_queue_stats_mapping(uint16_t port_id, uint16_t tx_queue_id,
 		uint8_t stat_idx)
@@ -3238,7 +3353,6 @@ rte_eth_dev_set_tx_queue_stats_mapping(uint16_t port_id, uint16_t tx_queue_id,
 						stat_idx, STAT_QMAP_TX));
 }
 
-
 int
 rte_eth_dev_set_rx_queue_stats_mapping(uint16_t port_id, uint16_t rx_queue_id,
 		uint8_t stat_idx)
@@ -3256,6 +3370,20 @@ rte_eth_dev_fw_version_get(uint16_t port_id, char *fw_version, size_t fw_size)
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
 	dev = &rte_eth_devices[port_id];
 
+	if (fw_version == NULL) {
+		RTE_ETHDEV_LOG(ERR,
+			"Cannot get ethdev port %u FW version to NULL\n",
+			port_id);
+		return -EINVAL;
+	}
+
+	if (fw_size == 0) {
+		RTE_ETHDEV_LOG(ERR,
+			"Cannot get ethdev port %u FW version to buffer with zero size\n",
+			port_id);
+		return -EINVAL;
+	}
+
 	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fw_version_get, -ENOTSUP);
 	return eth_err(port_id, (*dev->dev_ops->fw_version_get)(dev,
 							fw_version, fw_size));
@@ -3274,6 +3402,15 @@ rte_eth_dev_info_get(uint16_t port_id, struct rte_eth_dev_info *dev_info)
 	};
 	int diag;
 
+	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
+	dev = &rte_eth_devices[port_id];
+
+	if (dev_info == NULL) {
+		RTE_ETHDEV_LOG(ERR, "Cannot get ethdev port %u info to NULL\n",
+			port_id);
+		return -EINVAL;
+	}
+
 	/*
 	 * Init dev_info before port_id check since caller does not have
 	 * return status and does not know if get is successful or not.
@@ -3281,9 +3418,6 @@ rte_eth_dev_info_get(uint16_t port_id, struct rte_eth_dev_info *dev_info)
 	memset(dev_info, 0, sizeof(struct rte_eth_dev_info));
 	dev_info->switch_info.domain_id = RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID;
 
-	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
-	dev = &rte_eth_devices[port_id];
-
 	dev_info->rx_desc_lim = lim;
 	dev_info->tx_desc_lim = lim;
 	dev_info->device = dev->device;
@@ -3323,6 +3457,21 @@ rte_eth_dev_get_supported_ptypes(uint16_t port_id, uint32_t ptype_mask,
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
 	dev = &rte_eth_devices[port_id];
+
+	if (ptypes == NULL) {
+		RTE_ETHDEV_LOG(ERR,
+			"Cannot get ethdev port %u supported packet types to NULL\n",
+			port_id);
+		return -EINVAL;
+	}
+
+	if (num == 0) {
+		RTE_ETHDEV_LOG(ERR,
+			"Cannot get ethdev port %u supported packet types to array with zero size\n",
+			port_id);
+		return -EINVAL;
+	}
+
 	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_supported_ptypes_get, 0);
 	all_ptypes = (*dev->dev_ops->dev_supported_ptypes_get)(dev);
 
@@ -3361,8 +3510,12 @@ rte_eth_dev_set_ptypes(uint16_t port_id, uint32_t ptype_mask,
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
 	dev = &rte_eth_devices[port_id];
 
-	if (num > 0 && set_ptypes == NULL)
+	if (num > 0 && set_ptypes == NULL) {
+		RTE_ETHDEV_LOG(ERR,
+			"Cannot get ethdev port %u set packet types to NULL when array size is non zero\n",
+			port_id);
 		return -EINVAL;
+	}
 
 	if (*dev->dev_ops->dev_supported_ptypes_get == NULL ||
 			*dev->dev_ops->dev_ptypes_set == NULL) {
@@ -3432,6 +3585,14 @@ rte_eth_macaddr_get(uint16_t port_id, struct rte_ether_addr *mac_addr)
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
 	dev = &rte_eth_devices[port_id];
+
+	if (mac_addr == NULL) {
+		RTE_ETHDEV_LOG(ERR,
+			"Cannot get ethdev port %u MAC address to NULL\n",
+			port_id);
+		return -EINVAL;
+	}
+
 	rte_ether_addr_copy(&dev->data->mac_addrs[0], mac_addr);
 
 	return 0;
@@ -3443,8 +3604,14 @@ rte_eth_dev_get_mtu(uint16_t port_id, uint16_t *mtu)
 	struct rte_eth_dev *dev;
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
-
 	dev = &rte_eth_devices[port_id];
+
+	if (mtu == NULL) {
+		RTE_ETHDEV_LOG(ERR, "Cannot get ethdev port %u MTU to NULL\n",
+			port_id);
+		return -EINVAL;
+	}
+
 	*mtu = dev->data->mtu;
 	return 0;
 }
@@ -3490,6 +3657,7 @@ rte_eth_dev_vlan_filter(uint16_t port_id, uint16_t vlan_id, int on)
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
 	dev = &rte_eth_devices[port_id];
+
 	if (!(dev->data->dev_conf.rxmode.offloads &
 	      DEV_RX_OFFLOAD_VLAN_FILTER)) {
 		RTE_ETHDEV_LOG(ERR, "Port %u: vlan-filtering disabled\n",
@@ -3531,6 +3699,7 @@ rte_eth_dev_set_vlan_strip_on_queue(uint16_t port_id, uint16_t rx_queue_id,
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
 	dev = &rte_eth_devices[port_id];
+
 	if (rx_queue_id >= dev->data->nb_rx_queues) {
 		RTE_ETHDEV_LOG(ERR, "Invalid rx_queue_id=%u\n", rx_queue_id);
 		return -EINVAL;
@@ -3551,8 +3720,8 @@ rte_eth_dev_set_vlan_ether_type(uint16_t port_id,
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
 	dev = &rte_eth_devices[port_id];
-	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_tpid_set, -ENOTSUP);
 
+	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_tpid_set, -ENOTSUP);
 	return eth_err(port_id, (*dev->dev_ops->vlan_tpid_set)(dev, vlan_type,
 							       tpid));
 }
@@ -3681,8 +3850,8 @@ rte_eth_dev_set_vlan_pvid(uint16_t port_id, uint16_t pvid, int on)
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
 	dev = &rte_eth_devices[port_id];
-	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_pvid_set, -ENOTSUP);
 
+	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_pvid_set, -ENOTSUP);
 	return eth_err(port_id, (*dev->dev_ops->vlan_pvid_set)(dev, pvid, on));
 }
 
@@ -3693,6 +3862,14 @@ rte_eth_dev_flow_ctrl_get(uint16_t port_id, struct rte_eth_fc_conf *fc_conf)
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
 	dev = &rte_eth_devices[port_id];
+
+	if (fc_conf == NULL) {
+		RTE_ETHDEV_LOG(ERR,
+			"Cannot get ethdev port %u flow control config to NULL\n",
+			port_id);
+		return -EINVAL;
+	}
+
 	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_get, -ENOTSUP);
 	memset(fc_conf, 0, sizeof(*fc_conf));
 	return eth_err(port_id, (*dev->dev_ops->flow_ctrl_get)(dev, fc_conf));
@@ -3704,12 +3881,20 @@ rte_eth_dev_flow_ctrl_set(uint16_t port_id, struct rte_eth_fc_conf *fc_conf)
 	struct rte_eth_dev *dev;
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
+	dev = &rte_eth_devices[port_id];
+
+	if (fc_conf == NULL) {
+		RTE_ETHDEV_LOG(ERR,
+			"Cannot set ethdev port %u flow control from NULL config\n",
+			port_id);
+		return -EINVAL;
+	}
+
 	if ((fc_conf->send_xon != 0) && (fc_conf->send_xon != 1)) {
 		RTE_ETHDEV_LOG(ERR, "Invalid send_xon, only 0/1 allowed\n");
 		return -EINVAL;
 	}
 
-	dev = &rte_eth_devices[port_id];
 	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_set, -ENOTSUP);
 	return eth_err(port_id, (*dev->dev_ops->flow_ctrl_set)(dev, fc_conf));
 }
@@ -3721,12 +3906,20 @@ rte_eth_dev_priority_flow_ctrl_set(uint16_t port_id,
 	struct rte_eth_dev *dev;
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
+	dev = &rte_eth_devices[port_id];
+
+	if (pfc_conf == NULL) {
+		RTE_ETHDEV_LOG(ERR,
+			"Cannot set ethdev port %u priority flow control from NULL config\n",
+			port_id);
+		return -EINVAL;
+	}
+
 	if (pfc_conf->priority > (ETH_DCB_NUM_USER_PRIORITIES - 1)) {
 		RTE_ETHDEV_LOG(ERR, "Invalid priority, only 0-7 allowed\n");
 		return -EINVAL;
 	}
 
-	dev = &rte_eth_devices[port_id];
 	/* High water, low water validation are device specific */
 	if  (*dev->dev_ops->priority_flow_ctrl_set)
 		return eth_err(port_id, (*dev->dev_ops->priority_flow_ctrl_set)
@@ -3740,9 +3933,6 @@ eth_check_reta_mask(struct rte_eth_rss_reta_entry64 *reta_conf,
 {
 	uint16_t i, num;
 
-	if (!reta_conf)
-		return -EINVAL;
-
 	num = (reta_size + RTE_RETA_GROUP_SIZE - 1) / RTE_RETA_GROUP_SIZE;
 	for (i = 0; i < num; i++) {
 		if (reta_conf[i].mask)
@@ -3759,9 +3949,6 @@ eth_check_reta_entry(struct rte_eth_rss_reta_entry64 *reta_conf,
 {
 	uint16_t i, idx, shift;
 
-	if (!reta_conf)
-		return -EINVAL;
-
 	if (max_rxq == 0) {
 		RTE_ETHDEV_LOG(ERR, "No receive queue is available\n");
 		return -EINVAL;
@@ -3792,13 +3979,27 @@ rte_eth_dev_rss_reta_update(uint16_t port_id,
 	int ret;
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
+	dev = &rte_eth_devices[port_id];
+
+	if (reta_conf == NULL) {
+		RTE_ETHDEV_LOG(ERR,
+			"Cannot update ethdev port %u RSS RETA to NULL\n",
+			port_id);
+		return -EINVAL;
+	}
+
+	if (reta_size == 0) {
+		RTE_ETHDEV_LOG(ERR,
+			"Cannot update ethdev port %u RSS RETA with zero size\n",
+			port_id);
+		return -EINVAL;
+	}
+
 	/* Check mask bits */
 	ret = eth_check_reta_mask(reta_conf, reta_size);
 	if (ret < 0)
 		return ret;
 
-	dev = &rte_eth_devices[port_id];
-
 	/* Check entry value */
 	ret = eth_check_reta_entry(reta_conf, reta_size,
 				dev->data->nb_rx_queues);
@@ -3819,13 +4020,20 @@ rte_eth_dev_rss_reta_query(uint16_t port_id,
 	int ret;
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
+	dev = &rte_eth_devices[port_id];
+
+	if (reta_conf == NULL) {
+		RTE_ETHDEV_LOG(ERR,
+			"Cannot query ethdev port %u RSS RETA from NULL config\n",
+			port_id);
+		return -EINVAL;
+	}
 
 	/* Check mask bits */
 	ret = eth_check_reta_mask(reta_conf, reta_size);
 	if (ret < 0)
 		return ret;
 
-	dev = &rte_eth_devices[port_id];
 	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_query, -ENOTSUP);
 	return eth_err(port_id, (*dev->dev_ops->reta_query)(dev, reta_conf,
 							    reta_size));
@@ -3840,14 +4048,20 @@ rte_eth_dev_rss_hash_update(uint16_t port_id,
 	int ret;
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
+	dev = &rte_eth_devices[port_id];
+
+	if (rss_conf == NULL) {
+		RTE_ETHDEV_LOG(ERR,
+			"Cannot update ethdev port %u RSS hash from NULL config\n",
+			port_id);
+		return -EINVAL;
+	}
 
 	ret = rte_eth_dev_info_get(port_id, &dev_info);
 	if (ret != 0)
 		return ret;
 
 	rss_conf->rss_hf = rte_eth_rss_hf_refine(rss_conf->rss_hf);
-
-	dev = &rte_eth_devices[port_id];
 	if ((dev_info.flow_type_rss_offloads | rss_conf->rss_hf) !=
 	    dev_info.flow_type_rss_offloads) {
 		RTE_ETHDEV_LOG(ERR,
@@ -3869,6 +4083,14 @@ rte_eth_dev_rss_hash_conf_get(uint16_t port_id,
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
 	dev = &rte_eth_devices[port_id];
+
+	if (rss_conf == NULL) {
+		RTE_ETHDEV_LOG(ERR,
+			"Cannot get ethdev port %u RSS hash config to NULL\n",
+			port_id);
+		return -EINVAL;
+	}
+
 	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_conf_get, -ENOTSUP);
 	return eth_err(port_id, (*dev->dev_ops->rss_hash_conf_get)(dev,
 								   rss_conf));
@@ -3881,8 +4103,12 @@ rte_eth_dev_udp_tunnel_port_add(uint16_t port_id,
 	struct rte_eth_dev *dev;
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
+	dev = &rte_eth_devices[port_id];
+
 	if (udp_tunnel == NULL) {
-		RTE_ETHDEV_LOG(ERR, "Invalid udp_tunnel parameter\n");
+		RTE_ETHDEV_LOG(ERR,
+			"Cannot add ethdev port %u UDP tunnel port from NULL UDP tunnel\n",
+			port_id);
 		return -EINVAL;
 	}
 
@@ -3891,7 +4117,6 @@ rte_eth_dev_udp_tunnel_port_add(uint16_t port_id,
 		return -EINVAL;
 	}
 
-	dev = &rte_eth_devices[port_id];
 	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_port_add, -ENOTSUP);
 	return eth_err(port_id, (*dev->dev_ops->udp_tunnel_port_add)(dev,
 								udp_tunnel));
@@ -3907,7 +4132,9 @@ rte_eth_dev_udp_tunnel_port_delete(uint16_t port_id,
 	dev = &rte_eth_devices[port_id];
 
 	if (udp_tunnel == NULL) {
-		RTE_ETHDEV_LOG(ERR, "Invalid udp_tunnel parameter\n");
+		RTE_ETHDEV_LOG(ERR,
+			"Cannot delete ethdev port %u UDP tunnel port from NULL UDP tunnel\n",
+			port_id);
 		return -EINVAL;
 	}
 
@@ -3928,6 +4155,7 @@ rte_eth_led_on(uint16_t port_id)
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
 	dev = &rte_eth_devices[port_id];
+
 	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_on, -ENOTSUP);
 	return eth_err(port_id, (*dev->dev_ops->dev_led_on)(dev));
 }
@@ -3939,6 +4167,7 @@ rte_eth_led_off(uint16_t port_id)
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
 	dev = &rte_eth_devices[port_id];
+
 	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_off, -ENOTSUP);
 	return eth_err(port_id, (*dev->dev_ops->dev_led_off)(dev));
 }
@@ -3951,11 +4180,16 @@ rte_eth_fec_get_capability(uint16_t port_id,
 	struct rte_eth_dev *dev;
 	int ret;
 
-	if (speed_fec_capa == NULL && num > 0)
-		return -EINVAL;
-
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
 	dev = &rte_eth_devices[port_id];
+
+	if (speed_fec_capa == NULL && num > 0) {
+		RTE_ETHDEV_LOG(ERR,
+			"Cannot get ethdev port %u FEC capability to NULL when array size is non zero\n",
+			port_id);
+		return -EINVAL;
+	}
+
 	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fec_get_capability, -ENOTSUP);
 	ret = (*dev->dev_ops->fec_get_capability)(dev, speed_fec_capa, num);
 
@@ -3967,11 +4201,16 @@ rte_eth_fec_get(uint16_t port_id, uint32_t *fec_capa)
 {
 	struct rte_eth_dev *dev;
 
-	if (fec_capa == NULL)
-		return -EINVAL;
-
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
 	dev = &rte_eth_devices[port_id];
+
+	if (fec_capa == NULL) {
+		RTE_ETHDEV_LOG(ERR,
+			"Cannot get ethdev port %u current FEC mode to NULL\n",
+			port_id);
+		return -EINVAL;
+	}
+
 	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fec_get, -ENOTSUP);
 	return eth_err(port_id, (*dev->dev_ops->fec_get)(dev, fec_capa));
 }
@@ -3983,6 +4222,7 @@ rte_eth_fec_set(uint16_t port_id, uint32_t fec_capa)
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
 	dev = &rte_eth_devices[port_id];
+
 	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fec_set, -ENOTSUP);
 	return eth_err(port_id, (*dev->dev_ops->fec_set)(dev, fec_capa));
 }
@@ -4024,6 +4264,14 @@ rte_eth_dev_mac_addr_add(uint16_t port_id, struct rte_ether_addr *addr,
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
 	dev = &rte_eth_devices[port_id];
+
+	if (addr == NULL) {
+		RTE_ETHDEV_LOG(ERR,
+			"Cannot add ethdev port %u MAC address from NULL address\n",
+			port_id);
+		return -EINVAL;
+	}
+
 	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_add, -ENOTSUP);
 
 	if (rte_is_zero_ether_addr(addr)) {
@@ -4074,6 +4322,14 @@ rte_eth_dev_mac_addr_remove(uint16_t port_id, struct rte_ether_addr *addr)
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
 	dev = &rte_eth_devices[port_id];
+
+	if (addr == NULL) {
+		RTE_ETHDEV_LOG(ERR,
+			"Cannot remove ethdev port %u MAC address from NULL address\n",
+			port_id);
+		return -EINVAL;
+	}
+
 	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_remove, -ENOTSUP);
 
 	index = eth_dev_get_mac_addr_index(port_id, addr);
@@ -4104,11 +4360,18 @@ rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr)
 	int ret;
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
+	dev = &rte_eth_devices[port_id];
+
+	if (addr == NULL) {
+		RTE_ETHDEV_LOG(ERR,
+			"Cannot set ethdev port %u default MAC address from NULL address\n",
+			port_id);
+		return -EINVAL;
+	}
 
 	if (!rte_is_valid_assigned_ether_addr(addr))
 		return -EINVAL;
 
-	dev = &rte_eth_devices[port_id];
 	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_set, -ENOTSUP);
 
 	ret = (*dev->dev_ops->mac_addr_set)(dev, addr);
@@ -4159,8 +4422,15 @@ rte_eth_dev_uc_hash_table_set(uint16_t port_id, struct rte_ether_addr *addr,
 	struct rte_eth_dev *dev;
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
-
 	dev = &rte_eth_devices[port_id];
+
+	if (addr == NULL) {
+		RTE_ETHDEV_LOG(ERR,
+			"Cannot set ethdev port %u unicast hash table from NULL address\n",
+			port_id);
+		return -EINVAL;
+	}
+
 	if (rte_is_zero_ether_addr(addr)) {
 		RTE_ETHDEV_LOG(ERR, "Port %u: Cannot add NULL MAC address\n",
 			port_id);
@@ -4209,7 +4479,6 @@ rte_eth_dev_uc_all_hash_table_set(uint16_t port_id, uint8_t on)
 	struct rte_eth_dev *dev;
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
-
 	dev = &rte_eth_devices[port_id];
 
 	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_all_hash_table_set, -ENOTSUP);
@@ -4226,12 +4495,12 @@ int rte_eth_set_queue_rate_limit(uint16_t port_id, uint16_t queue_idx,
 	int ret;
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
+	dev = &rte_eth_devices[port_id];
 
 	ret = rte_eth_dev_info_get(port_id, &dev_info);
 	if (ret != 0)
 		return ret;
 
-	dev = &rte_eth_devices[port_id];
 	link = dev->data->dev_link;
 
 	if (queue_idx > dev_info.max_tx_queues) {
@@ -4261,6 +4530,15 @@ rte_eth_mirror_rule_set(uint16_t port_id,
 	struct rte_eth_dev *dev;
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
+	dev = &rte_eth_devices[port_id];
+
+	if (mirror_conf == NULL) {
+		RTE_ETHDEV_LOG(ERR,
+			"Cannot set ethdev port %u mirror rule from NULL config\n",
+			port_id);
+		return -EINVAL;
+	}
+
 	if (mirror_conf->rule_type == 0) {
 		RTE_ETHDEV_LOG(ERR, "Mirror rule type can not be 0\n");
 		return -EINVAL;
@@ -4287,7 +4565,6 @@ rte_eth_mirror_rule_set(uint16_t port_id,
 		return -EINVAL;
 	}
 
-	dev = &rte_eth_devices[port_id];
 	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_set, -ENOTSUP);
 
 	return eth_err(port_id, (*dev->dev_ops->mirror_rule_set)(dev,
@@ -4300,12 +4577,10 @@ rte_eth_mirror_rule_reset(uint16_t port_id, uint8_t rule_id)
 	struct rte_eth_dev *dev;
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
-
 	dev = &rte_eth_devices[port_id];
-	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_reset, -ENOTSUP);
 
-	return eth_err(port_id, (*dev->dev_ops->mirror_rule_reset)(dev,
-								   rule_id));
+	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_reset, -ENOTSUP);
+	return eth_err(port_id, (*dev->dev_ops->mirror_rule_reset)(dev, rule_id));
 }
 
 RTE_INIT(eth_dev_init_cb_lists)
@@ -4326,8 +4601,12 @@ rte_eth_dev_callback_register(uint16_t port_id,
 	uint16_t next_port;
 	uint16_t last_port;
 
-	if (!cb_fn)
+	if (cb_fn == NULL) {
+		RTE_ETHDEV_LOG(ERR,
+			"Cannot register ethdev port %u callback from NULL\n",
+			port_id);
 		return -EINVAL;
+	}
 
 	if (!rte_eth_dev_is_valid_port(port_id) && port_id != RTE_ETH_ALL) {
 		RTE_ETHDEV_LOG(ERR, "Invalid port_id=%d\n", port_id);
@@ -4389,8 +4668,12 @@ rte_eth_dev_callback_unregister(uint16_t port_id,
 	uint16_t next_port;
 	uint16_t last_port;
 
-	if (!cb_fn)
+	if (cb_fn == NULL) {
+		RTE_ETHDEV_LOG(ERR,
+			"Cannot unregister ethdev port %u callback from NULL\n",
+			port_id);
 		return -EINVAL;
+	}
 
 	if (!rte_eth_dev_is_valid_port(port_id) && port_id != RTE_ETH_ALL) {
 		RTE_ETHDEV_LOG(ERR, "Invalid port_id=%d\n", port_id);
@@ -4483,7 +4766,6 @@ rte_eth_dev_rx_intr_ctl(uint16_t port_id, int epfd, int op, void *data)
 	int rc;
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
-
 	dev = &rte_eth_devices[port_id];
 
 	if (!dev->intr_handle) {
@@ -4520,7 +4802,6 @@ rte_eth_dev_rx_intr_ctl_q_get_fd(uint16_t port_id, uint16_t queue_id)
 	int fd;
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -1);
-
 	dev = &rte_eth_devices[port_id];
 
 	if (queue_id >= dev->data->nb_rx_queues) {
@@ -4707,8 +4988,8 @@ rte_eth_dev_rx_intr_ctl_q(uint16_t port_id, uint16_t queue_id,
 	int rc;
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
-
 	dev = &rte_eth_devices[port_id];
+
 	if (queue_id >= dev->data->nb_rx_queues) {
 		RTE_ETHDEV_LOG(ERR, "Invalid RX queue_id=%u\n", queue_id);
 		return -EINVAL;
@@ -4745,7 +5026,6 @@ rte_eth_dev_rx_intr_enable(uint16_t port_id,
 	int ret;
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
-
 	dev = &rte_eth_devices[port_id];
 
 	ret = eth_dev_validate_rx_queue(dev, queue_id);
@@ -4753,8 +5033,7 @@ rte_eth_dev_rx_intr_enable(uint16_t port_id,
 		return ret;
 
 	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_intr_enable, -ENOTSUP);
-	return eth_err(port_id, (*dev->dev_ops->rx_queue_intr_enable)(dev,
-								queue_id));
+	return eth_err(port_id, (*dev->dev_ops->rx_queue_intr_enable)(dev, queue_id));
 }
 
 int
@@ -4765,7 +5044,6 @@ rte_eth_dev_rx_intr_disable(uint16_t port_id,
 	int ret;
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
-
 	dev = &rte_eth_devices[port_id];
 
 	ret = eth_dev_validate_rx_queue(dev, queue_id);
@@ -4773,8 +5051,7 @@ rte_eth_dev_rx_intr_disable(uint16_t port_id,
 		return ret;
 
 	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_intr_disable, -ENOTSUP);
-	return eth_err(port_id, (*dev->dev_ops->rx_queue_intr_disable)(dev,
-								queue_id));
+	return eth_err(port_id, (*dev->dev_ops->rx_queue_intr_disable)(dev, queue_id));
 }
 
 
@@ -5008,16 +5285,19 @@ rte_eth_rx_queue_info_get(uint16_t port_id, uint16_t queue_id,
 	struct rte_eth_dev *dev;
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
-
-	if (qinfo == NULL)
-		return -EINVAL;
-
 	dev = &rte_eth_devices[port_id];
+
 	if (queue_id >= dev->data->nb_rx_queues) {
 		RTE_ETHDEV_LOG(ERR, "Invalid RX queue_id=%u\n", queue_id);
 		return -EINVAL;
 	}
 
+	if (qinfo == NULL) {
+		RTE_ETHDEV_LOG(ERR, "Cannot get ethdev port %u Rx queue %u info to NULL\n",
+			port_id, queue_id);
+		return -EINVAL;
+	}
+
 	if (dev->data->rx_queues == NULL ||
 			dev->data->rx_queues[queue_id] == NULL) {
 		RTE_ETHDEV_LOG(ERR,
@@ -5050,16 +5330,19 @@ rte_eth_tx_queue_info_get(uint16_t port_id, uint16_t queue_id,
 	struct rte_eth_dev *dev;
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
-
-	if (qinfo == NULL)
-		return -EINVAL;
-
 	dev = &rte_eth_devices[port_id];
+
 	if (queue_id >= dev->data->nb_tx_queues) {
 		RTE_ETHDEV_LOG(ERR, "Invalid TX queue_id=%u\n", queue_id);
 		return -EINVAL;
 	}
 
+	if (qinfo == NULL) {
+		RTE_ETHDEV_LOG(ERR, "Cannot get ethdev port %u Tx queue %u info to NULL\n",
+			port_id, queue_id);
+		return -EINVAL;
+	}
+
 	if (dev->data->tx_queues == NULL ||
 			dev->data->tx_queues[queue_id] == NULL) {
 		RTE_ETHDEV_LOG(ERR,
@@ -5092,10 +5375,6 @@ rte_eth_rx_burst_mode_get(uint16_t port_id, uint16_t queue_id,
 	struct rte_eth_dev *dev;
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
-
-	if (mode == NULL)
-		return -EINVAL;
-
 	dev = &rte_eth_devices[port_id];
 
 	if (queue_id >= dev->data->nb_rx_queues) {
@@ -5103,6 +5382,13 @@ rte_eth_rx_burst_mode_get(uint16_t port_id, uint16_t queue_id,
 		return -EINVAL;
 	}
 
+	if (mode == NULL) {
+		RTE_ETHDEV_LOG(ERR,
+			"Cannot get ethdev port %u Rx queue %u burst mode to NULL\n",
+			port_id, queue_id);
+		return -EINVAL;
+	}
+
 	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_burst_mode_get, -ENOTSUP);
 	memset(mode, 0, sizeof(*mode));
 	return eth_err(port_id,
@@ -5116,10 +5402,6 @@ rte_eth_tx_burst_mode_get(uint16_t port_id, uint16_t queue_id,
 	struct rte_eth_dev *dev;
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
-
-	if (mode == NULL)
-		return -EINVAL;
-
 	dev = &rte_eth_devices[port_id];
 
 	if (queue_id >= dev->data->nb_tx_queues) {
@@ -5127,6 +5409,13 @@ rte_eth_tx_burst_mode_get(uint16_t port_id, uint16_t queue_id,
 		return -EINVAL;
 	}
 
+	if (mode == NULL) {
+		RTE_ETHDEV_LOG(ERR,
+			"Cannot get ethdev port %u Tx queue %u burst mode to NULL\n",
+			port_id, queue_id);
+		return -EINVAL;
+	}
+
 	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_burst_mode_get, -ENOTSUP);
 	memset(mode, 0, sizeof(*mode));
 	return eth_err(port_id,
@@ -5140,25 +5429,23 @@ rte_eth_get_monitor_addr(uint16_t port_id, uint16_t queue_id,
 	struct rte_eth_dev *dev;
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
-
 	dev = &rte_eth_devices[port_id];
 
-	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_monitor_addr, -ENOTSUP);
-
 	if (queue_id >= dev->data->nb_rx_queues) {
 		RTE_ETHDEV_LOG(ERR, "Invalid Rx queue_id=%u\n", queue_id);
 		return -EINVAL;
 	}
 
 	if (pmc == NULL) {
-		RTE_ETHDEV_LOG(ERR, "Invalid power monitor condition=%p\n",
-				pmc);
+		RTE_ETHDEV_LOG(ERR,
+			"Cannot get ethdev port %u Rx queue %u power monitor condition to NULL\n",
+			port_id, queue_id);
 		return -EINVAL;
 	}
 
+	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_monitor_addr, -ENOTSUP);
 	return eth_err(port_id,
-		dev->dev_ops->get_monitor_addr(dev->data->rx_queues[queue_id],
-			pmc));
+		dev->dev_ops->get_monitor_addr(dev->data->rx_queues[queue_id], pmc));
 }
 
 int
@@ -5169,8 +5456,8 @@ rte_eth_dev_set_mc_addr_list(uint16_t port_id,
 	struct rte_eth_dev *dev;
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
-
 	dev = &rte_eth_devices[port_id];
+
 	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_mc_addr_list, -ENOTSUP);
 	return eth_err(port_id, dev->dev_ops->set_mc_addr_list(dev,
 						mc_addr_set, nb_mc_addr));
@@ -5209,6 +5496,13 @@ rte_eth_timesync_read_rx_timestamp(uint16_t port_id, struct timespec *timestamp,
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
 	dev = &rte_eth_devices[port_id];
 
+	if (timestamp == NULL) {
+		RTE_ETHDEV_LOG(ERR,
+			"Cannot read ethdev port %u Rx timestamp to NULL\n",
+			port_id);
+		return -EINVAL;
+	}
+
 	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_rx_timestamp, -ENOTSUP);
 	return eth_err(port_id, (*dev->dev_ops->timesync_read_rx_timestamp)
 				(dev, timestamp, flags));
@@ -5223,6 +5517,13 @@ rte_eth_timesync_read_tx_timestamp(uint16_t port_id,
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
 	dev = &rte_eth_devices[port_id];
 
+	if (timestamp == NULL) {
+		RTE_ETHDEV_LOG(ERR,
+			"Cannot read ethdev port %u Tx timestamp to NULL\n",
+			port_id);
+		return -EINVAL;
+	}
+
 	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_tx_timestamp, -ENOTSUP);
 	return eth_err(port_id, (*dev->dev_ops->timesync_read_tx_timestamp)
 				(dev, timestamp));
@@ -5237,8 +5538,7 @@ rte_eth_timesync_adjust_time(uint16_t port_id, int64_t delta)
 	dev = &rte_eth_devices[port_id];
 
 	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_adjust_time, -ENOTSUP);
-	return eth_err(port_id, (*dev->dev_ops->timesync_adjust_time)(dev,
-								      delta));
+	return eth_err(port_id, (*dev->dev_ops->timesync_adjust_time)(dev, delta));
 }
 
 int
@@ -5249,6 +5549,13 @@ rte_eth_timesync_read_time(uint16_t port_id, struct timespec *timestamp)
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
 	dev = &rte_eth_devices[port_id];
 
+	if (timestamp == NULL) {
+		RTE_ETHDEV_LOG(ERR,
+			"Cannot read ethdev port %u timesync time to NULL\n",
+			port_id);
+		return -EINVAL;
+	}
+
 	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_time, -ENOTSUP);
 	return eth_err(port_id, (*dev->dev_ops->timesync_read_time)(dev,
 								timestamp));
@@ -5262,6 +5569,13 @@ rte_eth_timesync_write_time(uint16_t port_id, const struct timespec *timestamp)
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
 	dev = &rte_eth_devices[port_id];
 
+	if (timestamp == NULL) {
+		RTE_ETHDEV_LOG(ERR,
+			"Cannot write ethdev port %u timesync from NULL time\n",
+			port_id);
+		return -EINVAL;
+	}
+
 	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_write_time, -ENOTSUP);
 	return eth_err(port_id, (*dev->dev_ops->timesync_write_time)(dev,
 								timestamp));
@@ -5275,6 +5589,12 @@ rte_eth_read_clock(uint16_t port_id, uint64_t *clock)
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
 	dev = &rte_eth_devices[port_id];
 
+	if (clock == NULL) {
+		RTE_ETHDEV_LOG(ERR, "Cannot read ethdev port %u clock to NULL\n",
+			port_id);
+		return -EINVAL;
+	}
+
 	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->read_clock, -ENOTSUP);
 	return eth_err(port_id, (*dev->dev_ops->read_clock)(dev, clock));
 }
@@ -5285,10 +5605,15 @@ rte_eth_dev_get_reg_info(uint16_t port_id, struct rte_dev_reg_info *info)
 	struct rte_eth_dev *dev;
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
-	if (info == NULL)
+	dev = &rte_eth_devices[port_id];
+
+	if (info == NULL) {
+		RTE_ETHDEV_LOG(ERR,
+			"Cannot get ethdev port %u register info to NULL\n",
+			port_id);
 		return -EINVAL;
+	}
 
-	dev = &rte_eth_devices[port_id];
 	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_reg, -ENOTSUP);
 	return eth_err(port_id, (*dev->dev_ops->get_reg)(dev, info));
 }
@@ -5299,8 +5624,8 @@ rte_eth_dev_get_eeprom_length(uint16_t port_id)
 	struct rte_eth_dev *dev;
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
-
 	dev = &rte_eth_devices[port_id];
+
 	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_eeprom_length, -ENOTSUP);
 	return eth_err(port_id, (*dev->dev_ops->get_eeprom_length)(dev));
 }
@@ -5311,10 +5636,15 @@ rte_eth_dev_get_eeprom(uint16_t port_id, struct rte_dev_eeprom_info *info)
 	struct rte_eth_dev *dev;
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
-	if (info == NULL)
+	dev = &rte_eth_devices[port_id];
+
+	if (info == NULL) {
+		RTE_ETHDEV_LOG(ERR,
+			"Cannot get ethdev port %u EEPROM info to NULL\n",
+			port_id);
 		return -EINVAL;
+	}
 
-	dev = &rte_eth_devices[port_id];
 	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_eeprom, -ENOTSUP);
 	return eth_err(port_id, (*dev->dev_ops->get_eeprom)(dev, info));
 }
@@ -5325,10 +5655,15 @@ rte_eth_dev_set_eeprom(uint16_t port_id, struct rte_dev_eeprom_info *info)
 	struct rte_eth_dev *dev;
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
-	if (info == NULL)
+	dev = &rte_eth_devices[port_id];
+
+	if (info == NULL) {
+		RTE_ETHDEV_LOG(ERR,
+			"Cannot set ethdev port %u EEPROM from NULL info\n",
+			port_id);
 		return -EINVAL;
+	}
 
-	dev = &rte_eth_devices[port_id];
 	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_eeprom, -ENOTSUP);
 	return eth_err(port_id, (*dev->dev_ops->set_eeprom)(dev, info));
 }
@@ -5340,10 +5675,15 @@ rte_eth_dev_get_module_info(uint16_t port_id,
 	struct rte_eth_dev *dev;
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
-	if (modinfo == NULL)
+	dev = &rte_eth_devices[port_id];
+
+	if (modinfo == NULL) {
+		RTE_ETHDEV_LOG(ERR,
+			"Cannot get ethdev port %u EEPROM module info to NULL\n",
+			port_id);
 		return -EINVAL;
+	}
 
-	dev = &rte_eth_devices[port_id];
 	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_module_info, -ENOTSUP);
 	return (*dev->dev_ops->get_module_info)(dev, modinfo);
 }
@@ -5355,10 +5695,29 @@ rte_eth_dev_get_module_eeprom(uint16_t port_id,
 	struct rte_eth_dev *dev;
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
-	if (info == NULL || info->data == NULL || info->length == 0)
+	dev = &rte_eth_devices[port_id];
+
+	if (info == NULL) {
+		RTE_ETHDEV_LOG(ERR,
+			"Cannot get ethdev port %u module EEPROM info to NULL\n",
+			port_id);
 		return -EINVAL;
+	}
+
+	if (info->data == NULL) {
+		RTE_ETHDEV_LOG(ERR,
+			"Cannot get ethdev port %u module EEPROM data to NULL\n",
+			port_id);
+		return -EINVAL;
+	}
+
+	if (info->length == 0) {
+		RTE_ETHDEV_LOG(ERR,
+			"Cannot get ethdev port %u module EEPROM to data with zero size\n",
+			port_id);
+		return -EINVAL;
+	}
 
-	dev = &rte_eth_devices[port_id];
 	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_module_eeprom, -ENOTSUP);
 	return (*dev->dev_ops->get_module_eeprom)(dev, info);
 }
@@ -5370,8 +5729,15 @@ rte_eth_dev_get_dcb_info(uint16_t port_id,
 	struct rte_eth_dev *dev;
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
-
 	dev = &rte_eth_devices[port_id];
+
+	if (dcb_info == NULL) {
+		RTE_ETHDEV_LOG(ERR,
+			"Cannot get ethdev port %u DCB info to NULL\n",
+			port_id);
+		return -EINVAL;
+	}
+
 	memset(dcb_info, 0, sizeof(struct rte_eth_dcb_info));
 
 	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_dcb_info, -ENOTSUP);
@@ -5421,8 +5787,15 @@ rte_eth_dev_hairpin_capability_get(uint16_t port_id,
 	struct rte_eth_dev *dev;
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
-
 	dev = &rte_eth_devices[port_id];
+
+	if (cap == NULL) {
+		RTE_ETHDEV_LOG(ERR,
+			"Cannot get ethdev port %u hairpin capability to NULL\n",
+			port_id);
+		return -EINVAL;
+	}
+
 	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->hairpin_cap_get, -ENOTSUP);
 	memset(cap, 0, sizeof(*cap));
 	return eth_err(port_id, (*dev->dev_ops->hairpin_cap_get)(dev, cap));
@@ -5431,8 +5804,7 @@ rte_eth_dev_hairpin_capability_get(uint16_t port_id,
 int
 rte_eth_dev_is_rx_hairpin_queue(struct rte_eth_dev *dev, uint16_t queue_id)
 {
-	if (dev->data->rx_queue_state[queue_id] ==
-	    RTE_ETH_QUEUE_STATE_HAIRPIN)
+	if (dev->data->rx_queue_state[queue_id] == RTE_ETH_QUEUE_STATE_HAIRPIN)
 		return 1;
 	return 0;
 }
@@ -5440,8 +5812,7 @@ rte_eth_dev_is_rx_hairpin_queue(struct rte_eth_dev *dev, uint16_t queue_id)
 int
 rte_eth_dev_is_tx_hairpin_queue(struct rte_eth_dev *dev, uint16_t queue_id)
 {
-	if (dev->data->tx_queue_state[queue_id] ==
-	    RTE_ETH_QUEUE_STATE_HAIRPIN)
+	if (dev->data->tx_queue_state[queue_id] == RTE_ETH_QUEUE_STATE_HAIRPIN)
 		return 1;
 	return 0;
 }
@@ -5452,11 +5823,14 @@ rte_eth_dev_pool_ops_supported(uint16_t port_id, const char *pool)
 	struct rte_eth_dev *dev;
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
+	dev = &rte_eth_devices[port_id];
 
-	if (pool == NULL)
+	if (pool == NULL) {
+		RTE_ETHDEV_LOG(ERR,
+			"Cannot test ethdev port %u mempool operation from NULL pool\n",
+			port_id);
 		return -EINVAL;
-
-	dev = &rte_eth_devices[port_id];
+	}
 
 	if (*dev->dev_ops->pool_ops_supported == NULL)
 		return 1; /* all pools are supported */
@@ -5928,8 +6302,7 @@ rte_eth_representor_info_get(uint16_t port_id,
 	dev = &rte_eth_devices[port_id];
 
 	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->representor_info_get, -ENOTSUP);
-	return eth_err(port_id, (*dev->dev_ops->representor_info_get)(dev,
-								      info));
+	return eth_err(port_id, (*dev->dev_ops->representor_info_get)(dev, info));
 }
 
 RTE_LOG_REGISTER(rte_eth_dev_logtype, lib.ethdev, INFO);
diff --git a/lib/librte_ethdev/rte_ethdev.h b/lib/librte_ethdev/rte_ethdev.h
index a0d01d26675f..faf3bd901d75 100644
--- a/lib/librte_ethdev/rte_ethdev.h
+++ b/lib/librte_ethdev/rte_ethdev.h
@@ -2711,6 +2711,7 @@ int rte_eth_allmulticast_get(uint16_t port_id);
  *   - (0) if successful.
  *   - (-ENOTSUP) if the function is not supported in PMD driver.
  *   - (-ENODEV) if *port_id* invalid.
+ *   - (-EINVAL) if bad parameter.
  */
 int rte_eth_link_get(uint16_t port_id, struct rte_eth_link *link);
 
@@ -2726,6 +2727,7 @@ int rte_eth_link_get(uint16_t port_id, struct rte_eth_link *link);
  *   - (0) if successful.
  *   - (-ENOTSUP) if the function is not supported in PMD driver.
  *   - (-ENODEV) if *port_id* invalid.
+ *   - (-EINVAL) if bad parameter.
  */
 int rte_eth_link_get_nowait(uint16_t port_id, struct rte_eth_link *link);
 
@@ -2761,7 +2763,7 @@ const char *rte_eth_link_speed_to_str(uint32_t link_speed);
  * @param eth_link
  *   Link status returned by rte_eth_link_get function
  * @return
- *   Number of bytes written to str array.
+ *   Number of bytes written to str array or -EINVAL if bad parameter.
  */
 __rte_experimental
 int rte_eth_link_to_str(char *str, size_t len,
@@ -2934,6 +2936,7 @@ int rte_eth_xstats_get_by_id(uint16_t port_id, const uint64_t *ids,
  *    -ENODEV for invalid port_id,
  *    -EIO if device is removed,
  *    -EINVAL if the xstat_name doesn't exist in port_id
+ *    -ENOMEM if bad parameter.
  */
 int rte_eth_xstats_get_id_by_name(uint16_t port_id, const char *xstat_name,
 		uint64_t *id);
@@ -3006,6 +3009,7 @@ int rte_eth_dev_set_rx_queue_stats_mapping(uint16_t port_id,
  * @return
  *   - (0) if successful
  *   - (-ENODEV) if *port_id* invalid.
+ *   - (-EINVAL) if bad parameter.
  */
 int rte_eth_macaddr_get(uint16_t port_id, struct rte_ether_addr *mac_addr);
 
@@ -3050,6 +3054,7 @@ int rte_eth_macaddr_get(uint16_t port_id, struct rte_ether_addr *mac_addr);
  *   - (0) if successful.
  *   - (-ENOTSUP) if support for dev_infos_get() does not exist for the device.
  *   - (-ENODEV) if *port_id* invalid.
+ *   - (-EINVAL) if bad parameter.
  */
 int rte_eth_dev_info_get(uint16_t port_id, struct rte_eth_dev_info *dev_info);
 
@@ -3069,6 +3074,7 @@ int rte_eth_dev_info_get(uint16_t port_id, struct rte_eth_dev_info *dev_info);
  *   - (-ENOTSUP) if operation is not supported.
  *   - (-ENODEV) if *port_id* invalid.
  *   - (-EIO) if device is removed.
+ *   - (-EINVAL) if bad parameter.
  *   - (>0) if *fw_size* is not enough to store firmware version, return
  *          the size of the non truncated string.
  */
@@ -3112,6 +3118,7 @@ int rte_eth_dev_fw_version_get(uint16_t port_id,
  *           only num entries will be filled into the ptypes array, but the full
  *           count of supported ptypes will be returned.
  *   - (-ENODEV) if *port_id* invalid.
+ *   - (-EINVAL) if bad parameter.
  */
 int rte_eth_dev_get_supported_ptypes(uint16_t port_id, uint32_t ptype_mask,
 				     uint32_t *ptypes, int num);
@@ -3162,6 +3169,7 @@ int rte_eth_dev_set_ptypes(uint16_t port_id, uint32_t ptype_mask,
  * @return
  *   - (0) if successful.
  *   - (-ENODEV) if *port_id* invalid.
+ *   - (-EINVAL) if bad parameter.
  */
 int rte_eth_dev_get_mtu(uint16_t port_id, uint16_t *mtu);
 
@@ -3356,7 +3364,7 @@ rte_eth_tx_buffer_init(struct rte_eth_dev_tx_buffer *buffer, uint16_t size);
  * @param userdata
  *   Arbitrary parameter to be passed to the callback function
  * @return
- *   0 on success, or -1 on error with rte_errno set appropriately
+ *   0 on success, or -EINVAL if bad parameter
  */
 int
 rte_eth_tx_buffer_set_err_callback(struct rte_eth_dev_tx_buffer *buffer,
@@ -3783,6 +3791,7 @@ int rte_eth_fec_set(uint16_t port_id, uint32_t fec_capa);
  *   - (-ENOTSUP) if hardware doesn't support flow control.
  *   - (-ENODEV)  if *port_id* invalid.
  *   - (-EIO)  if device is removed.
+ *   - (-EINVAL) if bad parameter.
  */
 int rte_eth_dev_flow_ctrl_get(uint16_t port_id,
 			      struct rte_eth_fc_conf *fc_conf);
@@ -3854,7 +3863,8 @@ int rte_eth_dev_mac_addr_add(uint16_t port_id, struct rte_ether_addr *mac_addr,
  *   - (0) if successful, or *mac_addr* didn't exist.
  *   - (-ENOTSUP) if hardware doesn't support.
  *   - (-ENODEV) if *port* invalid.
- *   - (-EADDRINUSE) if attempting to remove the default MAC address
+ *   - (-EADDRINUSE) if attempting to remove the default MAC address.
+ *   - (-EINVAL) if MAC address is invalid.
  */
 int rte_eth_dev_mac_addr_remove(uint16_t port_id,
 				struct rte_ether_addr *mac_addr);
@@ -4053,6 +4063,7 @@ int rte_eth_dev_rss_hash_update(uint16_t port_id,
  *   - (-ENODEV) if port identifier is invalid.
  *   - (-EIO) if device is removed.
  *   - (-ENOTSUP) if hardware doesn't support RSS.
+ *   - (-EINVAL) if bad parameter.
  */
 int
 rte_eth_dev_rss_hash_conf_get(uint16_t port_id,
@@ -4121,6 +4132,7 @@ rte_eth_dev_udp_tunnel_port_delete(uint16_t port_id,
  *   - (-ENODEV) if port identifier is invalid.
  *   - (-EIO) if device is removed.
  *   - (-ENOTSUP) if hardware doesn't support.
+ *   - (-EINVAL) if bad parameter.
  */
 int rte_eth_dev_get_dcb_info(uint16_t port_id,
 			     struct rte_eth_dcb_info *dcb_info);
@@ -4533,6 +4545,7 @@ rte_eth_dev_get_module_eeprom(uint16_t port_id,
  *   - (-EIO) if device is removed.
  *   - (-ENOTSUP) if PMD of *port_id* doesn't support multicast filtering.
  *   - (-ENOSPC) if *port_id* has not enough multicast filtering resources.
+ *   - (-EINVAL) if bad parameter.
  */
 int rte_eth_dev_set_mc_addr_list(uint16_t port_id,
 				 struct rte_ether_addr *mc_addr_set,
@@ -4637,6 +4650,7 @@ int rte_eth_timesync_adjust_time(uint16_t port_id, int64_t delta);
  *
  * @return
  *   - 0: Success.
+ *   - -EINVAL: Bad parameter.
  */
 int rte_eth_timesync_read_time(uint16_t port_id, struct timespec *time);
 
@@ -4703,6 +4717,7 @@ int rte_eth_timesync_write_time(uint16_t port_id, const struct timespec *time);
  *   - 0: Success.
  *   - -ENODEV: The port ID is invalid.
  *   - -ENOTSUP: The function is not supported by the Ethernet driver.
+ *   - -EINVAL: if bad parameter.
  */
 __rte_experimental
 int
@@ -4806,6 +4821,7 @@ rte_eth_dev_get_sec_ctx(uint16_t port_id);
  * @return
  *   - (0) if successful.
  *   - (-ENOTSUP) if hardware doesn't support.
+ *   - (-EINVAL) if bad parameter.
  */
 __rte_experimental
 int rte_eth_dev_hairpin_capability_get(uint16_t port_id,
-- 
2.30.2


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [dpdk-stable] [PATCH v9] ethdev: add sanity checks in control APIs
  2021-04-21  2:36 ` [dpdk-stable] [PATCH v9] ethdev: add sanity checks in control APIs Ferruh Yigit
@ 2021-04-21 10:48   ` Thomas Monjalon
  2021-04-21 11:28   ` Andrew Rybchenko
  1 sibling, 0 replies; 10+ messages in thread
From: Thomas Monjalon @ 2021-04-21 10:48 UTC (permalink / raw)
  To: Ferruh Yigit, Min Hu (Connor)
  Cc: Andrew Rybchenko, Gaetan Rivet, Stephen Hemminger, dev, stable,
	Kevin Traynor

21/04/2021 04:36, Ferruh Yigit:
> From: "Min Hu (Connor)" <humin29@huawei.com>
> 
> This patch adds more sanity checks in control path APIs.
> 
> Fixes: 214ed1acd125 ("ethdev: add iterator to match devargs input")
> Fixes: 3d98f921fbe9 ("ethdev: unify prefix for static functions and variables")
> Fixes: 0366137722a0 ("ethdev: check for invalid device name")
> Fixes: d948f596fee2 ("ethdev: fix port data mismatched in multiple process model")
> Fixes: 5b7ba31148a8 ("ethdev: add port ownership")
> Fixes: f8244c6399d9 ("ethdev: increase port id range")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Min Hu (Connor) <humin29@huawei.com>
> Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
> Reviewed-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
> Acked-by: Kevin Traynor <ktraynor@redhat.com>
> ---
> 
> It seems I underestimated finding good log messages ;), not sure if they
> are complete, please comment, we can have more versions until they are
> good.

They are probably good enough.
Thanks for all the work.

Acked-by: Thomas Monjalon <thomas@monjalon.net>



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [dpdk-stable] [PATCH v9] ethdev: add sanity checks in control APIs
  2021-04-21  2:36 ` [dpdk-stable] [PATCH v9] ethdev: add sanity checks in control APIs Ferruh Yigit
  2021-04-21 10:48   ` Thomas Monjalon
@ 2021-04-21 11:28   ` Andrew Rybchenko
  2021-04-21 12:36     ` Min Hu (Connor)
                       ` (3 more replies)
  1 sibling, 4 replies; 10+ messages in thread
From: Andrew Rybchenko @ 2021-04-21 11:28 UTC (permalink / raw)
  To: Ferruh Yigit, Thomas Monjalon, Gaetan Rivet, Stephen Hemminger,
	Qi Zhang, Ali Alnubani, Yuanhan Liu, Matan Azrad,
	Konstantin Ananyev, Zhiyong Yang, Adrien Mazarguil
  Cc: dev, Min Hu (Connor), stable, Kevin Traynor

On 4/21/21 5:36 AM, Ferruh Yigit wrote:
> From: "Min Hu (Connor)" <humin29@huawei.com>
> 
> This patch adds more sanity checks in control path APIs.
> 
> Fixes: 214ed1acd125 ("ethdev: add iterator to match devargs input")
> Fixes: 3d98f921fbe9 ("ethdev: unify prefix for static functions and variables")
> Fixes: 0366137722a0 ("ethdev: check for invalid device name")
> Fixes: d948f596fee2 ("ethdev: fix port data mismatched in multiple process model")
> Fixes: 5b7ba31148a8 ("ethdev: add port ownership")
> Fixes: f8244c6399d9 ("ethdev: increase port id range")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Min Hu (Connor) <humin29@huawei.com>
> Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
> Reviewed-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
> Acked-by: Kevin Traynor <ktraynor@redhat.com>

Few nits below.
Other than that I confirm my "Reviewed-by".

The patch is really long. It would be better to split it into
few:
 - relocate dev assignment
 - empty lines mangling (when it is unrelated to previous item)
 - ops check before usage (combined with related style checks)
 - error logs refinement

However, since the patch is already reviewed this way, may
be it is better to push as is after review notes processing.

> @@ -817,7 +859,12 @@ rte_eth_dev_get_port_by_name(const char *name, uint16_t *port_id)
>  	uint16_t pid;
>  
>  	if (name == NULL) {
> -		RTE_ETHDEV_LOG(ERR, "Null pointer is specified\n");
> +		RTE_ETHDEV_LOG(ERR, "Cannot get port ID from NULL name");
> +		return -EINVAL;
> +	}
> +
> +	if (port_id == NULL) {
> +		RTE_ETHDEV_LOG(ERR, "Cannot get port ID to NULL\n");

Since name is already checked above, I think it would be useful
to log 'name' here to provide context.

>  		return -EINVAL;
>  	}
>  

[snip]

> @@ -3256,6 +3370,20 @@ rte_eth_dev_fw_version_get(uint16_t port_id, char *fw_version, size_t fw_size)
>  	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
>  	dev = &rte_eth_devices[port_id];
>  
> +	if (fw_version == NULL) {
> +		RTE_ETHDEV_LOG(ERR,
> +			"Cannot get ethdev port %u FW version to NULL\n",
> +			port_id);
> +		return -EINVAL;
> +	}
> +
> +	if (fw_size == 0) {
> +		RTE_ETHDEV_LOG(ERR,
> +			"Cannot get ethdev port %u FW version to buffer with zero size\n",
> +			port_id);
> +		return -EINVAL;
> +	}
> +

The only error condition is NULL fw_version with positive
fw_size. Othwerwise, it could be just a call to get required
size of buffer for FW version.

>  	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fw_version_get, -ENOTSUP);
>  	return eth_err(port_id, (*dev->dev_ops->fw_version_get)(dev,
>  							fw_version, fw_size));

[snip]

> @@ -3323,6 +3457,21 @@ rte_eth_dev_get_supported_ptypes(uint16_t port_id, uint32_t ptype_mask,
>  
>  	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
>  	dev = &rte_eth_devices[port_id];
> +
> +	if (ptypes == NULL) {
> +		RTE_ETHDEV_LOG(ERR,
> +			"Cannot get ethdev port %u supported packet types to NULL\n",
> +			port_id);
> +		return -EINVAL;
> +	}
> +
> +	if (num == 0) {
> +		RTE_ETHDEV_LOG(ERR,
> +			"Cannot get ethdev port %u supported packet types to array with zero size\n",
> +			port_id);
> +		return -EINVAL;
> +	}
> +

The error condition is "ptypes == NULL && num > 0".
Otherwise, if num == 0 (regardless ptypes) it is just
a call to get size of required buffer. Same as below.

>  	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_supported_ptypes_get, 0);
>  	all_ptypes = (*dev->dev_ops->dev_supported_ptypes_get)(dev);
>  

[snip]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [dpdk-stable] [PATCH v9] ethdev: add sanity checks in control APIs
  2021-04-21 11:28   ` Andrew Rybchenko
@ 2021-04-21 12:36     ` Min Hu (Connor)
  2021-04-21 12:38     ` Kevin Traynor
                       ` (2 subsequent siblings)
  3 siblings, 0 replies; 10+ messages in thread
From: Min Hu (Connor) @ 2021-04-21 12:36 UTC (permalink / raw)
  To: Andrew Rybchenko, Ferruh Yigit, Thomas Monjalon, Gaetan Rivet,
	Stephen Hemminger, Qi Zhang, Ali Alnubani, Yuanhan Liu,
	Matan Azrad, Konstantin Ananyev, Zhiyong Yang, Adrien Mazarguil
  Cc: dev, stable, Kevin Traynor

Hi, fixed in v10, thanks.

在 2021/4/21 19:28, Andrew Rybchenko 写道:
> On 4/21/21 5:36 AM, Ferruh Yigit wrote:
>> From: "Min Hu (Connor)" <humin29@huawei.com>
>>
>> This patch adds more sanity checks in control path APIs.
>>
>> Fixes: 214ed1acd125 ("ethdev: add iterator to match devargs input")
>> Fixes: 3d98f921fbe9 ("ethdev: unify prefix for static functions and variables")
>> Fixes: 0366137722a0 ("ethdev: check for invalid device name")
>> Fixes: d948f596fee2 ("ethdev: fix port data mismatched in multiple process model")
>> Fixes: 5b7ba31148a8 ("ethdev: add port ownership")
>> Fixes: f8244c6399d9 ("ethdev: increase port id range")
>> Cc: stable@dpdk.org
>>
>> Signed-off-by: Min Hu (Connor) <humin29@huawei.com>
>> Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
>> Reviewed-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
>> Acked-by: Kevin Traynor <ktraynor@redhat.com>
> 
> Few nits below.
> Other than that I confirm my "Reviewed-by".
> 
> The patch is really long. It would be better to split it into
> few:
>   - relocate dev assignment
>   - empty lines mangling (when it is unrelated to previous item)
>   - ops check before usage (combined with related style checks)
>   - error logs refinement
> 
> However, since the patch is already reviewed this way, may
> be it is better to push as is after review notes processing.
> 
>> @@ -817,7 +859,12 @@ rte_eth_dev_get_port_by_name(const char *name, uint16_t *port_id)
>>   	uint16_t pid;
>>   
>>   	if (name == NULL) {
>> -		RTE_ETHDEV_LOG(ERR, "Null pointer is specified\n");
>> +		RTE_ETHDEV_LOG(ERR, "Cannot get port ID from NULL name");
>> +		return -EINVAL;
>> +	}
>> +
>> +	if (port_id == NULL) {
>> +		RTE_ETHDEV_LOG(ERR, "Cannot get port ID to NULL\n");
> 
> Since name is already checked above, I think it would be useful
> to log 'name' here to provide context.
> 
>>   		return -EINVAL;
>>   	}
>>   
> 
> [snip]
> 
>> @@ -3256,6 +3370,20 @@ rte_eth_dev_fw_version_get(uint16_t port_id, char *fw_version, size_t fw_size)
>>   	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
>>   	dev = &rte_eth_devices[port_id];
>>   
>> +	if (fw_version == NULL) {
>> +		RTE_ETHDEV_LOG(ERR,
>> +			"Cannot get ethdev port %u FW version to NULL\n",
>> +			port_id);
>> +		return -EINVAL;
>> +	}
>> +
>> +	if (fw_size == 0) {
>> +		RTE_ETHDEV_LOG(ERR,
>> +			"Cannot get ethdev port %u FW version to buffer with zero size\n",
>> +			port_id);
>> +		return -EINVAL;
>> +	}
>> +
> 
> The only error condition is NULL fw_version with positive
> fw_size. Othwerwise, it could be just a call to get required
> size of buffer for FW version.
> 
>>   	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fw_version_get, -ENOTSUP);
>>   	return eth_err(port_id, (*dev->dev_ops->fw_version_get)(dev,
>>   							fw_version, fw_size));
> 
> [snip]
> 
>> @@ -3323,6 +3457,21 @@ rte_eth_dev_get_supported_ptypes(uint16_t port_id, uint32_t ptype_mask,
>>   
>>   	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
>>   	dev = &rte_eth_devices[port_id];
>> +
>> +	if (ptypes == NULL) {
>> +		RTE_ETHDEV_LOG(ERR,
>> +			"Cannot get ethdev port %u supported packet types to NULL\n",
>> +			port_id);
>> +		return -EINVAL;
>> +	}
>> +
>> +	if (num == 0) {
>> +		RTE_ETHDEV_LOG(ERR,
>> +			"Cannot get ethdev port %u supported packet types to array with zero size\n",
>> +			port_id);
>> +		return -EINVAL;
>> +	}
>> +
> 
> The error condition is "ptypes == NULL && num > 0".
> Otherwise, if num == 0 (regardless ptypes) it is just
> a call to get size of required buffer. Same as below.
> 
>>   	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_supported_ptypes_get, 0);
>>   	all_ptypes = (*dev->dev_ops->dev_supported_ptypes_get)(dev);
>>   
> 
> [snip]
> .
> 

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [dpdk-stable] [PATCH v9] ethdev: add sanity checks in control APIs
  2021-04-21 11:28   ` Andrew Rybchenko
  2021-04-21 12:36     ` Min Hu (Connor)
@ 2021-04-21 12:38     ` Kevin Traynor
  2021-04-21 13:19     ` Ferruh Yigit
  2021-04-21 14:17     ` Ferruh Yigit
  3 siblings, 0 replies; 10+ messages in thread
From: Kevin Traynor @ 2021-04-21 12:38 UTC (permalink / raw)
  To: Andrew Rybchenko, Ferruh Yigit, Thomas Monjalon, Gaetan Rivet,
	Stephen Hemminger, Qi Zhang, Ali Alnubani, Yuanhan Liu,
	Matan Azrad, Konstantin Ananyev, Zhiyong Yang, Adrien Mazarguil
  Cc: dev, Min Hu (Connor), stable

On 21/04/2021 12:28, Andrew Rybchenko wrote:
> On 4/21/21 5:36 AM, Ferruh Yigit wrote:
>> From: "Min Hu (Connor)" <humin29@huawei.com>
>>
>> This patch adds more sanity checks in control path APIs.
>>
>> Fixes: 214ed1acd125 ("ethdev: add iterator to match devargs input")
>> Fixes: 3d98f921fbe9 ("ethdev: unify prefix for static functions and variables")
>> Fixes: 0366137722a0 ("ethdev: check for invalid device name")
>> Fixes: d948f596fee2 ("ethdev: fix port data mismatched in multiple process model")
>> Fixes: 5b7ba31148a8 ("ethdev: add port ownership")
>> Fixes: f8244c6399d9 ("ethdev: increase port id range")
>> Cc: stable@dpdk.org
>>
>> Signed-off-by: Min Hu (Connor) <humin29@huawei.com>
>> Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
>> Reviewed-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
>> Acked-by: Kevin Traynor <ktraynor@redhat.com>
> 
> Few nits below.
> Other than that I confirm my "Reviewed-by".
> 
> The patch is really long. It would be better to split it into
> few:
>  - relocate dev assignment
>  - empty lines mangling (when it is unrelated to previous item)
>  - ops check before usage (combined with related style checks)
>  - error logs refinement
> 

+1

> However, since the patch is already reviewed this way, may
> be it is better to push as is after review notes processing.
> 
>> @@ -817,7 +859,12 @@ rte_eth_dev_get_port_by_name(const char *name, uint16_t *port_id)
>>  	uint16_t pid;
>>  
>>  	if (name == NULL) {
>> -		RTE_ETHDEV_LOG(ERR, "Null pointer is specified\n");
>> +		RTE_ETHDEV_LOG(ERR, "Cannot get port ID from NULL name");
>> +		return -EINVAL;
>> +	}
>> +
>> +	if (port_id == NULL) {
>> +		RTE_ETHDEV_LOG(ERR, "Cannot get port ID to NULL\n");
> 
> Since name is already checked above, I think it would be useful
> to log 'name' here to provide context.
> 
>>  		return -EINVAL;
>>  	}
>>  
> 
> [snip]
> 
>> @@ -3256,6 +3370,20 @@ rte_eth_dev_fw_version_get(uint16_t port_id, char *fw_version, size_t fw_size)
>>  	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
>>  	dev = &rte_eth_devices[port_id];
>>  
>> +	if (fw_version == NULL) {
>> +		RTE_ETHDEV_LOG(ERR,
>> +			"Cannot get ethdev port %u FW version to NULL\n",
>> +			port_id);
>> +		return -EINVAL;
>> +	}
>> +
>> +	if (fw_size == 0) {
>> +		RTE_ETHDEV_LOG(ERR,
>> +			"Cannot get ethdev port %u FW version to buffer with zero size\n",
>> +			port_id);
>> +		return -EINVAL;
>> +	}
>> +
> 
> The only error condition is NULL fw_version with positive
> fw_size. Othwerwise, it could be just a call to get required
> size of buffer for FW version.
> 
>>  	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fw_version_get, -ENOTSUP);
>>  	return eth_err(port_id, (*dev->dev_ops->fw_version_get)(dev,
>>  							fw_version, fw_size));
> 
> [snip]
> 
>> @@ -3323,6 +3457,21 @@ rte_eth_dev_get_supported_ptypes(uint16_t port_id, uint32_t ptype_mask,
>>  
>>  	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
>>  	dev = &rte_eth_devices[port_id];
>> +
>> +	if (ptypes == NULL) {
>> +		RTE_ETHDEV_LOG(ERR,
>> +			"Cannot get ethdev port %u supported packet types to NULL\n",
>> +			port_id);
>> +		return -EINVAL;
>> +	}
>> +
>> +	if (num == 0) {
>> +		RTE_ETHDEV_LOG(ERR,
>> +			"Cannot get ethdev port %u supported packet types to array with zero size\n",
>> +			port_id);
>> +		return -EINVAL;
>> +	}
>> +
> 
> The error condition is "ptypes == NULL && num > 0".
> Otherwise, if num == 0 (regardless ptypes) it is just
> a call to get size of required buffer. Same as below.
> 
>>  	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_supported_ptypes_get, 0);
>>  	all_ptypes = (*dev->dev_ops->dev_supported_ptypes_get)(dev);
>>  
> 

nice catch for these.

> [snip]
>






^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [dpdk-stable] [PATCH v9] ethdev: add sanity checks in control APIs
  2021-04-21 11:28   ` Andrew Rybchenko
  2021-04-21 12:36     ` Min Hu (Connor)
  2021-04-21 12:38     ` Kevin Traynor
@ 2021-04-21 13:19     ` Ferruh Yigit
  2021-04-21 13:40       ` [dpdk-stable] [dpdk-dev] " Ferruh Yigit
  2021-04-21 13:50       ` [dpdk-stable] " Andrew Rybchenko
  2021-04-21 14:17     ` Ferruh Yigit
  3 siblings, 2 replies; 10+ messages in thread
From: Ferruh Yigit @ 2021-04-21 13:19 UTC (permalink / raw)
  To: Andrew Rybchenko, Thomas Monjalon, Gaetan Rivet,
	Stephen Hemminger, Qi Zhang, Ali Alnubani, Yuanhan Liu,
	Matan Azrad, Konstantin Ananyev, Zhiyong Yang, Adrien Mazarguil
  Cc: dev, Min Hu (Connor), stable, Kevin Traynor

On 4/21/2021 12:28 PM, Andrew Rybchenko wrote:
> On 4/21/21 5:36 AM, Ferruh Yigit wrote:
>> From: "Min Hu (Connor)" <humin29@huawei.com>
>>
>> This patch adds more sanity checks in control path APIs.
>>
>> Fixes: 214ed1acd125 ("ethdev: add iterator to match devargs input")
>> Fixes: 3d98f921fbe9 ("ethdev: unify prefix for static functions and variables")
>> Fixes: 0366137722a0 ("ethdev: check for invalid device name")
>> Fixes: d948f596fee2 ("ethdev: fix port data mismatched in multiple process model")
>> Fixes: 5b7ba31148a8 ("ethdev: add port ownership")
>> Fixes: f8244c6399d9 ("ethdev: increase port id range")
>> Cc: stable@dpdk.org
>>
>> Signed-off-by: Min Hu (Connor) <humin29@huawei.com>
>> Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
>> Reviewed-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
>> Acked-by: Kevin Traynor <ktraynor@redhat.com>
> 
> Few nits below.
> Other than that I confirm my "Reviewed-by".
> 
> The patch is really long. It would be better to split it into
> few:
>   - relocate dev assignment
>   - empty lines mangling (when it is unrelated to previous item)
>   - ops check before usage (combined with related style checks)
>   - error logs refinement
> 
> However, since the patch is already reviewed this way, may
> be it is better to push as is after review notes processing.
> 
>> @@ -817,7 +859,12 @@ rte_eth_dev_get_port_by_name(const char *name, uint16_t *port_id)
>>   	uint16_t pid;
>>   
>>   	if (name == NULL) {
>> -		RTE_ETHDEV_LOG(ERR, "Null pointer is specified\n");
>> +		RTE_ETHDEV_LOG(ERR, "Cannot get port ID from NULL name");
>> +		return -EINVAL;
>> +	}
>> +
>> +	if (port_id == NULL) {
>> +		RTE_ETHDEV_LOG(ERR, "Cannot get port ID to NULL\n");
> 
> Since name is already checked above, I think it would be useful
> to log 'name' here to provide context.
> 
>>   		return -EINVAL;
>>   	}
>>   
> 
> [snip]
> 
>> @@ -3256,6 +3370,20 @@ rte_eth_dev_fw_version_get(uint16_t port_id, char *fw_version, size_t fw_size)
>>   	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
>>   	dev = &rte_eth_devices[port_id];
>>   
>> +	if (fw_version == NULL) {
>> +		RTE_ETHDEV_LOG(ERR,
>> +			"Cannot get ethdev port %u FW version to NULL\n",
>> +			port_id);
>> +		return -EINVAL;
>> +	}
>> +
>> +	if (fw_size == 0) {
>> +		RTE_ETHDEV_LOG(ERR,
>> +			"Cannot get ethdev port %u FW version to buffer with zero size\n",
>> +			port_id);
>> +		return -EINVAL;
>> +	}
>> +
> 
> The only error condition is NULL fw_version with positive
> fw_size. Othwerwise, it could be just a call to get required
> size of buffer for FW version.
> 

Right, above is wrong.

Agree that "fw_version == NULL && fw_size > 0" is error condition,
but is it clear if how this API should behave on
"fw_version == NULL && fw_size == 0"?

Like sfc has following,
  if ((fw_version == NULL) || (fw_size == 0))
  	return -EINVAL;

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [dpdk-stable] [dpdk-dev] [PATCH v9] ethdev: add sanity checks in control APIs
  2021-04-21 13:19     ` Ferruh Yigit
@ 2021-04-21 13:40       ` Ferruh Yigit
  2021-04-21 13:50         ` Andrew Rybchenko
  2021-04-21 13:50       ` [dpdk-stable] " Andrew Rybchenko
  1 sibling, 1 reply; 10+ messages in thread
From: Ferruh Yigit @ 2021-04-21 13:40 UTC (permalink / raw)
  To: Andrew Rybchenko, Thomas Monjalon, Gaetan Rivet,
	Stephen Hemminger, Qi Zhang, Ali Alnubani, Yuanhan Liu,
	Matan Azrad, Konstantin Ananyev, Zhiyong Yang, Adrien Mazarguil
  Cc: dev, Min Hu (Connor), stable, Kevin Traynor

On 4/21/2021 2:19 PM, Ferruh Yigit wrote:
> On 4/21/2021 12:28 PM, Andrew Rybchenko wrote:
>> On 4/21/21 5:36 AM, Ferruh Yigit wrote:
>>> From: "Min Hu (Connor)" <humin29@huawei.com>
>>>
>>> This patch adds more sanity checks in control path APIs.
>>>
>>> Fixes: 214ed1acd125 ("ethdev: add iterator to match devargs input")
>>> Fixes: 3d98f921fbe9 ("ethdev: unify prefix for static functions and variables")
>>> Fixes: 0366137722a0 ("ethdev: check for invalid device name")
>>> Fixes: d948f596fee2 ("ethdev: fix port data mismatched in multiple process 
>>> model")
>>> Fixes: 5b7ba31148a8 ("ethdev: add port ownership")
>>> Fixes: f8244c6399d9 ("ethdev: increase port id range")
>>> Cc: stable@dpdk.org
>>>
>>> Signed-off-by: Min Hu (Connor) <humin29@huawei.com>
>>> Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
>>> Reviewed-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
>>> Acked-by: Kevin Traynor <ktraynor@redhat.com>
>>
>> Few nits below.
>> Other than that I confirm my "Reviewed-by".
>>
>> The patch is really long. It would be better to split it into
>> few:
>>   - relocate dev assignment
>>   - empty lines mangling (when it is unrelated to previous item)
>>   - ops check before usage (combined with related style checks)
>>   - error logs refinement
>>
>> However, since the patch is already reviewed this way, may
>> be it is better to push as is after review notes processing.
>>
>>> @@ -817,7 +859,12 @@ rte_eth_dev_get_port_by_name(const char *name, uint16_t 
>>> *port_id)
>>>       uint16_t pid;
>>>       if (name == NULL) {
>>> -        RTE_ETHDEV_LOG(ERR, "Null pointer is specified\n");
>>> +        RTE_ETHDEV_LOG(ERR, "Cannot get port ID from NULL name");
>>> +        return -EINVAL;
>>> +    }
>>> +
>>> +    if (port_id == NULL) {
>>> +        RTE_ETHDEV_LOG(ERR, "Cannot get port ID to NULL\n");
>>
>> Since name is already checked above, I think it would be useful
>> to log 'name' here to provide context.
>>
>>>           return -EINVAL;
>>>       }
>>
>> [snip]
>>
>>> @@ -3256,6 +3370,20 @@ rte_eth_dev_fw_version_get(uint16_t port_id, char 
>>> *fw_version, size_t fw_size)
>>>       RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
>>>       dev = &rte_eth_devices[port_id];
>>> +    if (fw_version == NULL) {
>>> +        RTE_ETHDEV_LOG(ERR,
>>> +            "Cannot get ethdev port %u FW version to NULL\n",
>>> +            port_id);
>>> +        return -EINVAL;
>>> +    }
>>> +
>>> +    if (fw_size == 0) {
>>> +        RTE_ETHDEV_LOG(ERR,
>>> +            "Cannot get ethdev port %u FW version to buffer with zero size\n",
>>> +            port_id);
>>> +        return -EINVAL;
>>> +    }
>>> +
>>
>> The only error condition is NULL fw_version with positive
>> fw_size. Othwerwise, it could be just a call to get required
>> size of buffer for FW version.
>>
> 
> Right, above is wrong.
> 
> Agree that "fw_version == NULL && fw_size > 0" is error condition,
> but is it clear if how this API should behave on
> "fw_version == NULL && fw_size == 0"?
> 
> Like sfc has following,
> if ((fw_version == NULL) || (fw_size == 0))
>      return -EINVAL;

axgbe, qede also returns error when fw_version is NULL, independent from fw_size.

But I think taking "fw_version == NULL && fw_size > 0" as only error condition 
is reasonable, although some PMDs will be behaving wrong.
I can send a separate patch to unify the behavior.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [dpdk-stable] [PATCH v9] ethdev: add sanity checks in control APIs
  2021-04-21 13:19     ` Ferruh Yigit
  2021-04-21 13:40       ` [dpdk-stable] [dpdk-dev] " Ferruh Yigit
@ 2021-04-21 13:50       ` Andrew Rybchenko
  1 sibling, 0 replies; 10+ messages in thread
From: Andrew Rybchenko @ 2021-04-21 13:50 UTC (permalink / raw)
  To: Ferruh Yigit, Thomas Monjalon, Gaetan Rivet, Stephen Hemminger,
	Qi Zhang, Ali Alnubani, Yuanhan Liu, Matan Azrad,
	Konstantin Ananyev, Zhiyong Yang, Adrien Mazarguil
  Cc: dev, Min Hu (Connor), stable, Kevin Traynor

On 4/21/21 4:19 PM, Ferruh Yigit wrote:
> On 4/21/2021 12:28 PM, Andrew Rybchenko wrote:
>> On 4/21/21 5:36 AM, Ferruh Yigit wrote:
>>> From: "Min Hu (Connor)" <humin29@huawei.com>
>>>
>>> This patch adds more sanity checks in control path APIs.
>>>
>>> Fixes: 214ed1acd125 ("ethdev: add iterator to match devargs input")
>>> Fixes: 3d98f921fbe9 ("ethdev: unify prefix for static functions and
>>> variables")
>>> Fixes: 0366137722a0 ("ethdev: check for invalid device name")
>>> Fixes: d948f596fee2 ("ethdev: fix port data mismatched in multiple
>>> process model")
>>> Fixes: 5b7ba31148a8 ("ethdev: add port ownership")
>>> Fixes: f8244c6399d9 ("ethdev: increase port id range")
>>> Cc: stable@dpdk.org
>>>
>>> Signed-off-by: Min Hu (Connor) <humin29@huawei.com>
>>> Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
>>> Reviewed-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
>>> Acked-by: Kevin Traynor <ktraynor@redhat.com>
>>
>> Few nits below.
>> Other than that I confirm my "Reviewed-by".
>>
>> The patch is really long. It would be better to split it into
>> few:
>>   - relocate dev assignment
>>   - empty lines mangling (when it is unrelated to previous item)
>>   - ops check before usage (combined with related style checks)
>>   - error logs refinement
>>
>> However, since the patch is already reviewed this way, may
>> be it is better to push as is after review notes processing.
>>
>>> @@ -817,7 +859,12 @@ rte_eth_dev_get_port_by_name(const char *name,
>>> uint16_t *port_id)
>>>       uint16_t pid;
>>>         if (name == NULL) {
>>> -        RTE_ETHDEV_LOG(ERR, "Null pointer is specified\n");
>>> +        RTE_ETHDEV_LOG(ERR, "Cannot get port ID from NULL name");
>>> +        return -EINVAL;
>>> +    }
>>> +
>>> +    if (port_id == NULL) {
>>> +        RTE_ETHDEV_LOG(ERR, "Cannot get port ID to NULL\n");
>>
>> Since name is already checked above, I think it would be useful
>> to log 'name' here to provide context.
>>
>>>           return -EINVAL;
>>>       }
>>>   
>>
>> [snip]
>>
>>> @@ -3256,6 +3370,20 @@ rte_eth_dev_fw_version_get(uint16_t port_id,
>>> char *fw_version, size_t fw_size)
>>>       RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
>>>       dev = &rte_eth_devices[port_id];
>>>   +    if (fw_version == NULL) {
>>> +        RTE_ETHDEV_LOG(ERR,
>>> +            "Cannot get ethdev port %u FW version to NULL\n",
>>> +            port_id);
>>> +        return -EINVAL;
>>> +    }
>>> +
>>> +    if (fw_size == 0) {
>>> +        RTE_ETHDEV_LOG(ERR,
>>> +            "Cannot get ethdev port %u FW version to buffer with
>>> zero size\n",
>>> +            port_id);
>>> +        return -EINVAL;
>>> +    }
>>> +
>>
>> The only error condition is NULL fw_version with positive
>> fw_size. Othwerwise, it could be just a call to get required
>> size of buffer for FW version.
>>
>
> Right, above is wrong.
>
> Agree that "fw_version == NULL && fw_size > 0" is error condition,
> but is it clear if how this API should behave on
> "fw_version == NULL && fw_size == 0"?
>
> Like sfc has following,
> if ((fw_version == NULL) || (fw_size == 0))
>     return -EINVAL;

It looks like net/sfc is buggy here. My review notes are based on
rte_eth_dev_fw_version_get() return values description.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [dpdk-stable] [dpdk-dev] [PATCH v9] ethdev: add sanity checks in control APIs
  2021-04-21 13:40       ` [dpdk-stable] [dpdk-dev] " Ferruh Yigit
@ 2021-04-21 13:50         ` Andrew Rybchenko
  0 siblings, 0 replies; 10+ messages in thread
From: Andrew Rybchenko @ 2021-04-21 13:50 UTC (permalink / raw)
  To: Ferruh Yigit, Thomas Monjalon, Gaetan Rivet, Stephen Hemminger,
	Qi Zhang, Ali Alnubani, Yuanhan Liu, Matan Azrad,
	Konstantin Ananyev, Zhiyong Yang, Adrien Mazarguil
  Cc: dev, Min Hu (Connor), stable, Kevin Traynor

On 4/21/21 4:40 PM, Ferruh Yigit wrote:
> On 4/21/2021 2:19 PM, Ferruh Yigit wrote:
>> On 4/21/2021 12:28 PM, Andrew Rybchenko wrote:
>>> On 4/21/21 5:36 AM, Ferruh Yigit wrote:
>>>> From: "Min Hu (Connor)" <humin29@huawei.com>
>>>>
>>>> This patch adds more sanity checks in control path APIs.
>>>>
>>>> Fixes: 214ed1acd125 ("ethdev: add iterator to match devargs input")
>>>> Fixes: 3d98f921fbe9 ("ethdev: unify prefix for static functions and
>>>> variables")
>>>> Fixes: 0366137722a0 ("ethdev: check for invalid device name")
>>>> Fixes: d948f596fee2 ("ethdev: fix port data mismatched in multiple
>>>> process model")
>>>> Fixes: 5b7ba31148a8 ("ethdev: add port ownership")
>>>> Fixes: f8244c6399d9 ("ethdev: increase port id range")
>>>> Cc: stable@dpdk.org
>>>>
>>>> Signed-off-by: Min Hu (Connor) <humin29@huawei.com>
>>>> Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
>>>> Reviewed-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
>>>> Acked-by: Kevin Traynor <ktraynor@redhat.com>
>>>
>>> Few nits below.
>>> Other than that I confirm my "Reviewed-by".
>>>
>>> The patch is really long. It would be better to split it into
>>> few:
>>>   - relocate dev assignment
>>>   - empty lines mangling (when it is unrelated to previous item)
>>>   - ops check before usage (combined with related style checks)
>>>   - error logs refinement
>>>
>>> However, since the patch is already reviewed this way, may
>>> be it is better to push as is after review notes processing.
>>>
>>>> @@ -817,7 +859,12 @@ rte_eth_dev_get_port_by_name(const char *name,
>>>> uint16_t *port_id)
>>>>       uint16_t pid;
>>>>       if (name == NULL) {
>>>> -        RTE_ETHDEV_LOG(ERR, "Null pointer is specified\n");
>>>> +        RTE_ETHDEV_LOG(ERR, "Cannot get port ID from NULL name");
>>>> +        return -EINVAL;
>>>> +    }
>>>> +
>>>> +    if (port_id == NULL) {
>>>> +        RTE_ETHDEV_LOG(ERR, "Cannot get port ID to NULL\n");
>>>
>>> Since name is already checked above, I think it would be useful
>>> to log 'name' here to provide context.
>>>
>>>>           return -EINVAL;
>>>>       }
>>>
>>> [snip]
>>>
>>>> @@ -3256,6 +3370,20 @@ rte_eth_dev_fw_version_get(uint16_t port_id,
>>>> char *fw_version, size_t fw_size)
>>>>       RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
>>>>       dev = &rte_eth_devices[port_id];
>>>> +    if (fw_version == NULL) {
>>>> +        RTE_ETHDEV_LOG(ERR,
>>>> +            "Cannot get ethdev port %u FW version to NULL\n",
>>>> +            port_id);
>>>> +        return -EINVAL;
>>>> +    }
>>>> +
>>>> +    if (fw_size == 0) {
>>>> +        RTE_ETHDEV_LOG(ERR,
>>>> +            "Cannot get ethdev port %u FW version to buffer with
>>>> zero size\n",
>>>> +            port_id);
>>>> +        return -EINVAL;
>>>> +    }
>>>> +
>>>
>>> The only error condition is NULL fw_version with positive
>>> fw_size. Othwerwise, it could be just a call to get required
>>> size of buffer for FW version.
>>>
>>
>> Right, above is wrong.
>>
>> Agree that "fw_version == NULL && fw_size > 0" is error condition,
>> but is it clear if how this API should behave on
>> "fw_version == NULL && fw_size == 0"?
>>
>> Like sfc has following,
>> if ((fw_version == NULL) || (fw_size == 0))
>>      return -EINVAL;
> 
> axgbe, qede also returns error when fw_version is NULL, independent from
> fw_size.
> 
> But I think taking "fw_version == NULL && fw_size > 0" as only error
> condition is reasonable, although some PMDs will be behaving wrong.
> I can send a separate patch to unify the behavior.

Many thanks, please, let me know if you need help with net/sfc.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [dpdk-stable] [PATCH v9] ethdev: add sanity checks in control APIs
  2021-04-21 11:28   ` Andrew Rybchenko
                       ` (2 preceding siblings ...)
  2021-04-21 13:19     ` Ferruh Yigit
@ 2021-04-21 14:17     ` Ferruh Yigit
  3 siblings, 0 replies; 10+ messages in thread
From: Ferruh Yigit @ 2021-04-21 14:17 UTC (permalink / raw)
  To: Andrew Rybchenko, Thomas Monjalon, Gaetan Rivet,
	Stephen Hemminger, Qi Zhang, Ali Alnubani, Yuanhan Liu,
	Matan Azrad, Konstantin Ananyev, Zhiyong Yang, Adrien Mazarguil
  Cc: dev, Min Hu (Connor), stable, Kevin Traynor

On 4/21/2021 12:28 PM, Andrew Rybchenko wrote:
> On 4/21/21 5:36 AM, Ferruh Yigit wrote:
>> From: "Min Hu (Connor)" <humin29@huawei.com>
>>
>> This patch adds more sanity checks in control path APIs.
>>
>> Fixes: 214ed1acd125 ("ethdev: add iterator to match devargs input")
>> Fixes: 3d98f921fbe9 ("ethdev: unify prefix for static functions and variables")
>> Fixes: 0366137722a0 ("ethdev: check for invalid device name")
>> Fixes: d948f596fee2 ("ethdev: fix port data mismatched in multiple process model")
>> Fixes: 5b7ba31148a8 ("ethdev: add port ownership")
>> Fixes: f8244c6399d9 ("ethdev: increase port id range")
>> Cc: stable@dpdk.org
>>
>> Signed-off-by: Min Hu (Connor) <humin29@huawei.com>
>> Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
>> Reviewed-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
>> Acked-by: Kevin Traynor <ktraynor@redhat.com>

<...>

>> @@ -3323,6 +3457,21 @@ rte_eth_dev_get_supported_ptypes(uint16_t port_id, uint32_t ptype_mask,
>>   
>>   	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
>>   	dev = &rte_eth_devices[port_id];
>> +
>> +	if (ptypes == NULL) {
>> +		RTE_ETHDEV_LOG(ERR,
>> +			"Cannot get ethdev port %u supported packet types to NULL\n",
>> +			port_id);
>> +		return -EINVAL;
>> +	}
>> +
>> +	if (num == 0) {
>> +		RTE_ETHDEV_LOG(ERR,
>> +			"Cannot get ethdev port %u supported packet types to array with zero size\n",
>> +			port_id);
>> +		return -EINVAL;
>> +	}
>> +
> 
> The error condition is "ptypes == NULL && num > 0".
> Otherwise, if num == 0 (regardless ptypes) it is just
> a call to get size of required buffer. Same as below.
> 
>>   	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_supported_ptypes_get, 0);
>>   	all_ptypes = (*dev->dev_ops->dev_supported_ptypes_get)(dev);
>>   
> 

Ack. Thanks for catching these issues.


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2021-04-21 14:17 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <1618645179-11582-1-git-send-email-humin29@huawei.com>
2021-04-21  2:36 ` [dpdk-stable] [PATCH v9] ethdev: add sanity checks in control APIs Ferruh Yigit
2021-04-21 10:48   ` Thomas Monjalon
2021-04-21 11:28   ` Andrew Rybchenko
2021-04-21 12:36     ` Min Hu (Connor)
2021-04-21 12:38     ` Kevin Traynor
2021-04-21 13:19     ` Ferruh Yigit
2021-04-21 13:40       ` [dpdk-stable] [dpdk-dev] " Ferruh Yigit
2021-04-21 13:50         ` Andrew Rybchenko
2021-04-21 13:50       ` [dpdk-stable] " Andrew Rybchenko
2021-04-21 14:17     ` Ferruh Yigit

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).