Skip to content

Commit 9b7d4be

Browse files
maorgottliebrleon
authored andcommitted
RDMA/mlx5: Fix UMR cleanup on error flow of driver init
The cited commit removed from the cleanup flow of umr the checks if the resources were created. This could lead to null-ptr-deref in case that we had failure in mlx5_ib_stage_ib_reg_init stage. Fix it by adding new state to the umr that can say if the resources were created or not and check it in the umr cleanup flow before destroying the resources. Fixes: 04876c1 ("RDMA/mlx5: Move init and cleanup of UMR to umr.c") Reviewed-by: Michael Guralnik <[email protected]> Signed-off-by: Maor Gottlieb <[email protected]> Link: https://lore.kernel.org/r/4cfa61386cf202e9ce330e8d228ce3b25a36326e.1661763459.git.leonro@nvidia.com Signed-off-by: Leon Romanovsky <[email protected]>
1 parent 74b30b3 commit 9b7d4be

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

drivers/infiniband/hw/mlx5/mlx5_ib.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,7 @@ struct mlx5_ib_umr_context {
708708
};
709709

710710
enum {
711+
MLX5_UMR_STATE_UNINIT,
711712
MLX5_UMR_STATE_ACTIVE,
712713
MLX5_UMR_STATE_RECOVER,
713714
MLX5_UMR_STATE_ERR,

drivers/infiniband/hw/mlx5/umr.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ int mlx5r_umr_resource_init(struct mlx5_ib_dev *dev)
177177

178178
sema_init(&dev->umrc.sem, MAX_UMR_WR);
179179
mutex_init(&dev->umrc.lock);
180+
dev->umrc.state = MLX5_UMR_STATE_ACTIVE;
180181

181182
return 0;
182183

@@ -191,6 +192,8 @@ int mlx5r_umr_resource_init(struct mlx5_ib_dev *dev)
191192

192193
void mlx5r_umr_resource_cleanup(struct mlx5_ib_dev *dev)
193194
{
195+
if (dev->umrc.state == MLX5_UMR_STATE_UNINIT)
196+
return;
194197
ib_destroy_qp(dev->umrc.qp);
195198
ib_free_cq(dev->umrc.cq);
196199
ib_dealloc_pd(dev->umrc.pd);

0 commit comments

Comments
 (0)