diff mbox

[2/4,2.6.29] cxgb3 - avoid potential memory leak.

Message ID 20081126203820.4819.17969.stgit@speedy5
State Accepted, archived
Delegated to: David Miller
Headers show

Commit Message

Divy Le Ray Nov. 26, 2008, 8:38 p.m. UTC
From: Divy Le Ray <divy@chelsio.com>

Add consistency in alloc_ring() parameter checking
to avoid potential memory leaks.
alloc_ring() callers are correct fo far.

Signed-off-by: Divy Le Ray <divy@chelsio.com>
---

 drivers/net/cxgb3/sge.c |    5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)


--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

David Miller Nov. 26, 2008, 11:36 p.m. UTC | #1
From: Divy Le Ray <divy@chelsio.com>
Date: Wed, 26 Nov 2008 12:38:20 -0800

> From: Divy Le Ray <divy@chelsio.com>
> 
> Add consistency in alloc_ring() parameter checking
> to avoid potential memory leaks.
> alloc_ring() callers are correct fo far.
> 
> Signed-off-by: Divy Le Ray <divy@chelsio.com>

Applied.
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/net/cxgb3/sge.c b/drivers/net/cxgb3/sge.c
index 268f158..bc6a8dc 100644
--- a/drivers/net/cxgb3/sge.c
+++ b/drivers/net/cxgb3/sge.c
@@ -549,16 +549,15 @@  static void *alloc_ring(struct pci_dev *pdev, size_t nelem, size_t elem_size,
 
 	if (!p)
 		return NULL;
-	if (sw_size) {
+	if (sw_size && metadata) {
 		s = kcalloc(nelem, sw_size, GFP_KERNEL);
 
 		if (!s) {
 			dma_free_coherent(&pdev->dev, len, p, *phys);
 			return NULL;
 		}
-	}
-	if (metadata)
 		*(void **)metadata = s;
+	}
 	memset(p, 0, len);
 	return p;
 }