Blame SOURCES/0001-Fix-cmd_fd-leak-in-mlx5_alloc_context.patch

3bcb62
From 169d050bc82a519fdc28f83bb685d86804383f0b Mon Sep 17 00:00:00 2001
3bcb62
From: Greg Inozemtsev <greg@purestorage.com>
3bcb62
Date: Tue, 27 Oct 2020 11:24:30 -0700
3bcb62
Subject: [PATCH] Fix cmd_fd leak in mlx5_alloc_context
3bcb62
MIME-Version: 1.0
3bcb62
Content-Type: text/plain; charset=UTF-8
3bcb62
Content-Transfer-Encoding: 8bit
3bcb62
3bcb62
The alloc_context function is supposed to take ownership of cmd_fd
3bcb62
and close it if it fails and returns NULL.  This was not done in
3bcb62
early exit error paths from mlx5_init_context (called from mlx5_alloc_context).
3bcb62
3bcb62
Fixes: cb3be404fadc (“mlx5: Refactor mlx5_alloc_context()”)
3bcb62
Signed-off-by: Greg Inozemtsev <greg@purestorage.com>
3bcb62
---
3bcb62
 providers/mlx5/mlx5.c | 28 ++++++++++++++--------------
3bcb62
 1 file changed, 14 insertions(+), 14 deletions(-)
3bcb62
3bcb62
diff --git a/providers/mlx5/mlx5.c b/providers/mlx5/mlx5.c
3bcb62
index 0a091f5b6b49..551560d561fe 100644
3bcb62
--- a/providers/mlx5/mlx5.c
3bcb62
+++ b/providers/mlx5/mlx5.c
3bcb62
@@ -1334,25 +1334,14 @@ static void mlx5_uninit_context(struct mlx5_context *context)
3bcb62
 }
3bcb62
 
3bcb62
 static struct mlx5_context *mlx5_init_context(struct ibv_device *ibdev,
3bcb62
-						int cmd_fd,
3bcb62
-						void *private_data)
3bcb62
+						int cmd_fd)
3bcb62
 {
3bcb62
-	struct mlx5dv_context_attr *ctx_attr = private_data;
3bcb62
 	struct mlx5_device *mdev = to_mdev(ibdev);
3bcb62
 	struct mlx5_context *context;
3bcb62
 	int low_lat_uuars;
3bcb62
 	int tot_uuars;
3bcb62
 	int ret;
3bcb62
 
3bcb62
-	if (ctx_attr && ctx_attr->comp_mask) {
3bcb62
-		errno = EINVAL;
3bcb62
-		return NULL;
3bcb62
-	}
3bcb62
-
3bcb62
-	ret = get_uar_info(mdev, &tot_uuars, &low_lat_uuars);
3bcb62
-	if (ret)
3bcb62
-		return NULL;
3bcb62
-
3bcb62
 	context = verbs_init_and_alloc_context(ibdev, cmd_fd, context, ibv_ctx,
3bcb62
 					       RDMA_DRIVER_MLX5);
3bcb62
 	if (!context)
3bcb62
@@ -1365,6 +1354,12 @@ static struct mlx5_context *mlx5_init_context(struct ibv_device *ibdev,
3bcb62
 		strcpy(context->hostname, "host_unknown");
3bcb62
 
3bcb62
 	mlx5_single_threaded = single_threaded_app();
3bcb62
+
3bcb62
+	ret = get_uar_info(mdev, &tot_uuars, &low_lat_uuars);
3bcb62
+	if (ret) {
3bcb62
+		mlx5_uninit_context(context);
3bcb62
+		return NULL;
3bcb62
+	}
3bcb62
 	context->tot_uuars = tot_uuars;
3bcb62
 	context->low_lat_uuars = low_lat_uuars;
3bcb62
 
3bcb62
@@ -1569,10 +1564,15 @@ static struct verbs_context *mlx5_alloc_context(struct ibv_device *ibdev,
3bcb62
 	bool				always_devx = false;
3bcb62
 	int ret;
3bcb62
 
3bcb62
-	context = mlx5_init_context(ibdev, cmd_fd, NULL);
3bcb62
+	context = mlx5_init_context(ibdev, cmd_fd);
3bcb62
 	if (!context)
3bcb62
 		return NULL;
3bcb62
 
3bcb62
+	if (ctx_attr && ctx_attr->comp_mask) {
3bcb62
+		errno = EINVAL;
3bcb62
+		goto err;
3bcb62
+	}
3bcb62
+
3bcb62
 	req.total_num_bfregs = context->tot_uuars;
3bcb62
 	req.num_low_latency_bfregs = context->low_lat_uuars;
3bcb62
 	req.max_cqe_version = MLX5_CQE_VERSION_V1;
3bcb62
@@ -1627,7 +1627,7 @@ static struct verbs_context *mlx5_import_context(struct ibv_device *ibdev,
3bcb62
 	struct mlx5_context *mctx;
3bcb62
 	int ret;
3bcb62
 
3bcb62
-	mctx = mlx5_init_context(ibdev, cmd_fd, NULL);
3bcb62
+	mctx = mlx5_init_context(ibdev, cmd_fd);
3bcb62
 	if (!mctx)
3bcb62
 		return NULL;
3bcb62
 
3bcb62
-- 
3bcb62
2.25.4
3bcb62