Skip to contentSkip to conversation

hw: pvrdma: fix memory leak in error path

PATCH Superseded Li Qiang 3 participants 5 messages Jan 3, 2019 – Jan 8, 2019

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Li Qiang

author
#0 lore raw

PATCH 1/1 hw: pvrdma: fix memory leak in error path

Spotted by Coverity: CID 1398595

---
 hw/rdma/vmw/pvrdma_qp_ops.c | 2 ++
 1 file changed, 2 insertions(+)
hw/rdma/vmw/pvrdma_qp_ops.c +2 -0
index 300471a4c9..584be2043e 100644
@@ -168,6 +168,7 @@ int pvrdma_qp_send(PVRDMADev *dev, uint32_t qp_handle)
         sgid = rdma_rm_get_gid(&dev->rdma_dev_res, wqe->hdr.wr.ud.av.gid_index);
         if (!sgid) {
             pr_dbg("Fail to get gid for idx %d\n", wqe->hdr.wr.ud.av.gid_index);
+            g_free(comp_ctx);
             return -EIO;
         }
         pr_dbg("sgid_id=%d, sgid=0x%llx\n", wqe->hdr.wr.ud.av.gid_index,
@@ -179,6 +180,7 @@ int pvrdma_qp_send(PVRDMADev *dev, uint32_t qp_handle)
         if (sgid_idx <= 0) {
             pr_dbg("Fail to get bk sgid_idx for sgid_idx %d\n",
                    wqe->hdr.wr.ud.av.gid_index);
+            g_free(comp_ctx);
             return -EIO;
         }
 
Signature · 1 line
2.17.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 2 lines · Li Qiang

Spotted by Coverity: CID 1398595

Fixes 2b05705dc8
Quoted 1 line
Quoted 25 lines
---
 hw/rdma/vmw/pvrdma_qp_ops.c | 2 ++
 1 file changed, 2 insertions(+)
hw/rdma/vmw/pvrdma_qp_ops.c +2 -0
index 300471a4c9..584be2043e 100644
@@ -168,6 +168,7 @@ int pvrdma_qp_send(PVRDMADev *dev, uint32_t qp_handle)
         sgid = rdma_rm_get_gid(&dev->rdma_dev_res, wqe->hdr.wr.ud.av.gid_index);
         if (!sgid) {
             pr_dbg("Fail to get gid for idx %d\n", wqe->hdr.wr.ud.av.gid_index);
+            g_free(comp_ctx);
             return -EIO;
         }
         pr_dbg("sgid_id=%d, sgid=0x%llx\n", wqe->hdr.wr.ud.av.gid_index,
@@ -179,6 +180,7 @@ int pvrdma_qp_send(PVRDMADev *dev, uint32_t qp_handle)
         if (sgid_idx <= 0) {
             pr_dbg("Fail to get bk sgid_idx for sgid_idx %d\n",
                    wqe->hdr.wr.ud.av.gid_index);
+            g_free(comp_ctx);
             return -EIO;
         }
 
#2 lore raw
Quoted 25 lines · Philippe Mathieu-Daudé
Quoted 2 lines · Li Qiang

Spotted by Coverity: CID 1398595

Fixes 2b05705dc8
Quoted 1 line
Quoted 15 lines
---
 hw/rdma/vmw/pvrdma_qp_ops.c | 2 ++
 1 file changed, 2 insertions(+)
hw/rdma/vmw/pvrdma_qp_ops.c +1 -0
index 300471a4c9..584be2043e 100644
@@ -168,6 +168,7 @@ int pvrdma_qp_send(PVRDMADev *dev, uint32_t qp_handle)
         sgid = rdma_rm_get_gid(&dev->rdma_dev_res, wqe->hdr.wr.ud.av.gid_index);
         if (!sgid) {
             pr_dbg("Fail to get gid for idx %d\n", wqe->hdr.wr.ud.av.gid_index);
+            g_free(comp_ctx);
             return -EIO;
         }
Quoted 8 lines

hw/rdma/vmw/pvrdma_qp_ops.c int pvrdma_qp_send(PVRDMADev *dev, uint32_t qp_handle) · line 185

Quoted 8 lines
hw/rdma/vmw/pvrdma_qp_ops.c +1 -0
         pr_dbg("sgid_id=%d, sgid=0x%llx\n", wqe->hdr.wr.ud.av.gid_index,
@@ -179,6 +180,7 @@ int pvrdma_qp_send(PVRDMADev *dev, uint32_t qp_handle)
         if (sgid_idx <= 0) {
             pr_dbg("Fail to get bk sgid_idx for sgid_idx %d\n",
                    wqe->hdr.wr.ud.av.gid_index);
+            g_free(comp_ctx);
             return -EIO;
         }

Since comp_ctx is not used until the two checks are done we just can relocate the allocation & initialization right after the two checks.

Yuval

Quoted 2 lines
Quoted 2 lines
author
#3 lore raw
Quoted 29 lines · Yuval Shaia
Quoted 28 lines · Philippe Mathieu-Daudé
Quoted 2 lines · Li Qiang

Spotted by Coverity: CID 1398595

Fixes 2b05705dc8
Quoted 1 line
Quoted 18 lines
---
 hw/rdma/vmw/pvrdma_qp_ops.c | 2 ++
 1 file changed, 2 insertions(+)
hw/rdma/vmw/pvrdma_qp_ops.c +1 -0
index 300471a4c9..584be2043e 100644
@@ -168,6 +168,7 @@ int pvrdma_qp_send(PVRDMADev *dev, uint32_t qp_handle)
         sgid = rdma_rm_get_gid(&dev->rdma_dev_res, wqe->hdr.wr.ud.av.gid_index);
         if (!sgid) {
             pr_dbg("Fail to get gid for idx %d\n", wqe->hdr.wr.ud.av.gid_index);
+            g_free(comp_ctx);
             return -EIO;
         }
         pr_dbg("sgid_id=%d, sgid=0x%llx\n", wqe->hdr.wr.ud.av.gid_index,
@@ -179,6 +180,7 @@ int pvrdma_qp_send(PVRDMADev *dev, uint32_t qp_handle)
         if (sgid_idx <= 0) {
Quoted 10 lines
Quoted 5 lines

hw/rdma/vmw/pvrdma_qp_ops.c int pvrdma_qp_send(PVRDMADev *dev, uint32_t qp_handle) · line 185

Quoted 5 lines
hw/rdma/vmw/pvrdma_qp_ops.c +1 -0
             pr_dbg("Fail to get bk sgid_idx for sgid_idx %d\n",
                    wqe->hdr.wr.ud.av.gid_index);
+            g_free(comp_ctx);
             return -EIO;
         }

Since comp_ctx is not used until the two checks are done we just can relocate the allocation & initialization right after the two checks.

OK, will send a revised version later.

Thanks,
Li Qiang

Quoted 4 lines

Yuval

Quoted 2 lines
Quoted 2 lines
#4 lore raw
In reply to Yuval Shaia
Quoted 29 lines · Yuval Shaia
Quoted 28 lines · Philippe Mathieu-Daudé
Quoted 2 lines · Li Qiang

Spotted by Coverity: CID 1398595

Fixes 2b05705dc8
Quoted 1 line
Quoted 18 lines
---
 hw/rdma/vmw/pvrdma_qp_ops.c | 2 ++
 1 file changed, 2 insertions(+)
hw/rdma/vmw/pvrdma_qp_ops.c +1 -0
index 300471a4c9..584be2043e 100644
@@ -168,6 +168,7 @@ int pvrdma_qp_send(PVRDMADev *dev, uint32_t qp_handle)
         sgid = rdma_rm_get_gid(&dev->rdma_dev_res, wqe->hdr.wr.ud.av.gid_index);
         if (!sgid) {
             pr_dbg("Fail to get gid for idx %d\n", wqe->hdr.wr.ud.av.gid_index);
+            g_free(comp_ctx);
             return -EIO;
         }
         pr_dbg("sgid_id=%d, sgid=0x%llx\n", wqe->hdr.wr.ud.av.gid_index,
@@ -179,6 +180,7 @@ int pvrdma_qp_send(PVRDMADev *dev, uint32_t qp_handle)
         if (sgid_idx <= 0) {
Quoted 8 lines
Quoted 5 lines

hw/rdma/vmw/pvrdma_qp_ops.c int pvrdma_qp_send(PVRDMADev *dev, uint32_t qp_handle) · line 185

Quoted 5 lines
hw/rdma/vmw/pvrdma_qp_ops.c +1 -0
             pr_dbg("Fail to get bk sgid_idx for sgid_idx %d\n",
                    wqe->hdr.wr.ud.av.gid_index);
+            g_free(comp_ctx);
             return -EIO;
         }

Since comp_ctx is not used until the two checks are done we just can relocate the allocation & initialization right after the two checks.

Oops I missed this, thanks your suggestion is way cleaner!

Phil.