Skip to contentSkip to conversation

RDMA/ocrdma: Fix memory leak in _ocrdma_alloc_pd()

PATCH In review Roland Dreier 3 participants 3 messages May 30, 2015 – Jun 1, 2015 2 messages not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/3 RDMA/ocrdma: Fix memory leak in _ocrdma_alloc_pd()

From: Roland Dreier <[email protected]>

If ocrdma_get_pd_num() fails, then we need to free the pd struct we allocated.

This was detected by Coverity (CID 1271245).

---
 drivers/infiniband/hw/ocrdma/ocrdma_verbs.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/infiniband/hw/ocrdma/ocrdma_verbs.c +6 -1
index 9dcb66077d6c..fcb86749efc9 100644
@@ -375,7 +375,12 @@ static struct ocrdma_pd *_ocrdma_alloc_pd(struct ocrdma_dev *dev,
 
 	if (dev->pd_mgr->pd_prealloc_valid) {
 		status = ocrdma_get_pd_num(dev, pd);
-		return (status == 0) ? pd : ERR_PTR(status);
+		if (status == 0) {
+			return pd;
+		} else {
+			kfree(pd);
+			return ERR_PTR(status);
+		}
 	}
 
 retry:
Signature · 6 lines
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 1432966231-12125-1-git-send-email-roland-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org

#2 lore raw
Quoted 7 lines · Roland Dreier

From: Roland Dreier <[email protected]>

If ocrdma_get_pd_num() fails, then we need to free the pd struct we allocated.

This was detected by Coverity (CID 1271245).

Thanks, series applied.

Quoted 22 lines
---
 drivers/infiniband/hw/ocrdma/ocrdma_verbs.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/infiniband/hw/ocrdma/ocrdma_verbs.c +6 -1
index 9dcb66077d6c..fcb86749efc9 100644
@@ -375,7 +375,12 @@ static struct ocrdma_pd *_ocrdma_alloc_pd(struct ocrdma_dev *dev,
 
 	if (dev->pd_mgr->pd_prealloc_valid) {
 		status = ocrdma_get_pd_num(dev, pd);
-		return (status == 0) ? pd : ERR_PTR(status);
+		if (status == 0) {
+			return pd;
+		} else {
+			kfree(pd);
+			return ERR_PTR(status);
+		}
 	}
 
 retry:
Signature · 2 lines
Doug Ledford <[email protected]>
              GPG KeyID: 0E572FDD

A message that is not in the archive (sent off-list or not yet received): 1432999586.114391.158.camel-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org

Acked-by
#4 lore raw
Quoted 32 lines · Doug Ledford
Quoted 7 lines · Roland Dreier

From: Roland Dreier <[email protected]>

If ocrdma_get_pd_num() fails, then we need to free the pd struct we allocated.

This was detected by Coverity (CID 1271245).

Thanks, series applied.

Quoted 21 lines
---
 drivers/infiniband/hw/ocrdma/ocrdma_verbs.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/infiniband/hw/ocrdma/ocrdma_verbs.c +6 -1
index 9dcb66077d6c..fcb86749efc9 100644
@@ -375,7 +375,12 @@ static struct ocrdma_pd *_ocrdma_alloc_pd(struct ocrdma_dev *dev,
 
      if (dev->pd_mgr->pd_prealloc_valid) {
              status = ocrdma_get_pd_num(dev, pd);
-             return (status == 0) ? pd : ERR_PTR(status);
+             if (status == 0) {
+                     return pd;
+             } else {
+                     kfree(pd);
+                     return ERR_PTR(status);
+             }
      }
 
Quoted 7 lines

drivers/infiniband/hw/ocrdma/ocrdma_verbs.c static struct ocrdma_pd *_ocrdma_alloc_pd(struct ocrdma_dev *dev, · line 386

Quoted 1 line
drivers/infiniband/hw/ocrdma/ocrdma_verbs.c +0 -0
 retry:

--
Doug Ledford <[email protected]>

              GPG KeyID: 0E572FDD

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html