RDMA/hns: fix memory leak on 'context' on error return path
Subsystems (3)
PATCH 1/1 RDMA/hns: fix memory leak on 'context' on error return path
From: Colin Ian King <[email protected]>
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")
--- drivers/infiniband/hw/hns/hns_roce_restrack.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)
drivers/infiniband/hw/hns/hns_roce_restrack.c +11 -5
@@ -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; + } 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,
Signature · 1 line
2.20.1
Quoted 21 lines · Colin King
From: Colin Ian King <[email protected]>
Currently, the error return path when the call to function
dev->dfx->query_cqc_infofails 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-EINVALrather 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 <[email protected]>--- drivers/infiniband/hw/hns/hns_roce_restrack.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)drivers/infiniband/hw/hns/hns_roce_restrack.c +0
-0
drivers/infiniband/hw/hns/hns_roce_restrack.c static int hns_roce_fill_res_cq_entry(struct sk_buff *msg, · line 99
Quoted 8 lines
drivers/infiniband/hw/hns/hns_roce_restrack.c +3
-2@@ -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?
Quoted 26 lines
drivers/infiniband/hw/hns/hns_roce_restrack.c +8
-3+ } 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,
Jason Gunthorpe
AppliedQuoted 9 lines · Colin King
From: Colin Ian King <[email protected]>
Currently, the error return path when the call to function
dev->dfx->query_cqc_infofails 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-EINVALrather than just returning without freeing context.
Quoted 6 lines
Addresses-Coverity: ("Resource leak")
Fixes e1c9a0dc2939 ("RDMA/hns: Dump detailed driver-specific CQ")Signed-off-by Colin Ian King <[email protected]>--- drivers/infiniband/hw/hns/hns_roce_restrack.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)
Applied to for-next with the note to remove the EINVAL return
Thanks,
Jason