Commit 9b7d4be9 authored by Maor Gottlieb's avatar Maor Gottlieb Committed by Leon Romanovsky

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: 04876c12 ("RDMA/mlx5: Move init and cleanup of UMR to umr.c")
Reviewed-by: default avatarMichael Guralnik <michaelgur@nvidia.com>
Signed-off-by: default avatarMaor Gottlieb <maorg@nvidia.com>
Link: https://lore.kernel.org/r/4cfa61386cf202e9ce330e8d228ce3b25a36326e.1661763459.git.leonro@nvidia.comSigned-off-by: default avatarLeon Romanovsky <leon@kernel.org>
parent 74b30b3a
...@@ -708,6 +708,7 @@ struct mlx5_ib_umr_context { ...@@ -708,6 +708,7 @@ struct mlx5_ib_umr_context {
}; };
enum { enum {
MLX5_UMR_STATE_UNINIT,
MLX5_UMR_STATE_ACTIVE, MLX5_UMR_STATE_ACTIVE,
MLX5_UMR_STATE_RECOVER, MLX5_UMR_STATE_RECOVER,
MLX5_UMR_STATE_ERR, MLX5_UMR_STATE_ERR,
......
...@@ -177,6 +177,7 @@ int mlx5r_umr_resource_init(struct mlx5_ib_dev *dev) ...@@ -177,6 +177,7 @@ int mlx5r_umr_resource_init(struct mlx5_ib_dev *dev)
sema_init(&dev->umrc.sem, MAX_UMR_WR); sema_init(&dev->umrc.sem, MAX_UMR_WR);
mutex_init(&dev->umrc.lock); mutex_init(&dev->umrc.lock);
dev->umrc.state = MLX5_UMR_STATE_ACTIVE;
return 0; return 0;
...@@ -191,6 +192,8 @@ int mlx5r_umr_resource_init(struct mlx5_ib_dev *dev) ...@@ -191,6 +192,8 @@ int mlx5r_umr_resource_init(struct mlx5_ib_dev *dev)
void mlx5r_umr_resource_cleanup(struct mlx5_ib_dev *dev) void mlx5r_umr_resource_cleanup(struct mlx5_ib_dev *dev)
{ {
if (dev->umrc.state == MLX5_UMR_STATE_UNINIT)
return;
ib_destroy_qp(dev->umrc.qp); ib_destroy_qp(dev->umrc.qp);
ib_free_cq(dev->umrc.cq); ib_free_cq(dev->umrc.cq);
ib_dealloc_pd(dev->umrc.pd); ib_dealloc_pd(dev->umrc.pd);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment