IB/mlx5: Don't clean uninitialized UMR resources
authorMark Bloch <markb@mellanox.com>
Tue, 20 Mar 2018 13:45:37 +0000 (15:45 +0200)
committerJason Gunthorpe <jgg@mellanox.com>
Wed, 21 Mar 2018 20:22:22 +0000 (14:22 -0600)
In case we failed to create UMR resources, mark them as invalid so we
won't try to destroy them on the unwind path.

Add the relevant checks to destroy_umrc_res(), this is done for the
unlikely event ib_register_device() or create_umr_res() err out and we
try to destroy invalid objects.

Fixes: 42cea83f9524 ("IB/mlx5: Fix cleanup order on unload")
Signed-off-by: Mark Bloch <markb@mellanox.com>
Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
drivers/infiniband/hw/mlx5/main.c
drivers/infiniband/hw/mlx5/mr.c

index da091de4e69d81eda73de4e3ce758830aaa1413c..7f8bda3a20058753c7bc3109c985895b2fb46664 100644 (file)
@@ -3448,9 +3448,12 @@ static void destroy_umrc_res(struct mlx5_ib_dev *dev)
        if (err)
                mlx5_ib_warn(dev, "mr cache cleanup failed\n");
 
-       mlx5_ib_destroy_qp(dev->umrc.qp);
-       ib_free_cq(dev->umrc.cq);
-       ib_dealloc_pd(dev->umrc.pd);
+       if (dev->umrc.qp)
+               mlx5_ib_destroy_qp(dev->umrc.qp);
+       if (dev->umrc.cq)
+               ib_free_cq(dev->umrc.cq);
+       if (dev->umrc.pd)
+               ib_dealloc_pd(dev->umrc.pd);
 }
 
 enum {
@@ -3552,12 +3555,15 @@ static int create_umr_res(struct mlx5_ib_dev *dev)
 
 error_4:
        mlx5_ib_destroy_qp(qp);
+       dev->umrc.qp = NULL;
 
 error_3:
        ib_free_cq(cq);
+       dev->umrc.cq = NULL;
 
 error_2:
        ib_dealloc_pd(pd);
+       dev->umrc.pd = NULL;
 
 error_0:
        kfree(attr);
index c51c602f06d6ea6d9c4737abbf4a6ab6f09fa6eb..3e0b3f0238d69315a8bd16d2177a0e5a96f8746e 100644 (file)
@@ -739,6 +739,9 @@ int mlx5_mr_cache_cleanup(struct mlx5_ib_dev *dev)
 {
        int i;
 
+       if (!dev->cache.wq)
+               return 0;
+
        dev->cache.stopped = 1;
        flush_workqueue(dev->cache.wq);