diff options
Diffstat (limited to 'extras/recipes-kernel/linux/linux-omap/linus/0040-Broadcom-CNIC-core-network-driver-fix-mem-leak-on-al.patch')
-rw-r--r-- | extras/recipes-kernel/linux/linux-omap/linus/0040-Broadcom-CNIC-core-network-driver-fix-mem-leak-on-al.patch | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/extras/recipes-kernel/linux/linux-omap/linus/0040-Broadcom-CNIC-core-network-driver-fix-mem-leak-on-al.patch b/extras/recipes-kernel/linux/linux-omap/linus/0040-Broadcom-CNIC-core-network-driver-fix-mem-leak-on-al.patch new file mode 100644 index 00000000..b9be4132 --- /dev/null +++ b/extras/recipes-kernel/linux/linux-omap/linus/0040-Broadcom-CNIC-core-network-driver-fix-mem-leak-on-al.patch | |||
@@ -0,0 +1,58 @@ | |||
1 | From dcb64d3c0d57e8bc674ec4ca6bf7f4812f49f7b2 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/65] Broadcom CNIC core network driver: fix mem leak on allocation failures in cnic_alloc_uio_rings() | ||
5 | |||
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. | ||
10 | |||
11 | Thanks to Joe Perches <joe@perches.com> for suggesting a better | ||
12 | implementation than my initial version. | ||
13 | |||
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> | ||
17 | --- | ||
18 | drivers/net/cnic.c | 10 ++++++++-- | ||
19 | 1 files changed, 8 insertions(+), 2 deletions(-) | ||
20 | |||
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) | ||
26 | &udev->l2_ring_map, | ||
27 | GFP_KERNEL | __GFP_COMP); | ||
28 | if (!udev->l2_ring) | ||
29 | - return -ENOMEM; | ||
30 | + goto err_udev; | ||
31 | |||
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) | ||
35 | &udev->l2_buf_map, | ||
36 | GFP_KERNEL | __GFP_COMP); | ||
37 | if (!udev->l2_buf) | ||
38 | - return -ENOMEM; | ||
39 | + goto err_dma; | ||
40 | |||
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) | ||
44 | cp->udev = udev; | ||
45 | |||
46 | return 0; | ||
47 | + err_dma: | ||
48 | + dma_free_coherent(&udev->pdev->dev, udev->l2_ring_size, | ||
49 | + udev->l2_ring, udev->l2_ring_map); | ||
50 | + err_udev: | ||
51 | + kfree(udev); | ||
52 | + return -ENOMEM; | ||
53 | } | ||
54 | |||
55 | static int cnic_init_uio(struct cnic_dev *dev) | ||
56 | -- | ||
57 | 1.6.6.1 | ||
58 | |||