From: Leon Romanovsky <[email protected]>

These variables do not need to persist for the lifetime of the CQ object.
They can be safely allocated on the stack instead.

Signed-off-by: Leon Romanovsky <[email protected]>
---
 drivers/infiniband/hw/mlx4/cq.c      | 81 +++++++++++++-----------------------
 drivers/infiniband/hw/mlx4/mlx4_ib.h |  1 -
 2 files changed, 28 insertions(+), 54 deletions(-)

diff --git a/drivers/infiniband/hw/mlx4/cq.c b/drivers/infiniband/hw/mlx4/cq.c
index ffc3902dc329..6e8017ecf137 100644
--- a/drivers/infiniband/hw/mlx4/cq.c
+++ b/drivers/infiniband/hw/mlx4/cq.c
@@ -294,15 +294,29 @@ int mlx4_ib_create_cq(struct ib_cq *ibcq, const struct 
ib_cq_init_attr *attr,
        return err;
 }
 
-static int mlx4_alloc_resize_umem(struct mlx4_ib_dev *dev, struct mlx4_ib_cq 
*cq,
-                                  int entries, struct ib_udata *udata)
+int mlx4_ib_resize_cq(struct ib_cq *ibcq, unsigned int entries,
+                     struct ib_udata *udata)
 {
+       struct mlx4_ib_dev *dev = to_mdev(ibcq->device);
+       struct mlx4_ib_cq *cq = to_mcq(ibcq);
        struct mlx4_ib_resize_cq ucmd;
        int cqe_size = dev->dev->caps.cqe_size;
+       struct ib_umem *umem;
+       struct mlx4_mtt mtt;
        int shift;
        int n;
        int err;
 
+       if (entries > dev->dev->caps.max_cqes)
+               return -EINVAL;
+
+       entries = roundup_pow_of_two(entries + 1);
+       if (entries == ibcq->cqe + 1)
+               return 0;
+
+       if (entries > dev->dev->caps.max_cqes + 1)
+               return -EINVAL;
+
        if (ib_copy_from_udata(&ucmd, udata, sizeof ucmd))
                return -EFAULT;
 
@@ -310,15 +324,14 @@ static int mlx4_alloc_resize_umem(struct mlx4_ib_dev 
*dev, struct mlx4_ib_cq *cq
        if (!cq->resize_buf)
                return -ENOMEM;
 
-       cq->resize_umem = ib_umem_get(&dev->ib_dev, ucmd.buf_addr,
-                                     entries * cqe_size,
-                                     IB_ACCESS_LOCAL_WRITE);
-       if (IS_ERR(cq->resize_umem)) {
-               err = PTR_ERR(cq->resize_umem);
+       umem = ib_umem_get(&dev->ib_dev, ucmd.buf_addr,
+                          entries * cqe_size, IB_ACCESS_LOCAL_WRITE);
+       if (IS_ERR(umem)) {
+               err = PTR_ERR(umem);
                goto err_buf;
        }
 
-       shift = mlx4_ib_umem_calc_optimal_mtt_size(cq->resize_umem, 0, &n);
+       shift = mlx4_ib_umem_calc_optimal_mtt_size(umem, 0, &n);
        if (shift < 0) {
                err = shift;
                goto err_umem;
@@ -328,73 +341,35 @@ static int mlx4_alloc_resize_umem(struct mlx4_ib_dev 
*dev, struct mlx4_ib_cq *cq
        if (err)
                goto err_umem;
 
-       err = mlx4_ib_umem_write_mtt(dev, &cq->resize_buf->buf.mtt,
-                                    cq->resize_umem);
+       err = mlx4_ib_umem_write_mtt(dev, &cq->resize_buf->buf.mtt, umem);
        if (err)
                goto err_mtt;
 
        cq->resize_buf->cqe = entries - 1;
 
-       return 0;
-
-err_mtt:
-       mlx4_mtt_cleanup(dev->dev, &cq->resize_buf->buf.mtt);
-
-err_umem:
-       ib_umem_release(cq->resize_umem);
-       cq->resize_umem = NULL;
-err_buf:
-       kfree(cq->resize_buf);
-       cq->resize_buf = NULL;
-       return err;
-}
-
-int mlx4_ib_resize_cq(struct ib_cq *ibcq, unsigned int entries,
-                     struct ib_udata *udata)
-{
-       struct mlx4_ib_dev *dev = to_mdev(ibcq->device);
-       struct mlx4_ib_cq *cq = to_mcq(ibcq);
-       struct mlx4_mtt mtt;
-       int err;
-
-       if (entries > dev->dev->caps.max_cqes)
-               return -EINVAL;
-
-       entries = roundup_pow_of_two(entries + 1);
-       if (entries == ibcq->cqe + 1)
-               return 0;
-
-       if (entries > dev->dev->caps.max_cqes + 1)
-               return -EINVAL;
-
-       err = mlx4_alloc_resize_umem(dev, cq, entries, udata);
-       if (err)
-               return err;
        mtt = cq->buf.mtt;
 
        err = mlx4_cq_resize(dev->dev, &cq->mcq, entries, 
&cq->resize_buf->buf.mtt);
        if (err)
-               goto err_buf;
+               goto err_mtt;
 
        mlx4_mtt_cleanup(dev->dev, &mtt);
        cq->buf = cq->resize_buf->buf;
        cq->ibcq.cqe = cq->resize_buf->cqe;
        ib_umem_release(cq->ibcq.umem);
-       cq->ibcq.umem = cq->resize_umem;
+       cq->ibcq.umem = umem;
 
        kfree(cq->resize_buf);
        cq->resize_buf = NULL;
-       cq->resize_umem = NULL;
        return 0;
 
+err_mtt:
+       mlx4_mtt_cleanup(dev->dev, &cq->resize_buf->buf.mtt);
 
+err_umem:
+       ib_umem_release(umem);
 err_buf:
-       mlx4_mtt_cleanup(dev->dev, &cq->resize_buf->buf.mtt);
        kfree(cq->resize_buf);
-       cq->resize_buf = NULL;
-
-       ib_umem_release(cq->resize_umem);
-       cq->resize_umem = NULL;
        return err;
 }
 
diff --git a/drivers/infiniband/hw/mlx4/mlx4_ib.h 
b/drivers/infiniband/hw/mlx4/mlx4_ib.h
index 2f1043690554..4163a6cb32d0 100644
--- a/drivers/infiniband/hw/mlx4/mlx4_ib.h
+++ b/drivers/infiniband/hw/mlx4/mlx4_ib.h
@@ -120,7 +120,6 @@ struct mlx4_ib_cq {
        struct mlx4_ib_cq_resize *resize_buf;
        struct mlx4_db          db;
        spinlock_t              lock;
-       struct ib_umem         *resize_umem;
        /* List of qps that it serves.*/
        struct list_head                send_qp_list;
        struct list_head                recv_qp_list;

-- 
2.52.0


Reply via email to