RDMA: Check umem pointer validity prior to release

Update ib_umem_release() to behave similarly to kfree() and allow
submitting NULL pointer as safe input to this function.

Fixes: a52c8e2469 ("RDMA: Clean destroy CQ in drivers do not return errors")
Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
This commit is contained in:
Leon Romanovsky 2019-06-16 15:05:20 +03:00 committed by Doug Ledford
parent 89a6da3cb8
commit 836a0fbb3e
26 changed files with 73 additions and 132 deletions

View File

@ -361,6 +361,9 @@ static void __ib_umem_release_tail(struct ib_umem *umem)
*/ */
void ib_umem_release(struct ib_umem *umem) void ib_umem_release(struct ib_umem *umem)
{ {
if (!umem)
return;
if (umem->is_odp) { if (umem->is_odp) {
ib_umem_odp_release(to_ib_umem_odp(umem)); ib_umem_odp_release(to_ib_umem_odp(umem));
__ib_umem_release_tail(umem); __ib_umem_release_tail(umem);

View File

@ -805,10 +805,8 @@ int bnxt_re_destroy_qp(struct ib_qp *ib_qp, struct ib_udata *udata)
rdev->sqp_ah = NULL; rdev->sqp_ah = NULL;
} }
if (!IS_ERR_OR_NULL(qp->rumem)) ib_umem_release(qp->rumem);
ib_umem_release(qp->rumem); ib_umem_release(qp->sumem);
if (!IS_ERR_OR_NULL(qp->sumem))
ib_umem_release(qp->sumem);
mutex_lock(&rdev->qp_lock); mutex_lock(&rdev->qp_lock);
list_del(&qp->list); list_del(&qp->list);
@ -1201,12 +1199,8 @@ struct ib_qp *bnxt_re_create_qp(struct ib_pd *ib_pd,
qp_destroy: qp_destroy:
bnxt_qplib_destroy_qp(&rdev->qplib_res, &qp->qplib_qp); bnxt_qplib_destroy_qp(&rdev->qplib_res, &qp->qplib_qp);
free_umem: free_umem:
if (udata) { ib_umem_release(qp->rumem);
if (qp->rumem) ib_umem_release(qp->sumem);
ib_umem_release(qp->rumem);
if (qp->sumem)
ib_umem_release(qp->sumem);
}
fail: fail:
kfree(qp); kfree(qp);
return ERR_PTR(rc); return ERR_PTR(rc);
@ -1302,8 +1296,7 @@ void bnxt_re_destroy_srq(struct ib_srq *ib_srq, struct ib_udata *udata)
if (qplib_srq->cq) if (qplib_srq->cq)
nq = qplib_srq->cq->nq; nq = qplib_srq->cq->nq;
bnxt_qplib_destroy_srq(&rdev->qplib_res, qplib_srq); bnxt_qplib_destroy_srq(&rdev->qplib_res, qplib_srq);
if (srq->umem) ib_umem_release(srq->umem);
ib_umem_release(srq->umem);
atomic_dec(&rdev->srq_count); atomic_dec(&rdev->srq_count);
if (nq) if (nq)
nq->budget--; nq->budget--;
@ -1412,8 +1405,7 @@ int bnxt_re_create_srq(struct ib_srq *ib_srq,
return 0; return 0;
fail: fail:
if (srq->umem) ib_umem_release(srq->umem);
ib_umem_release(srq->umem);
exit: exit:
return rc; return rc;
} }
@ -2528,8 +2520,7 @@ void bnxt_re_destroy_cq(struct ib_cq *ib_cq, struct ib_udata *udata)
nq = cq->qplib_cq.nq; nq = cq->qplib_cq.nq;
bnxt_qplib_destroy_cq(&rdev->qplib_res, &cq->qplib_cq); bnxt_qplib_destroy_cq(&rdev->qplib_res, &cq->qplib_cq);
if (!cq->umem) ib_umem_release(cq->umem);
ib_umem_release(cq->umem);
atomic_dec(&rdev->cq_count); atomic_dec(&rdev->cq_count);
nq->budget--; nq->budget--;
@ -2632,8 +2623,7 @@ int bnxt_re_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr,
return 0; return 0;
c2fail: c2fail:
if (udata) ib_umem_release(cq->umem);
ib_umem_release(cq->umem);
fail: fail:
kfree(cq->cql); kfree(cq->cql);
return rc; return rc;
@ -3340,8 +3330,7 @@ int bnxt_re_dereg_mr(struct ib_mr *ib_mr, struct ib_udata *udata)
mr->npages = 0; mr->npages = 0;
mr->pages = NULL; mr->pages = NULL;
} }
if (!IS_ERR_OR_NULL(mr->ib_umem)) ib_umem_release(mr->ib_umem);
ib_umem_release(mr->ib_umem);
kfree(mr); kfree(mr);
atomic_dec(&rdev->mr_count); atomic_dec(&rdev->mr_count);

View File

@ -346,8 +346,7 @@ static int iwch_dereg_mr(struct ib_mr *ib_mr, struct ib_udata *udata)
xa_erase_irq(&rhp->mrs, mmid); xa_erase_irq(&rhp->mrs, mmid);
if (mhp->kva) if (mhp->kva)
kfree((void *) (unsigned long) mhp->kva); kfree((void *) (unsigned long) mhp->kva);
if (mhp->umem) ib_umem_release(mhp->umem);
ib_umem_release(mhp->umem);
pr_debug("%s mmid 0x%x ptr %p\n", __func__, mmid, mhp); pr_debug("%s mmid 0x%x ptr %p\n", __func__, mmid, mhp);
kfree(mhp); kfree(mhp);
return 0; return 0;

View File

@ -808,8 +808,7 @@ int c4iw_dereg_mr(struct ib_mr *ib_mr, struct ib_udata *udata)
mhp->attr.pbl_size << 3); mhp->attr.pbl_size << 3);
if (mhp->kva) if (mhp->kva)
kfree((void *) (unsigned long) mhp->kva); kfree((void *) (unsigned long) mhp->kva);
if (mhp->umem) ib_umem_release(mhp->umem);
ib_umem_release(mhp->umem);
pr_debug("mmid 0x%x ptr %p\n", mmid, mhp); pr_debug("mmid 0x%x ptr %p\n", mmid, mhp);
c4iw_put_wr_wait(mhp->wr_waitp); c4iw_put_wr_wait(mhp->wr_waitp);
kfree(mhp); kfree(mhp);

View File

@ -1513,8 +1513,8 @@ int efa_dereg_mr(struct ib_mr *ibmr, struct ib_udata *udata)
err = efa_com_dereg_mr(&dev->edev, &params); err = efa_com_dereg_mr(&dev->edev, &params);
if (err) if (err)
return err; return err;
ib_umem_release(mr->umem);
} }
ib_umem_release(mr->umem);
kfree(mr); kfree(mr);

View File

@ -423,9 +423,8 @@ err_dbmap:
err_mtt: err_mtt:
hns_roce_mtt_cleanup(hr_dev, &hr_cq->hr_buf.hr_mtt); hns_roce_mtt_cleanup(hr_dev, &hr_cq->hr_buf.hr_mtt);
if (udata) ib_umem_release(hr_cq->umem);
ib_umem_release(hr_cq->umem); if (!udata)
else
hns_roce_ib_free_cq_buf(hr_dev, &hr_cq->hr_buf, hns_roce_ib_free_cq_buf(hr_dev, &hr_cq->hr_buf,
hr_cq->ib_cq.cqe); hr_cq->ib_cq.cqe);
@ -451,9 +450,8 @@ void hns_roce_ib_destroy_cq(struct ib_cq *ib_cq, struct ib_udata *udata)
hns_roce_free_cq(hr_dev, hr_cq); hns_roce_free_cq(hr_dev, hr_cq);
hns_roce_mtt_cleanup(hr_dev, &hr_cq->hr_buf.hr_mtt); hns_roce_mtt_cleanup(hr_dev, &hr_cq->hr_buf.hr_mtt);
ib_umem_release(hr_cq->umem);
if (udata) { if (udata) {
ib_umem_release(hr_cq->umem);
if (hr_cq->db_en == 1) if (hr_cq->db_en == 1)
hns_roce_db_unmap_user(rdma_udata_to_drv_context( hns_roce_db_unmap_user(rdma_udata_to_drv_context(
udata, udata,

View File

@ -1163,8 +1163,7 @@ free_mr:
hns_roce_bitmap_free(&hr_dev->mr_table.mtpt_bitmap, hns_roce_bitmap_free(&hr_dev->mr_table.mtpt_bitmap,
key_to_hw_index(mr->key), 0); key_to_hw_index(mr->key), 0);
if (mr->umem) ib_umem_release(mr->umem);
ib_umem_release(mr->umem);
kfree(mr); kfree(mr);
@ -3641,9 +3640,8 @@ int hns_roce_v1_destroy_qp(struct ib_qp *ibqp, struct ib_udata *udata)
hns_roce_mtt_cleanup(hr_dev, &hr_qp->mtt); hns_roce_mtt_cleanup(hr_dev, &hr_qp->mtt);
if (udata) ib_umem_release(hr_qp->umem);
ib_umem_release(hr_qp->umem); if (!udata) {
else {
kfree(hr_qp->sq.wrid); kfree(hr_qp->sq.wrid);
kfree(hr_qp->rq.wrid); kfree(hr_qp->rq.wrid);
@ -3694,9 +3692,8 @@ static void hns_roce_v1_destroy_cq(struct ib_cq *ibcq, struct ib_udata *udata)
hns_roce_mtt_cleanup(hr_dev, &hr_cq->hr_buf.hr_mtt); hns_roce_mtt_cleanup(hr_dev, &hr_cq->hr_buf.hr_mtt);
if (ibcq->uobject) ib_umem_release(hr_cq->umem);
ib_umem_release(hr_cq->umem); if (!udata) {
else {
/* Free the buff of stored cq */ /* Free the buff of stored cq */
cq_buf_size = (ibcq->cqe + 1) * hr_dev->caps.cq_entry_sz; cq_buf_size = (ibcq->cqe + 1) * hr_dev->caps.cq_entry_sz;
hns_roce_buf_free(hr_dev, cq_buf_size, &hr_cq->hr_buf.hr_buf); hns_roce_buf_free(hr_dev, cq_buf_size, &hr_cq->hr_buf.hr_buf);

View File

@ -4582,7 +4582,6 @@ static int hns_roce_v2_destroy_qp_common(struct hns_roce_dev *hr_dev,
if (hr_qp->rq.wqe_cnt && (hr_qp->rdb_en == 1)) if (hr_qp->rq.wqe_cnt && (hr_qp->rdb_en == 1))
hns_roce_db_unmap_user(context, &hr_qp->rdb); hns_roce_db_unmap_user(context, &hr_qp->rdb);
ib_umem_release(hr_qp->umem);
} else { } else {
kfree(hr_qp->sq.wrid); kfree(hr_qp->sq.wrid);
kfree(hr_qp->rq.wrid); kfree(hr_qp->rq.wrid);
@ -4590,6 +4589,7 @@ static int hns_roce_v2_destroy_qp_common(struct hns_roce_dev *hr_dev,
if (hr_qp->rq.wqe_cnt) if (hr_qp->rq.wqe_cnt)
hns_roce_free_db(hr_dev, &hr_qp->rdb); hns_roce_free_db(hr_dev, &hr_qp->rdb);
} }
ib_umem_release(hr_qp->umem);
if ((hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_RQ_INLINE) && if ((hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_RQ_INLINE) &&
hr_qp->rq.wqe_cnt) { hr_qp->rq.wqe_cnt) {

View File

@ -1298,9 +1298,7 @@ int hns_roce_dereg_mr(struct ib_mr *ibmr, struct ib_udata *udata)
} else { } else {
hns_roce_mr_free(hr_dev, mr); hns_roce_mr_free(hr_dev, mr);
if (mr->umem) ib_umem_release(mr->umem);
ib_umem_release(mr->umem);
kfree(mr); kfree(mr);
} }

View File

@ -938,10 +938,9 @@ err_get_bufs:
hns_roce_free_buf_list(buf_list, hr_qp->region_cnt); hns_roce_free_buf_list(buf_list, hr_qp->region_cnt);
err_alloc_list: err_alloc_list:
if (hr_qp->umem) if (!hr_qp->umem)
ib_umem_release(hr_qp->umem);
else
hns_roce_buf_free(hr_dev, hr_qp->buff_size, &hr_qp->hr_buf); hns_roce_buf_free(hr_dev, hr_qp->buff_size, &hr_qp->hr_buf);
ib_umem_release(hr_qp->umem);
err_db: err_db:
if (!udata && hns_roce_qp_has_rq(init_attr) && if (!udata && hns_roce_qp_has_rq(init_attr) &&

View File

@ -380,8 +380,7 @@ err_idx_buf:
hns_roce_mtt_cleanup(hr_dev, &srq->idx_que.mtt); hns_roce_mtt_cleanup(hr_dev, &srq->idx_que.mtt);
err_idx_mtt: err_idx_mtt:
if (udata) ib_umem_release(srq->idx_que.umem);
ib_umem_release(srq->idx_que.umem);
err_create_idx: err_create_idx:
hns_roce_buf_free(hr_dev, srq->idx_que.buf_size, hns_roce_buf_free(hr_dev, srq->idx_que.buf_size,
@ -392,9 +391,8 @@ err_srq_mtt:
hns_roce_mtt_cleanup(hr_dev, &srq->mtt); hns_roce_mtt_cleanup(hr_dev, &srq->mtt);
err_buf: err_buf:
if (udata) ib_umem_release(srq->umem);
ib_umem_release(srq->umem); if (!udata)
else
hns_roce_buf_free(hr_dev, srq_buf_size, &srq->buf); hns_roce_buf_free(hr_dev, srq_buf_size, &srq->buf);
return ret; return ret;
@ -408,15 +406,15 @@ void hns_roce_destroy_srq(struct ib_srq *ibsrq, struct ib_udata *udata)
hns_roce_srq_free(hr_dev, srq); hns_roce_srq_free(hr_dev, srq);
hns_roce_mtt_cleanup(hr_dev, &srq->mtt); hns_roce_mtt_cleanup(hr_dev, &srq->mtt);
if (ibsrq->uobject) { if (udata) {
hns_roce_mtt_cleanup(hr_dev, &srq->idx_que.mtt); hns_roce_mtt_cleanup(hr_dev, &srq->idx_que.mtt);
ib_umem_release(srq->idx_que.umem);
ib_umem_release(srq->umem);
} else { } else {
kvfree(srq->wrid); kvfree(srq->wrid);
hns_roce_buf_free(hr_dev, srq->max << srq->wqe_shift, hns_roce_buf_free(hr_dev, srq->max << srq->wqe_shift,
&srq->buf); &srq->buf);
} }
ib_umem_release(srq->idx_que.umem);
ib_umem_release(srq->umem);
} }
int hns_roce_init_srq_table(struct hns_roce_dev *hr_dev) int hns_roce_init_srq_table(struct hns_roce_dev *hr_dev)

View File

@ -2004,8 +2004,7 @@ static int i40iw_dereg_mr(struct ib_mr *ib_mr, struct ib_udata *udata)
struct cqp_commands_info *cqp_info; struct cqp_commands_info *cqp_info;
u32 stag_idx; u32 stag_idx;
if (iwmr->region) ib_umem_release(iwmr->region);
ib_umem_release(iwmr->region);
if (iwmr->type != IW_MEMREG_TYPE_MEM) { if (iwmr->type != IW_MEMREG_TYPE_MEM) {
/* region is released. only test for userness. */ /* region is released. only test for userness. */

View File

@ -277,9 +277,8 @@ err_dbmap:
err_mtt: err_mtt:
mlx4_mtt_cleanup(dev->dev, &cq->buf.mtt); mlx4_mtt_cleanup(dev->dev, &cq->buf.mtt);
if (udata) ib_umem_release(cq->umem);
ib_umem_release(cq->umem); if (!udata)
else
mlx4_ib_free_cq_buf(dev, &cq->buf, cq->ibcq.cqe); mlx4_ib_free_cq_buf(dev, &cq->buf, cq->ibcq.cqe);
err_db: err_db:
@ -468,11 +467,8 @@ err_buf:
kfree(cq->resize_buf); kfree(cq->resize_buf);
cq->resize_buf = NULL; cq->resize_buf = NULL;
if (cq->resize_umem) { ib_umem_release(cq->resize_umem);
ib_umem_release(cq->resize_umem); cq->resize_umem = NULL;
cq->resize_umem = NULL;
}
out: out:
mutex_unlock(&cq->resize_mutex); mutex_unlock(&cq->resize_mutex);
@ -494,11 +490,11 @@ void mlx4_ib_destroy_cq(struct ib_cq *cq, struct ib_udata *udata)
struct mlx4_ib_ucontext, struct mlx4_ib_ucontext,
ibucontext), ibucontext),
&mcq->db); &mcq->db);
ib_umem_release(mcq->umem);
} else { } else {
mlx4_ib_free_cq_buf(dev, &mcq->buf, cq->cqe); mlx4_ib_free_cq_buf(dev, &mcq->buf, cq->cqe);
mlx4_db_free(dev->dev, &mcq->db); mlx4_db_free(dev->dev, &mcq->db);
} }
ib_umem_release(mcq->umem);
} }
static void dump_cqe(void *cqe) static void dump_cqe(void *cqe)

View File

@ -1207,10 +1207,9 @@ err_mtt:
mlx4_mtt_cleanup(dev->dev, &qp->mtt); mlx4_mtt_cleanup(dev->dev, &qp->mtt);
err_buf: err_buf:
if (qp->umem) if (!qp->umem)
ib_umem_release(qp->umem);
else
mlx4_buf_free(dev->dev, qp->buf_size, &qp->buf); mlx4_buf_free(dev->dev, qp->buf_size, &qp->buf);
ib_umem_release(qp->umem);
err_db: err_db:
if (!udata && qp_has_rq(init_attr)) if (!udata && qp_has_rq(init_attr))
@ -1421,7 +1420,6 @@ static void destroy_qp_common(struct mlx4_ib_dev *dev, struct mlx4_ib_qp *qp,
mlx4_ib_db_unmap_user(mcontext, &qp->db); mlx4_ib_db_unmap_user(mcontext, &qp->db);
} }
ib_umem_release(qp->umem);
} else { } else {
kvfree(qp->sq.wrid); kvfree(qp->sq.wrid);
kvfree(qp->rq.wrid); kvfree(qp->rq.wrid);
@ -1432,6 +1430,7 @@ static void destroy_qp_common(struct mlx4_ib_dev *dev, struct mlx4_ib_qp *qp,
if (qp->rq.wqe_cnt) if (qp->rq.wqe_cnt)
mlx4_db_free(dev->dev, &qp->db); mlx4_db_free(dev->dev, &qp->db);
} }
ib_umem_release(qp->umem);
del_gid_entries(qp); del_gid_entries(qp);
} }

View File

@ -204,10 +204,9 @@ err_mtt:
mlx4_mtt_cleanup(dev->dev, &srq->mtt); mlx4_mtt_cleanup(dev->dev, &srq->mtt);
err_buf: err_buf:
if (srq->umem) if (!srq->umem)
ib_umem_release(srq->umem);
else
mlx4_buf_free(dev->dev, buf_size, &srq->buf); mlx4_buf_free(dev->dev, buf_size, &srq->buf);
ib_umem_release(srq->umem);
err_db: err_db:
if (!udata) if (!udata)
@ -275,13 +274,13 @@ void mlx4_ib_destroy_srq(struct ib_srq *srq, struct ib_udata *udata)
struct mlx4_ib_ucontext, struct mlx4_ib_ucontext,
ibucontext), ibucontext),
&msrq->db); &msrq->db);
ib_umem_release(msrq->umem);
} else { } else {
kvfree(msrq->wrid); kvfree(msrq->wrid);
mlx4_buf_free(dev->dev, msrq->msrq.max << msrq->msrq.wqe_shift, mlx4_buf_free(dev->dev, msrq->msrq.max << msrq->msrq.wqe_shift,
&msrq->buf); &msrq->buf);
mlx4_db_free(dev->dev, &msrq->db); mlx4_db_free(dev->dev, &msrq->db);
} }
ib_umem_release(msrq->umem);
} }
void mlx4_ib_free_srq_wqe(struct mlx4_ib_srq *srq, int wqe_index) void mlx4_ib_free_srq_wqe(struct mlx4_ib_srq *srq, int wqe_index)

View File

@ -1125,11 +1125,6 @@ static int resize_user(struct mlx5_ib_dev *dev, struct mlx5_ib_cq *cq,
return 0; return 0;
} }
static void un_resize_user(struct mlx5_ib_cq *cq)
{
ib_umem_release(cq->resize_umem);
}
static int resize_kernel(struct mlx5_ib_dev *dev, struct mlx5_ib_cq *cq, static int resize_kernel(struct mlx5_ib_dev *dev, struct mlx5_ib_cq *cq,
int entries, int cqe_size) int entries, int cqe_size)
{ {
@ -1152,12 +1147,6 @@ ex:
return err; return err;
} }
static void un_resize_kernel(struct mlx5_ib_dev *dev, struct mlx5_ib_cq *cq)
{
free_cq_buf(dev, cq->resize_buf);
cq->resize_buf = NULL;
}
static int copy_resize_cqes(struct mlx5_ib_cq *cq) static int copy_resize_cqes(struct mlx5_ib_cq *cq)
{ {
struct mlx5_ib_dev *dev = to_mdev(cq->ibcq.device); struct mlx5_ib_dev *dev = to_mdev(cq->ibcq.device);
@ -1338,10 +1327,11 @@ ex_alloc:
kvfree(in); kvfree(in);
ex_resize: ex_resize:
if (udata) ib_umem_release(cq->resize_umem);
un_resize_user(cq); if (!udata) {
else free_cq_buf(dev, cq->resize_buf);
un_resize_kernel(dev, cq); cq->resize_buf = NULL;
}
ex: ex:
mutex_unlock(&cq->resize_mutex); mutex_unlock(&cq->resize_mutex);
return err; return err;

View File

@ -1507,10 +1507,9 @@ int mlx5_ib_rereg_user_mr(struct ib_mr *ib_mr, int flags, u64 start,
return 0; return 0;
err: err:
if (mr->umem) { ib_umem_release(mr->umem);
ib_umem_release(mr->umem); mr->umem = NULL;
mr->umem = NULL;
}
clean_mr(dev, mr); clean_mr(dev, mr);
return err; return err;
} }
@ -1630,10 +1629,10 @@ static void dereg_mr(struct mlx5_ib_dev *dev, struct mlx5_ib_mr *mr)
* remove the DMA mapping. * remove the DMA mapping.
*/ */
mlx5_mr_cache_free(dev, mr); mlx5_mr_cache_free(dev, mr);
if (umem) { ib_umem_release(umem);
ib_umem_release(umem); if (umem)
atomic_sub(npages, &dev->mdev->priv.reg_pages); atomic_sub(npages, &dev->mdev->priv.reg_pages);
}
if (!mr->allocated_from_cache) if (!mr->allocated_from_cache)
kfree(mr); kfree(mr);
} }

View File

@ -790,8 +790,7 @@ static void destroy_user_rq(struct mlx5_ib_dev *dev, struct ib_pd *pd,
atomic_dec(&dev->delay_drop.rqs_cnt); atomic_dec(&dev->delay_drop.rqs_cnt);
mlx5_ib_db_unmap_user(context, &rwq->db); mlx5_ib_db_unmap_user(context, &rwq->db);
if (rwq->umem) ib_umem_release(rwq->umem);
ib_umem_release(rwq->umem);
} }
static int create_user_rq(struct mlx5_ib_dev *dev, struct ib_pd *pd, static int create_user_rq(struct mlx5_ib_dev *dev, struct ib_pd *pd,
@ -977,8 +976,7 @@ err_free:
kvfree(*in); kvfree(*in);
err_umem: err_umem:
if (ubuffer->umem) ib_umem_release(ubuffer->umem);
ib_umem_release(ubuffer->umem);
err_bfreg: err_bfreg:
if (bfregn != MLX5_IB_INVALID_BFREG) if (bfregn != MLX5_IB_INVALID_BFREG)
@ -997,8 +995,7 @@ static void destroy_qp_user(struct mlx5_ib_dev *dev, struct ib_pd *pd,
ibucontext); ibucontext);
mlx5_ib_db_unmap_user(context, &qp->db); mlx5_ib_db_unmap_user(context, &qp->db);
if (base->ubuffer.umem) ib_umem_release(base->ubuffer.umem);
ib_umem_release(base->ubuffer.umem);
/* /*
* Free only the BFREGs which are handled by the kernel. * Free only the BFREGs which are handled by the kernel.

View File

@ -953,8 +953,7 @@ static int mthca_dereg_mr(struct ib_mr *mr, struct ib_udata *udata)
struct mthca_mr *mmr = to_mmr(mr); struct mthca_mr *mmr = to_mmr(mr);
mthca_free_mr(to_mdev(mr->device), mmr); mthca_free_mr(to_mdev(mr->device), mmr);
if (mmr->umem) ib_umem_release(mmr->umem);
ib_umem_release(mmr->umem);
kfree(mmr); kfree(mmr);
return 0; return 0;

View File

@ -925,8 +925,7 @@ int ocrdma_dereg_mr(struct ib_mr *ib_mr, struct ib_udata *udata)
ocrdma_free_mr_pbl_tbl(dev, &mr->hwmr); ocrdma_free_mr_pbl_tbl(dev, &mr->hwmr);
/* it could be user registered memory. */ /* it could be user registered memory. */
if (mr->umem) ib_umem_release(mr->umem);
ib_umem_release(mr->umem);
kfree(mr); kfree(mr);
/* Don't stop cleanup, in case FW is unresponsive */ /* Don't stop cleanup, in case FW is unresponsive */

View File

@ -1572,12 +1572,10 @@ qedr_iwarp_populate_user_qp(struct qedr_dev *dev,
static void qedr_cleanup_user(struct qedr_dev *dev, struct qedr_qp *qp) static void qedr_cleanup_user(struct qedr_dev *dev, struct qedr_qp *qp)
{ {
if (qp->usq.umem) ib_umem_release(qp->usq.umem);
ib_umem_release(qp->usq.umem);
qp->usq.umem = NULL; qp->usq.umem = NULL;
if (qp->urq.umem) ib_umem_release(qp->urq.umem);
ib_umem_release(qp->urq.umem);
qp->urq.umem = NULL; qp->urq.umem = NULL;
} }
@ -2680,8 +2678,7 @@ int qedr_dereg_mr(struct ib_mr *ib_mr, struct ib_udata *udata)
qedr_free_pbl(dev, &mr->info.pbl_info, mr->info.pbl_table); qedr_free_pbl(dev, &mr->info.pbl_info, mr->info.pbl_table);
/* it could be user registered memory. */ /* it could be user registered memory. */
if (mr->umem) ib_umem_release(mr->umem);
ib_umem_release(mr->umem);
kfree(mr); kfree(mr);

View File

@ -213,8 +213,7 @@ int pvrdma_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr,
err_page_dir: err_page_dir:
pvrdma_page_dir_cleanup(dev, &cq->pdir); pvrdma_page_dir_cleanup(dev, &cq->pdir);
err_umem: err_umem:
if (!cq->is_kernel) ib_umem_release(cq->umem);
ib_umem_release(cq->umem);
err_cq: err_cq:
atomic_dec(&dev->num_cqs); atomic_dec(&dev->num_cqs);
return ret; return ret;
@ -226,8 +225,7 @@ static void pvrdma_free_cq(struct pvrdma_dev *dev, struct pvrdma_cq *cq)
complete(&cq->free); complete(&cq->free);
wait_for_completion(&cq->free); wait_for_completion(&cq->free);
if (!cq->is_kernel) ib_umem_release(cq->umem);
ib_umem_release(cq->umem);
pvrdma_page_dir_cleanup(dev, &cq->pdir); pvrdma_page_dir_cleanup(dev, &cq->pdir);
} }

View File

@ -290,8 +290,7 @@ int pvrdma_dereg_mr(struct ib_mr *ibmr, struct ib_udata *udata)
"could not deregister mem region, error: %d\n", ret); "could not deregister mem region, error: %d\n", ret);
pvrdma_page_dir_cleanup(dev, &mr->pdir); pvrdma_page_dir_cleanup(dev, &mr->pdir);
if (mr->umem) ib_umem_release(mr->umem);
ib_umem_release(mr->umem);
kfree(mr->pages); kfree(mr->pages);
kfree(mr); kfree(mr);

View File

@ -391,12 +391,8 @@ struct ib_qp *pvrdma_create_qp(struct ib_pd *pd,
err_pdir: err_pdir:
pvrdma_page_dir_cleanup(dev, &qp->pdir); pvrdma_page_dir_cleanup(dev, &qp->pdir);
err_umem: err_umem:
if (!qp->is_kernel) { ib_umem_release(qp->rumem);
if (qp->rumem) ib_umem_release(qp->sumem);
ib_umem_release(qp->rumem);
if (qp->sumem)
ib_umem_release(qp->sumem);
}
err_qp: err_qp:
kfree(qp); kfree(qp);
atomic_dec(&dev->num_qps); atomic_dec(&dev->num_qps);
@ -429,12 +425,8 @@ static void pvrdma_free_qp(struct pvrdma_qp *qp)
complete(&qp->free); complete(&qp->free);
wait_for_completion(&qp->free); wait_for_completion(&qp->free);
if (!qp->is_kernel) { ib_umem_release(qp->rumem);
if (qp->rumem) ib_umem_release(qp->sumem);
ib_umem_release(qp->rumem);
if (qp->sumem)
ib_umem_release(qp->sumem);
}
pvrdma_page_dir_cleanup(dev, &qp->pdir); pvrdma_page_dir_cleanup(dev, &qp->pdir);

View File

@ -560,8 +560,7 @@ int rvt_dereg_mr(struct ib_mr *ibmr, struct ib_udata *udata)
if (ret) if (ret)
goto out; goto out;
rvt_deinit_mregion(&mr->mr); rvt_deinit_mregion(&mr->mr);
if (mr->umem) ib_umem_release(mr->umem);
ib_umem_release(mr->umem);
kfree(mr); kfree(mr);
out: out:
return ret; return ret;

View File

@ -96,8 +96,7 @@ void rxe_mem_cleanup(struct rxe_pool_entry *arg)
struct rxe_mem *mem = container_of(arg, typeof(*mem), pelem); struct rxe_mem *mem = container_of(arg, typeof(*mem), pelem);
int i; int i;
if (mem->umem) ib_umem_release(mem->umem);
ib_umem_release(mem->umem);
if (mem->map) { if (mem->map) {
for (i = 0; i < mem->num_map; i++) for (i = 0; i < mem->num_map; i++)