Skip to content

Commit

Permalink
RDMA/qedr: Fix and simplify memory leak in PD alloc
Browse files Browse the repository at this point in the history
Free the PD if no internal resources were available. Move userspace
code under the relevant 'if'.

Signed-off-by: Ram Amrani <[email protected]>
Signed-off-by: Ariel Elior <[email protected]>
Signed-off-by: Doug Ledford <[email protected]>
  • Loading branch information
Ram Amrani authored and dledford committed Jan 24, 2017
1 parent af2b14b commit 9c1e022
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions drivers/infiniband/hw/qedr/verbs.c
Original file line number Diff line number Diff line change
Expand Up @@ -471,8 +471,6 @@ struct ib_pd *qedr_alloc_pd(struct ib_device *ibdev,
struct ib_ucontext *context, struct ib_udata *udata)
{
struct qedr_dev *dev = get_qedr_dev(ibdev);
struct qedr_ucontext *uctx = NULL;
struct qedr_alloc_pd_uresp uresp;
struct qedr_pd *pd;
u16 pd_id;
int rc;
Expand All @@ -489,21 +487,33 @@ struct ib_pd *qedr_alloc_pd(struct ib_device *ibdev,
if (!pd)
return ERR_PTR(-ENOMEM);

dev->ops->rdma_alloc_pd(dev->rdma_ctx, &pd_id);
rc = dev->ops->rdma_alloc_pd(dev->rdma_ctx, &pd_id);
if (rc)
goto err;

uresp.pd_id = pd_id;
pd->pd_id = pd_id;

if (udata && context) {
struct qedr_alloc_pd_uresp uresp;

uresp.pd_id = pd_id;

rc = ib_copy_to_udata(udata, &uresp, sizeof(uresp));
if (rc)
if (rc) {
DP_ERR(dev, "copy error pd_id=0x%x.\n", pd_id);
uctx = get_qedr_ucontext(context);
uctx->pd = pd;
pd->uctx = uctx;
dev->ops->rdma_dealloc_pd(dev->rdma_ctx, pd_id);
goto err;
}

pd->uctx = get_qedr_ucontext(context);
pd->uctx->pd = pd;
}

return &pd->ibpd;

err:
kfree(pd);
return ERR_PTR(rc);
}

int qedr_dealloc_pd(struct ib_pd *ibpd)
Expand Down

0 comments on commit 9c1e022

Please sign in to comment.