Skip to contentSkip to conversation

cxgb3 - avoid potential memory leak.

PATCH Applied Divy Le Ray 2 participants 2 messages Nov 26, 2008

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

PATCH 2/4 cxgb3 - avoid potential memory leak.

From: Divy Le Ray <[email protected]>

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

---

 drivers/net/cxgb3/sge.c |    5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)
drivers/net/cxgb3/sge.c +2 -3
index 268f158..bc6a8dc 100644
@@ -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;
 }