1 From f7e4c9775ea648deed4a8193951e50d0c7706173 Mon Sep 17 00:00:00 2001
2 From: Jesper Juhl <jj@chaosbits.net>
3 Date: Fri, 31 Dec 2010 11:18:48 -0800
4 Subject: [PATCH 40/66] Broadcom CNIC core network driver: fix mem leak on allocation failures in cnic_alloc_uio_rings()
6 We are leaking memory in drivers/net/cnic.c::cnic_alloc_uio_rings() if
7 either of the calls to dma_alloc_coherent() fail. This patch fixes it by
8 freeing both the memory allocated with kzalloc() and memory allocated with
9 previous calls to dma_alloc_coherent() when there's a failure.
11 Thanks to Joe Perches <joe@perches.com> for suggesting a better
12 implementation than my initial version.
14 Signed-off-by: Jesper Juhl <jj@chaosbits.net>
15 Acked-by: Michael Chan <mchan@broadcom.com>
16 Signed-off-by: David S. Miller <davem@davemloft.net>
18 drivers/net/cnic.c | 10 ++++++++--
19 1 files changed, 8 insertions(+), 2 deletions(-)
21 diff --git a/drivers/net/cnic.c b/drivers/net/cnic.c
22 index 92bac19..6dff321 100644
23 --- a/drivers/net/cnic.c
24 +++ b/drivers/net/cnic.c
25 @@ -940,7 +940,7 @@ static int cnic_alloc_uio_rings(struct cnic_dev *dev, int pages)
27 GFP_KERNEL | __GFP_COMP);
32 udev->l2_buf_size = (cp->l2_rx_ring_size + 1) * cp->l2_single_buf_size;
33 udev->l2_buf_size = PAGE_ALIGN(udev->l2_buf_size);
34 @@ -948,7 +948,7 @@ static int cnic_alloc_uio_rings(struct cnic_dev *dev, int pages)
36 GFP_KERNEL | __GFP_COMP);
41 write_lock(&cnic_dev_lock);
42 list_add(&udev->list, &cnic_udev_list);
43 @@ -959,6 +959,12 @@ static int cnic_alloc_uio_rings(struct cnic_dev *dev, int pages)
48 + dma_free_coherent(&udev->pdev->dev, udev->l2_ring_size,
49 + udev->l2_ring, udev->l2_ring_map);
55 static int cnic_init_uio(struct cnic_dev *dev)