From: oulijun <oulijun@huawei.com> To: Colin King <colin.king@canonical.com>, Wei Hu <xavier.huwei@huawei.com>, Doug Ledford <dledford@redhat.com>, Jason Gunthorpe <jgg@ziepe.ca>, Tao Tian <tiantao6@huawei.com>, Leon Romanovsky <leon@kernel.org>, Yangyang Li <liyangyang20@huawei.com>, <linux-rdma@vger.kernel.org> Cc: <kernel-janitors@vger.kernel.org>, <linux-kernel@vger.kernel.org> Subject: Re: [PATCH][next] RDMA/hns: fix memory leak on 'context' on error return path Date: Sat, 26 Oct 2019 11:17:51 +0800 [thread overview] Message-ID: <d3fefb17-e16f-bfe2-d244-d5a25309321f@huawei.com> (raw) In-Reply-To: <20191024131034.19989-1-colin.king@canonical.com> 在 2019/10/24 21:10, Colin King 写道: > From: Colin Ian King <colin.king@canonical.com> > > Currently, the error return path when the call to function > dev->dfx->query_cqc_info fails will leak object 'context'. Fix this > by making the error return path via 'err' return return codes rather > than -EMSGSIZE, set ret appropriately for all error return paths and > for the memory leak now return via 'err' with -EINVAL rather than > just returning without freeing context. > > Addresses-Coverity: ("Resource leak") > Fixes: e1c9a0dc2939 ("RDMA/hns: Dump detailed driver-specific CQ") > Signed-off-by: Colin Ian King <colin.king@canonical.com> > --- > drivers/infiniband/hw/hns/hns_roce_restrack.c | 16 +++++++++++----- > 1 file changed, 11 insertions(+), 5 deletions(-) > > diff --git a/drivers/infiniband/hw/hns/hns_roce_restrack.c b/drivers/infiniband/hw/hns/hns_roce_restrack.c > index a0d608ec81c1..7e4a91dd7329 100644 > --- a/drivers/infiniband/hw/hns/hns_roce_restrack.c > +++ b/drivers/infiniband/hw/hns/hns_roce_restrack.c > @@ -94,15 +94,21 @@ static int hns_roce_fill_res_cq_entry(struct sk_buff *msg, > return -ENOMEM; > > ret = hr_dev->dfx->query_cqc_info(hr_dev, hr_cq->cqn, (int *)context); > - if (ret) > - return -EINVAL; > + if (ret) { > + ret = -EINVAL; > + goto err; Why not remove ret = -EINVAL? > + } > > table_attr = nla_nest_start(msg, RDMA_NLDEV_ATTR_DRIVER); > - if (!table_attr) > + if (!table_attr) { > + ret = -EMSGSIZE; > goto err; > + } > > - if (hns_roce_fill_cq(msg, context)) > + if (hns_roce_fill_cq(msg, context)) { > + ret = -EMSGSIZE; > goto err_cancel_table; > + } > > nla_nest_end(msg, table_attr); > kfree(context); > @@ -113,7 +119,7 @@ static int hns_roce_fill_res_cq_entry(struct sk_buff *msg, > nla_nest_cancel(msg, table_attr); > err: > kfree(context); > - return -EMSGSIZE; > + return ret; > } > > int hns_roce_fill_res_entry(struct sk_buff *msg,
WARNING: multiple messages have this Message-ID (diff)
From: oulijun <oulijun@huawei.com> To: Colin King <colin.king@canonical.com>, Wei Hu <xavier.huwei@huawei.com>, Doug Ledford <dledford@redhat.com>, Jason Gunthorpe <jgg@ziepe.ca>, Tao Tian <tiantao6@huawei.com>, Leon Romanovsky <leon@kernel.org>, Yangyang Li <liyangyang20@huawei.com>, linux-rdma@vger.kernel.org Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH][next] RDMA/hns: fix memory leak on 'context' on error return path Date: Sat, 26 Oct 2019 03:17:51 +0000 [thread overview] Message-ID: <d3fefb17-e16f-bfe2-d244-d5a25309321f@huawei.com> (raw) In-Reply-To: <20191024131034.19989-1-colin.king@canonical.com> 在 2019/10/24 21:10, Colin King 写道: > From: Colin Ian King <colin.king@canonical.com> > > Currently, the error return path when the call to function > dev->dfx->query_cqc_info fails will leak object 'context'. Fix this > by making the error return path via 'err' return return codes rather > than -EMSGSIZE, set ret appropriately for all error return paths and > for the memory leak now return via 'err' with -EINVAL rather than > just returning without freeing context. > > Addresses-Coverity: ("Resource leak") > Fixes: e1c9a0dc2939 ("RDMA/hns: Dump detailed driver-specific CQ") > Signed-off-by: Colin Ian King <colin.king@canonical.com> > --- > drivers/infiniband/hw/hns/hns_roce_restrack.c | 16 +++++++++++----- > 1 file changed, 11 insertions(+), 5 deletions(-) > > diff --git a/drivers/infiniband/hw/hns/hns_roce_restrack.c b/drivers/infiniband/hw/hns/hns_roce_restrack.c > index a0d608ec81c1..7e4a91dd7329 100644 > --- a/drivers/infiniband/hw/hns/hns_roce_restrack.c > +++ b/drivers/infiniband/hw/hns/hns_roce_restrack.c > @@ -94,15 +94,21 @@ static int hns_roce_fill_res_cq_entry(struct sk_buff *msg, > return -ENOMEM; > > ret = hr_dev->dfx->query_cqc_info(hr_dev, hr_cq->cqn, (int *)context); > - if (ret) > - return -EINVAL; > + if (ret) { > + ret = -EINVAL; > + goto err; Why not remove ret = -EINVAL? > + } > > table_attr = nla_nest_start(msg, RDMA_NLDEV_ATTR_DRIVER); > - if (!table_attr) > + if (!table_attr) { > + ret = -EMSGSIZE; > goto err; > + } > > - if (hns_roce_fill_cq(msg, context)) > + if (hns_roce_fill_cq(msg, context)) { > + ret = -EMSGSIZE; > goto err_cancel_table; > + } > > nla_nest_end(msg, table_attr); > kfree(context); > @@ -113,7 +119,7 @@ static int hns_roce_fill_res_cq_entry(struct sk_buff *msg, > nla_nest_cancel(msg, table_attr); > err: > kfree(context); > - return -EMSGSIZE; > + return ret; > } > > int hns_roce_fill_res_entry(struct sk_buff *msg,
next prev parent reply other threads:[~2019-10-26 3:18 UTC|newest] Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-10-24 13:10 [PATCH][next] RDMA/hns: fix memory leak on 'context' on error return path Colin King 2019-10-24 13:10 ` Colin King 2019-10-26 3:17 ` oulijun [this message] 2019-10-26 3:17 ` oulijun 2019-10-28 16:54 ` Jason Gunthorpe 2019-10-28 16:54 ` Jason Gunthorpe
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=d3fefb17-e16f-bfe2-d244-d5a25309321f@huawei.com \ --to=oulijun@huawei.com \ --cc=colin.king@canonical.com \ --cc=dledford@redhat.com \ --cc=jgg@ziepe.ca \ --cc=kernel-janitors@vger.kernel.org \ --cc=leon@kernel.org \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-rdma@vger.kernel.org \ --cc=liyangyang20@huawei.com \ --cc=tiantao6@huawei.com \ --cc=xavier.huwei@huawei.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.