qedr: fix resource leak in qedr_create_qp
Subsystems (3)
A message that is not in the archive (sent off-list or not yet received): [email protected]
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 <[email protected]>:
Quoted 20 lines
Quoted 2 lines
Fix this by adding a new goto label that calls
qedr_free_qp_resources.…
Quoted 1 line
+++
b/drivers/infiniband/hw/qedr/verbs.c…
Quoted 1 line
(quoted diff) +0
-0@@ -2165,11 +2187,13 @@ struct ib_qp *qedr_create_qp(struct ib_pd *ibpd,…
Review
Quoted 6 lines
return &qp->ibqp;(quoted diff) +2
-0+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#n485Regards,
Markus
PATCH v2 1/1 qedr: fix resource leak in qedr_create_qp
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.
adjust idr routines.")
---
changelog(v2): Change numbered labels to descriptive labels
drivers/infiniband/hw/qedr/verbs.c | 52 ++++++++++++++++-------------- 1 file changed, 27 insertions(+), 25 deletions(-)
drivers/infiniband/hw/qedr/verbs.c +27 -25
@@ -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);
Signature · 1 line
2.17.1
A message that is not in the archive (sent off-list or not yet received): [email protected]
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 <[email protected]>:
Quoted 15 lines
Quoted 2 lines
I will re-label the goto statements and post the patch as version 2.
Thanks for such a positive feedback.
Another suggestion:
Quoted 2 lines
Quoted 2 lines
Fixes 1212767e23bb ("qedr: Add wrapping generic structure for qpidr andadjust idr routines.")
Please omit a line break for this tag.
Regards,
Markus