diff options
author | Jesper Juhl <jj@chaosbits.net> | 2010-12-31 14:18:48 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2010-12-31 14:18:48 -0500 |
commit | f7e4c9775ea648deed4a8193951e50d0c7706173 (patch) | |
tree | 552432919518946318a2fcec90365f4f5006cf8e /drivers | |
parent | 2393c944d5d60eedaede80273ede8a816b5fa3e0 (diff) |
Broadcom CNIC core network driver: fix mem leak on allocation failures in cnic_alloc_uio_rings()
We are leaking memory in drivers/net/cnic.c::cnic_alloc_uio_rings() if
either of the calls to dma_alloc_coherent() fail. This patch fixes it by
freeing both the memory allocated with kzalloc() and memory allocated with
previous calls to dma_alloc_coherent() when there's a failure.
Thanks to Joe Perches <joe@perches.com> for suggesting a better
implementation than my initial version.
Signed-off-by: Jesper Juhl <jj@chaosbits.net>
Acked-by: Michael Chan <mchan@broadcom.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/net/cnic.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/drivers/net/cnic.c b/drivers/net/cnic.c index 92bac19ad60a..6dff32196c92 100644 --- a/drivers/net/cnic.c +++ b/drivers/net/cnic.c | |||
@@ -940,7 +940,7 @@ static int cnic_alloc_uio_rings(struct cnic_dev *dev, int pages) | |||
940 | &udev->l2_ring_map, | 940 | &udev->l2_ring_map, |
941 | GFP_KERNEL | __GFP_COMP); | 941 | GFP_KERNEL | __GFP_COMP); |
942 | if (!udev->l2_ring) | 942 | if (!udev->l2_ring) |
943 | return -ENOMEM; | 943 | goto err_udev; |
944 | 944 | ||
945 | udev->l2_buf_size = (cp->l2_rx_ring_size + 1) * cp->l2_single_buf_size; | 945 | udev->l2_buf_size = (cp->l2_rx_ring_size + 1) * cp->l2_single_buf_size; |
946 | udev->l2_buf_size = PAGE_ALIGN(udev->l2_buf_size); | 946 | udev->l2_buf_size = PAGE_ALIGN(udev->l2_buf_size); |
@@ -948,7 +948,7 @@ static int cnic_alloc_uio_rings(struct cnic_dev *dev, int pages) | |||
948 | &udev->l2_buf_map, | 948 | &udev->l2_buf_map, |
949 | GFP_KERNEL | __GFP_COMP); | 949 | GFP_KERNEL | __GFP_COMP); |
950 | if (!udev->l2_buf) | 950 | if (!udev->l2_buf) |
951 | return -ENOMEM; | 951 | goto err_dma; |
952 | 952 | ||
953 | write_lock(&cnic_dev_lock); | 953 | write_lock(&cnic_dev_lock); |
954 | list_add(&udev->list, &cnic_udev_list); | 954 | list_add(&udev->list, &cnic_udev_list); |
@@ -959,6 +959,12 @@ static int cnic_alloc_uio_rings(struct cnic_dev *dev, int pages) | |||
959 | cp->udev = udev; | 959 | cp->udev = udev; |
960 | 960 | ||
961 | return 0; | 961 | return 0; |
962 | err_dma: | ||
963 | dma_free_coherent(&udev->pdev->dev, udev->l2_ring_size, | ||
964 | udev->l2_ring, udev->l2_ring_map); | ||
965 | err_udev: | ||
966 | kfree(udev); | ||
967 | return -ENOMEM; | ||
962 | } | 968 | } |
963 | 969 | ||
964 | static int cnic_init_uio(struct cnic_dev *dev) | 970 | static int cnic_init_uio(struct cnic_dev *dev) |