[03/12] net/mlx5: allocate device list explicitly

Message ID 1569398015-6027-4-git-send-email-viacheslavo@mellanox.com (mailing list archive)
State Accepted, archived
Delegated to: Raslan Darawsheh
Headers
Series net/mlx5: add bonding configuration support |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Slava Ovsiienko Sept. 25, 2019, 7:53 a.m. UTC
  At device probing the device list to spawn was allocated
as dynamic size local variable. It was no possible to have
one unified exit point from routine due to compiler warnings.
This patch allocates the spawn device list directly with
rte_zmalloc() and it is possible to goto to unified exit
label from anywhere of the routine.

Signed-off-by: Viacheslav Ovsiienko <viacheslavo@mellanox.com>
---
 drivers/net/mlx5/mlx5.c | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)
  

Patch

diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c
index dd8159c..701da7e 100644
--- a/drivers/net/mlx5/mlx5.c
+++ b/drivers/net/mlx5/mlx5.c
@@ -2154,6 +2154,7 @@  struct mlx5_dev_spawn_data {
 	 * Actually this is the number of iterations to spawn.
 	 */
 	unsigned int ns = 0;
+	struct mlx5_dev_spawn_data *list = NULL;
 	struct mlx5_dev_config dev_config;
 	int ret;
 
@@ -2176,8 +2177,8 @@  struct mlx5_dev_spawn_data {
 	 * matching ones, gathering into the list.
 	 */
 	struct ibv_device *ibv_match[ret + 1];
-	int nl_route = -1;
-	int nl_rdma = -1;
+	int nl_route = mlx5_nl_init(NETLINK_ROUTE);
+	int nl_rdma = mlx5_nl_init(NETLINK_RDMA);
 	unsigned int i;
 
 	while (ret-- > 0) {
@@ -2199,7 +2200,6 @@  struct mlx5_dev_spawn_data {
 	ibv_match[nd] = NULL;
 	if (!nd) {
 		/* No device matches, just complain and bail out. */
-		mlx5_glue->free_device_list(ibv_list);
 		DRV_LOG(WARNING,
 			"no Verbs device matches PCI device " PCI_PRI_FMT ","
 			" are kernel drivers loaded?",
@@ -2207,10 +2207,8 @@  struct mlx5_dev_spawn_data {
 			pci_dev->addr.devid, pci_dev->addr.function);
 		rte_errno = ENOENT;
 		ret = -rte_errno;
-		return ret;
+		goto exit;
 	}
-	nl_route = mlx5_nl_init(NETLINK_ROUTE);
-	nl_rdma = mlx5_nl_init(NETLINK_RDMA);
 	if (nd == 1) {
 		/*
 		 * Found single matching device may have multiple ports.
@@ -2227,8 +2225,16 @@  struct mlx5_dev_spawn_data {
 	 * Now we can determine the maximal
 	 * amount of devices to be spawned.
 	 */
-	struct mlx5_dev_spawn_data list[np ? np : nd];
-
+	list = rte_zmalloc("device spawn data",
+			 sizeof(struct mlx5_dev_spawn_data) *
+			 (np ? np : nd),
+			 RTE_CACHE_LINE_SIZE);
+	if (!list) {
+		DRV_LOG(ERR, "spawn data array allocation failure");
+		rte_errno = ENOMEM;
+		ret = -rte_errno;
+		goto exit;
+	}
 	if (np > 1) {
 		/*
 		 * Single IB device with multiple ports found,
@@ -2477,12 +2483,15 @@  struct mlx5_dev_spawn_data {
 	/*
 	 * Do the routine cleanup:
 	 * - close opened Netlink sockets
+	 * - free allocated spawn data array
 	 * - free the Infiniband device list
 	 */
 	if (nl_rdma >= 0)
 		close(nl_rdma);
 	if (nl_route >= 0)
 		close(nl_route);
+	if (list)
+		rte_free(list);
 	assert(ibv_list);
 	mlx5_glue->free_device_list(ibv_list);
 	return ret;