* Re: [PATCH] qedr: fix resource leak in qedr_create_qp
[not found] <f79159af-4408-dc2f-6efa-45c5b45cf2d9@web.de>
@ 2020-09-10 16:31 ` Keita Suzuki
2020-09-10 16:34 ` [PATCH v2] " Keita Suzuki
[not found] ` <59440849-23b1-9c69-ecf6-78f8a0b82c7a@web.de>
0 siblings, 2 replies; 3+ messages in thread
From: Keita Suzuki @ 2020-09-10 16:31 UTC (permalink / raw)
To: Markus Elfring
Cc: linux-rdma, open list, kernel-janitors, Ariel Elior,
Doug Ledford, Jason Gunthorpe, Michal Kalderon, Takafumi Kubota,
Yuval Bason
Hi,
Thank you for your comment.
I will re-label the goto statements and post the patch as version 2.
Thanks,
Keita
2020年9月10日(木) 22:24 Markus Elfring <Markus.Elfring@web.de>:
>
> > Fix this by adding a new goto label that calls qedr_free_qp_resources.
>
> …
> > +++ b/drivers/infiniband/hw/qedr/verbs.c
> …
> > @@ -2165,11 +2187,13 @@ struct ib_qp *qedr_create_qp(struct ib_pd *ibpd,
> …
> > return &qp->ibqp;
> >
> > +err2:
> > + qedr_free_qp_resources(dev, qp, udata);
> > err:
> > kfree(qp);
>
> I propose to choose further alternatives for numbered labels.
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/coding-style.rst?id=7fe10096c1508c7f033d34d0741809f8eecc1ed4#n485
>
> Regards,
> Markus
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH v2] qedr: fix resource leak in qedr_create_qp
2020-09-10 16:31 ` [PATCH] qedr: fix resource leak in qedr_create_qp Keita Suzuki
@ 2020-09-10 16:34 ` Keita Suzuki
[not found] ` <59440849-23b1-9c69-ecf6-78f8a0b82c7a@web.de>
1 sibling, 0 replies; 3+ messages in thread
From: Keita Suzuki @ 2020-09-10 16:34 UTC (permalink / raw)
Cc: keitasuzuki.park, takafumi, Michal Kalderon, Ariel Elior,
Doug Ledford, Jason Gunthorpe, Yuval Bason, linux-rdma,
linux-kernel
When xa_insert() fails, the acquired resource in qedr_create_qp should
also be freed. However, current implementation does not handle the
error.
Fix this by adding a new goto label that calls qedr_free_qp_resources.
Fixes: 1212767e23bb ("qedr: Add wrapping generic structure for qpidr and
adjust idr routines.")
Signed-off-by: Keita Suzuki <keitasuzuki.park@sslab.ics.keio.ac.jp>
---
changelog(v2): Change numbered labels to descriptive labels
drivers/infiniband/hw/qedr/verbs.c | 52 ++++++++++++++++--------------
1 file changed, 27 insertions(+), 25 deletions(-)
diff --git a/drivers/infiniband/hw/qedr/verbs.c b/drivers/infiniband/hw/qedr/verbs.c
index b49bef94637e..3b4c84f67023 100644
--- a/drivers/infiniband/hw/qedr/verbs.c
+++ b/drivers/infiniband/hw/qedr/verbs.c
@@ -2112,6 +2112,28 @@ static int qedr_create_kernel_qp(struct qedr_dev *dev,
return rc;
}
+static int qedr_free_qp_resources(struct qedr_dev *dev, struct qedr_qp *qp,
+ struct ib_udata *udata)
+{
+ struct qedr_ucontext *ctx =
+ rdma_udata_to_drv_context(udata, struct qedr_ucontext,
+ ibucontext);
+ int rc;
+
+ if (qp->qp_type != IB_QPT_GSI) {
+ rc = dev->ops->rdma_destroy_qp(dev->rdma_ctx, qp->qed_qp);
+ if (rc)
+ return rc;
+ }
+
+ if (qp->create_type == QEDR_QP_CREATE_USER)
+ qedr_cleanup_user(dev, ctx, qp);
+ else
+ qedr_cleanup_kernel(dev, qp);
+
+ return 0;
+}
+
struct ib_qp *qedr_create_qp(struct ib_pd *ibpd,
struct ib_qp_init_attr *attrs,
struct ib_udata *udata)
@@ -2158,19 +2180,21 @@ struct ib_qp *qedr_create_qp(struct ib_pd *ibpd,
rc = qedr_create_kernel_qp(dev, qp, ibpd, attrs);
if (rc)
- goto err;
+ goto out_free_qp;
qp->ibqp.qp_num = qp->qp_id;
if (rdma_protocol_iwarp(&dev->ibdev, 1)) {
rc = xa_insert(&dev->qps, qp->qp_id, qp, GFP_KERNEL);
if (rc)
- goto err;
+ goto out_free_qp_resources;
}
return &qp->ibqp;
-err:
+out_free_qp_resources:
+ qedr_free_qp_resources(dev, qp, udata);
+out_free_qp:
kfree(qp);
return ERR_PTR(-EFAULT);
@@ -2671,28 +2695,6 @@ int qedr_query_qp(struct ib_qp *ibqp,
return rc;
}
-static int qedr_free_qp_resources(struct qedr_dev *dev, struct qedr_qp *qp,
- struct ib_udata *udata)
-{
- struct qedr_ucontext *ctx =
- rdma_udata_to_drv_context(udata, struct qedr_ucontext,
- ibucontext);
- int rc;
-
- if (qp->qp_type != IB_QPT_GSI) {
- rc = dev->ops->rdma_destroy_qp(dev->rdma_ctx, qp->qed_qp);
- if (rc)
- return rc;
- }
-
- if (qp->create_type == QEDR_QP_CREATE_USER)
- qedr_cleanup_user(dev, ctx, qp);
- else
- qedr_cleanup_kernel(dev, qp);
-
- return 0;
-}
-
int qedr_destroy_qp(struct ib_qp *ibqp, struct ib_udata *udata)
{
struct qedr_qp *qp = get_qedr_qp(ibqp);
--
2.17.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] qedr: fix resource leak in qedr_create_qp
[not found] ` <59440849-23b1-9c69-ecf6-78f8a0b82c7a@web.de>
@ 2020-09-11 12:49 ` Keita Suzuki
0 siblings, 0 replies; 3+ messages in thread
From: Keita Suzuki @ 2020-09-11 12:49 UTC (permalink / raw)
To: Markus Elfring
Cc: linux-rdma, open list, kernel-janitors, Ariel Elior,
Doug Ledford, Jason Gunthorpe, Michal Kalderon, Takafumi Kubota,
Yuval Bason
Hi,
thank you for the comment.
I will fix the line break and re-post the patch
Thanks,
Keita
2020年9月11日(金) 4:48 Markus Elfring <Markus.Elfring@web.de>:
>
> > I will re-label the goto statements and post the patch as version 2.
>
> Thanks for such a positive feedback.
>
>
> Another suggestion:
>
> > > Fixes: 1212767e23bb ("qedr: Add wrapping generic structure for qpidr and
> > > adjust idr routines.")
>
> Please omit a line break for this tag.
>
> Regards,
> Markus
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-09-11 17:37 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <f79159af-4408-dc2f-6efa-45c5b45cf2d9@web.de>
2020-09-10 16:31 ` [PATCH] qedr: fix resource leak in qedr_create_qp Keita Suzuki
2020-09-10 16:34 ` [PATCH v2] " Keita Suzuki
[not found] ` <59440849-23b1-9c69-ecf6-78f8a0b82c7a@web.de>
2020-09-11 12:49 ` [PATCH] " Keita Suzuki
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).