Commit bbf61096 authored by Ram Amrani's avatar Ram Amrani Committed by Greg Kroah-Hartman

RDMA/qedr: Fix and simplify memory leak in PD alloc


[ Upstream commit 9c1e0228 ]

Free the PD if no internal resources were available. Move userspace
code under the relevant 'if'.
Signed-off-by: default avatarRam Amrani <Ram.Amrani@cavium.com>
Signed-off-by: default avatarAriel Elior <Ariel.Elior@cavium.com>
Signed-off-by: default avatarDoug Ledford <dledford@redhat.com>
Signed-off-by: default avatarSasha Levin <alexander.levin@verizon.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent a4fa2493
...@@ -471,8 +471,6 @@ struct ib_pd *qedr_alloc_pd(struct ib_device *ibdev, ...@@ -471,8 +471,6 @@ struct ib_pd *qedr_alloc_pd(struct ib_device *ibdev,
struct ib_ucontext *context, struct ib_udata *udata) struct ib_ucontext *context, struct ib_udata *udata)
{ {
struct qedr_dev *dev = get_qedr_dev(ibdev); struct qedr_dev *dev = get_qedr_dev(ibdev);
struct qedr_ucontext *uctx = NULL;
struct qedr_alloc_pd_uresp uresp;
struct qedr_pd *pd; struct qedr_pd *pd;
u16 pd_id; u16 pd_id;
int rc; int rc;
...@@ -489,21 +487,33 @@ struct ib_pd *qedr_alloc_pd(struct ib_device *ibdev, ...@@ -489,21 +487,33 @@ struct ib_pd *qedr_alloc_pd(struct ib_device *ibdev,
if (!pd) if (!pd)
return ERR_PTR(-ENOMEM); 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; pd->pd_id = pd_id;
if (udata && context) { if (udata && context) {
struct qedr_alloc_pd_uresp uresp;
uresp.pd_id = pd_id;
rc = ib_copy_to_udata(udata, &uresp, sizeof(uresp)); 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); DP_ERR(dev, "copy error pd_id=0x%x.\n", pd_id);
uctx = get_qedr_ucontext(context); dev->ops->rdma_dealloc_pd(dev->rdma_ctx, pd_id);
uctx->pd = pd; goto err;
pd->uctx = uctx; }
pd->uctx = get_qedr_ucontext(context);
pd->uctx->pd = pd;
} }
return &pd->ibpd; return &pd->ibpd;
err:
kfree(pd);
return ERR_PTR(rc);
} }
int qedr_dealloc_pd(struct ib_pd *ibpd) int qedr_dealloc_pd(struct ib_pd *ibpd)
......
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