diff options
| author | Ram Amrani <Ram.Amrani@Cavium.com> | 2017-01-24 06:51:42 -0500 |
|---|---|---|
| committer | Doug Ledford <dledford@redhat.com> | 2017-01-24 15:35:07 -0500 |
| commit | 9c1e0228ab35e52d30abf4b5629c28350833fbcb (patch) | |
| tree | ce82f7a64535c16e17cee5cef17a63a1de129c6e | |
| parent | af2b14b8b8ae21b0047a52c767ac8b44f435a280 (diff) | |
RDMA/qedr: Fix and simplify memory leak in PD alloc
Free the PD if no internal resources were available. Move userspace
code under the relevant 'if'.
Signed-off-by: Ram Amrani <Ram.Amrani@cavium.com>
Signed-off-by: Ariel Elior <Ariel.Elior@cavium.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
| -rw-r--r-- | drivers/infiniband/hw/qedr/verbs.c | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/drivers/infiniband/hw/qedr/verbs.c b/drivers/infiniband/hw/qedr/verbs.c index c4f4c2131a45..c7d6c9a783bd 100644 --- a/drivers/infiniband/hw/qedr/verbs.c +++ b/drivers/infiniband/hw/qedr/verbs.c | |||
| @@ -471,8 +471,6 @@ struct ib_pd *qedr_alloc_pd(struct ib_device *ibdev, | |||
| 471 | struct ib_ucontext *context, struct ib_udata *udata) | 471 | struct ib_ucontext *context, struct ib_udata *udata) |
| 472 | { | 472 | { |
| 473 | struct qedr_dev *dev = get_qedr_dev(ibdev); | 473 | struct qedr_dev *dev = get_qedr_dev(ibdev); |
| 474 | struct qedr_ucontext *uctx = NULL; | ||
| 475 | struct qedr_alloc_pd_uresp uresp; | ||
| 476 | struct qedr_pd *pd; | 474 | struct qedr_pd *pd; |
| 477 | u16 pd_id; | 475 | u16 pd_id; |
| 478 | int rc; | 476 | int rc; |
| @@ -489,21 +487,33 @@ struct ib_pd *qedr_alloc_pd(struct ib_device *ibdev, | |||
| 489 | if (!pd) | 487 | if (!pd) |
| 490 | return ERR_PTR(-ENOMEM); | 488 | return ERR_PTR(-ENOMEM); |
| 491 | 489 | ||
| 492 | dev->ops->rdma_alloc_pd(dev->rdma_ctx, &pd_id); | 490 | rc = dev->ops->rdma_alloc_pd(dev->rdma_ctx, &pd_id); |
| 491 | if (rc) | ||
| 492 | goto err; | ||
| 493 | 493 | ||
| 494 | uresp.pd_id = pd_id; | ||
| 495 | pd->pd_id = pd_id; | 494 | pd->pd_id = pd_id; |
| 496 | 495 | ||
| 497 | if (udata && context) { | 496 | if (udata && context) { |
| 497 | struct qedr_alloc_pd_uresp uresp; | ||
| 498 | |||
| 499 | uresp.pd_id = pd_id; | ||
| 500 | |||
| 498 | rc = ib_copy_to_udata(udata, &uresp, sizeof(uresp)); | 501 | rc = ib_copy_to_udata(udata, &uresp, sizeof(uresp)); |
| 499 | if (rc) | 502 | if (rc) { |
| 500 | DP_ERR(dev, "copy error pd_id=0x%x.\n", pd_id); | 503 | DP_ERR(dev, "copy error pd_id=0x%x.\n", pd_id); |
| 501 | uctx = get_qedr_ucontext(context); | 504 | dev->ops->rdma_dealloc_pd(dev->rdma_ctx, pd_id); |
| 502 | uctx->pd = pd; | 505 | goto err; |
| 503 | pd->uctx = uctx; | 506 | } |
| 507 | |||
| 508 | pd->uctx = get_qedr_ucontext(context); | ||
| 509 | pd->uctx->pd = pd; | ||
| 504 | } | 510 | } |
| 505 | 511 | ||
| 506 | return &pd->ibpd; | 512 | return &pd->ibpd; |
| 513 | |||
| 514 | err: | ||
| 515 | kfree(pd); | ||
| 516 | return ERR_PTR(rc); | ||
| 507 | } | 517 | } |
| 508 | 518 | ||
| 509 | int qedr_dealloc_pd(struct ib_pd *ibpd) | 519 | int qedr_dealloc_pd(struct ib_pd *ibpd) |
