Commit 994195e1 authored by Colin Ian King's avatar Colin Ian King Committed by Jason Gunthorpe

RDMA/hns: Fix memory leak on 'context' on error return path

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' rather than just returning without
freeing context.

Link: https://lore.kernel.org/r/20191024131034.19989-1-colin.king@canonical.com
Addresses-Coverity: ("Resource leak")
Fixes: e1c9a0dc ("RDMA/hns: Dump detailed driver-specific CQ")
Signed-off-by: default avatarColin Ian King <colin.king@canonical.com>
Reviewed-by: default avatarJason Gunthorpe <jgg@mellanox.com>
Signed-off-by: default avatarJason Gunthorpe <jgg@mellanox.com>
parent 887803db
...@@ -95,14 +95,18 @@ static int hns_roce_fill_res_cq_entry(struct sk_buff *msg, ...@@ -95,14 +95,18 @@ static int hns_roce_fill_res_cq_entry(struct sk_buff *msg,
ret = hr_dev->dfx->query_cqc_info(hr_dev, hr_cq->cqn, (int *)context); ret = hr_dev->dfx->query_cqc_info(hr_dev, hr_cq->cqn, (int *)context);
if (ret) if (ret)
return -EINVAL; goto err;
table_attr = nla_nest_start(msg, RDMA_NLDEV_ATTR_DRIVER); table_attr = nla_nest_start(msg, RDMA_NLDEV_ATTR_DRIVER);
if (!table_attr) if (!table_attr) {
ret = -EMSGSIZE;
goto err; goto err;
}
if (hns_roce_fill_cq(msg, context)) if (hns_roce_fill_cq(msg, context)) {
ret = -EMSGSIZE;
goto err_cancel_table; goto err_cancel_table;
}
nla_nest_end(msg, table_attr); nla_nest_end(msg, table_attr);
kfree(context); kfree(context);
...@@ -113,7 +117,7 @@ static int hns_roce_fill_res_cq_entry(struct sk_buff *msg, ...@@ -113,7 +117,7 @@ static int hns_roce_fill_res_cq_entry(struct sk_buff *msg,
nla_nest_cancel(msg, table_attr); nla_nest_cancel(msg, table_attr);
err: err:
kfree(context); kfree(context);
return -EMSGSIZE; return ret;
} }
int hns_roce_fill_res_entry(struct sk_buff *msg, int hns_roce_fill_res_entry(struct sk_buff *msg,
......
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