diff mbox series

IB/mlx4: Fix memory leaks

Message ID 1566159781-4642-1-git-send-email-wenwen@cs.uga.edu (mailing list archive)
State Mainlined
Commit 5c1baaa82cea2c815a5180ded402a7cd455d1810
Headers show
Series IB/mlx4: Fix memory leaks | expand

Commit Message

Wenwen Wang Aug. 18, 2019, 8:23 p.m. UTC
In mlx4_ib_alloc_pv_bufs(), 'tun_qp->tx_ring' is allocated through
kcalloc(). However, it is not always deallocated in the following execution
if an error occurs, leading to memory leaks. To fix this issue, free
'tun_qp->tx_ring' whenever an error occurs.

Signed-off-by: Wenwen Wang <wenwen@cs.uga.edu>
---
 drivers/infiniband/hw/mlx4/mad.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Leon Romanovsky Aug. 19, 2019, 11:56 a.m. UTC | #1
On Sun, Aug 18, 2019 at 03:23:01PM -0500, Wenwen Wang wrote:
> In mlx4_ib_alloc_pv_bufs(), 'tun_qp->tx_ring' is allocated through
> kcalloc(). However, it is not always deallocated in the following execution
> if an error occurs, leading to memory leaks. To fix this issue, free
> 'tun_qp->tx_ring' whenever an error occurs.
>
> Signed-off-by: Wenwen Wang <wenwen@cs.uga.edu>
> ---
>  drivers/infiniband/hw/mlx4/mad.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>

Thanks,
Acked-by: Leon Romanovsky <leonro@mellanox.com>
Doug Ledford Aug. 20, 2019, 5:18 p.m. UTC | #2
On Sun, 2019-08-18 at 15:23 -0500, Wenwen Wang wrote:
> In mlx4_ib_alloc_pv_bufs(), 'tun_qp->tx_ring' is allocated through
> kcalloc(). However, it is not always deallocated in the following
> execution
> if an error occurs, leading to memory leaks. To fix this issue, free
> 'tun_qp->tx_ring' whenever an error occurs.
> 
> Signed-off-by: Wenwen Wang <wenwen@cs.uga.edu>
> ---

Thanks, applied to for-rc.
diff mbox series

Patch

diff --git a/drivers/infiniband/hw/mlx4/mad.c b/drivers/infiniband/hw/mlx4/mad.c
index 68c9514..5707911 100644
--- a/drivers/infiniband/hw/mlx4/mad.c
+++ b/drivers/infiniband/hw/mlx4/mad.c
@@ -1677,8 +1677,6 @@  static int mlx4_ib_alloc_pv_bufs(struct mlx4_ib_demux_pv_ctx *ctx,
 				    tx_buf_size, DMA_TO_DEVICE);
 		kfree(tun_qp->tx_ring[i].buf.addr);
 	}
-	kfree(tun_qp->tx_ring);
-	tun_qp->tx_ring = NULL;
 	i = MLX4_NUM_TUNNEL_BUFS;
 err:
 	while (i > 0) {
@@ -1687,6 +1685,8 @@  static int mlx4_ib_alloc_pv_bufs(struct mlx4_ib_demux_pv_ctx *ctx,
 				    rx_buf_size, DMA_FROM_DEVICE);
 		kfree(tun_qp->ring[i].addr);
 	}
+	kfree(tun_qp->tx_ring);
+	tun_qp->tx_ring = NULL;
 	kfree(tun_qp->ring);
 	tun_qp->ring = NULL;
 	return -ENOMEM;