Linux-RDMA Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH v2] net/mlx4_en: fix a memory leak bug
@ 2019-08-12 19:11 Wenwen Wang
  2019-08-13 14:39 ` Tariq Toukan
  2019-08-14  2:46 ` Jakub Kicinski
  0 siblings, 2 replies; 3+ messages in thread
From: Wenwen Wang @ 2019-08-12 19:11 UTC (permalink / raw)
  To: Wenwen Wang
  Cc: Tariq Toukan, David S. Miller, netdev, linux-rdma, linux-kernel

In mlx4_en_config_rss_steer(), 'rss_map->indir_qp' is allocated through
kzalloc(). After that, mlx4_qp_alloc() is invoked to configure RSS
indirection. However, if mlx4_qp_alloc() fails, the allocated
'rss_map->indir_qp' is not deallocated, leading to a memory leak bug.

To fix the above issue, add the 'qp_alloc_err' label to free
'rss_map->indir_qp'.

Fixes: 4931c6ef04b4 ("net/mlx4_en: Optimized single ring steering")

Signed-off-by: Wenwen Wang <wenwen@cs.uga.edu>
---
 drivers/net/ethernet/mellanox/mlx4/en_rx.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/mellanox/mlx4/en_rx.c b/drivers/net/ethernet/mellanox/mlx4/en_rx.c
index 6c01314..db3552f 100644
--- a/drivers/net/ethernet/mellanox/mlx4/en_rx.c
+++ b/drivers/net/ethernet/mellanox/mlx4/en_rx.c
@@ -1187,7 +1187,7 @@ int mlx4_en_config_rss_steer(struct mlx4_en_priv *priv)
 	err = mlx4_qp_alloc(mdev->dev, priv->base_qpn, rss_map->indir_qp);
 	if (err) {
 		en_err(priv, "Failed to allocate RSS indirection QP\n");
-		goto rss_err;
+		goto qp_alloc_err;
 	}
 
 	rss_map->indir_qp->event = mlx4_en_sqp_event;
@@ -1241,6 +1241,7 @@ int mlx4_en_config_rss_steer(struct mlx4_en_priv *priv)
 		       MLX4_QP_STATE_RST, NULL, 0, 0, rss_map->indir_qp);
 	mlx4_qp_remove(mdev->dev, rss_map->indir_qp);
 	mlx4_qp_free(mdev->dev, rss_map->indir_qp);
+qp_alloc_err:
 	kfree(rss_map->indir_qp);
 	rss_map->indir_qp = NULL;
 rss_err:
-- 
2.7.4


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] net/mlx4_en: fix a memory leak bug
  2019-08-12 19:11 [PATCH v2] net/mlx4_en: fix a memory leak bug Wenwen Wang
@ 2019-08-13 14:39 ` Tariq Toukan
  2019-08-14  2:46 ` Jakub Kicinski
  1 sibling, 0 replies; 3+ messages in thread
From: Tariq Toukan @ 2019-08-13 14:39 UTC (permalink / raw)
  To: Wenwen Wang
  Cc: Tariq Toukan, David S. Miller,
	open list:MELLANOX ETHERNET DRIVER (mlx4_en),
	open list:MELLANOX MLX4 core VPI driver, open list



On 8/12/2019 10:11 PM, Wenwen Wang wrote:
> In mlx4_en_config_rss_steer(), 'rss_map->indir_qp' is allocated through
> kzalloc(). After that, mlx4_qp_alloc() is invoked to configure RSS
> indirection. However, if mlx4_qp_alloc() fails, the allocated
> 'rss_map->indir_qp' is not deallocated, leading to a memory leak bug.
> 
> To fix the above issue, add the 'qp_alloc_err' label to free
> 'rss_map->indir_qp'.
> 
> Fixes: 4931c6ef04b4 ("net/mlx4_en: Optimized single ring steering")
> 
> Signed-off-by: Wenwen Wang <wenwen@cs.uga.edu>
> ---
>   drivers/net/ethernet/mellanox/mlx4/en_rx.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/ethernet/mellanox/mlx4/en_rx.c b/drivers/net/ethernet/mellanox/mlx4/en_rx.c
> index 6c01314..db3552f 100644
> --- a/drivers/net/ethernet/mellanox/mlx4/en_rx.c
> +++ b/drivers/net/ethernet/mellanox/mlx4/en_rx.c
> @@ -1187,7 +1187,7 @@ int mlx4_en_config_rss_steer(struct mlx4_en_priv *priv)
>   	err = mlx4_qp_alloc(mdev->dev, priv->base_qpn, rss_map->indir_qp);
>   	if (err) {
>   		en_err(priv, "Failed to allocate RSS indirection QP\n");
> -		goto rss_err;
> +		goto qp_alloc_err;
>   	}
>   
>   	rss_map->indir_qp->event = mlx4_en_sqp_event;
> @@ -1241,6 +1241,7 @@ int mlx4_en_config_rss_steer(struct mlx4_en_priv *priv)
>   		       MLX4_QP_STATE_RST, NULL, 0, 0, rss_map->indir_qp);
>   	mlx4_qp_remove(mdev->dev, rss_map->indir_qp);
>   	mlx4_qp_free(mdev->dev, rss_map->indir_qp);
> +qp_alloc_err:
>   	kfree(rss_map->indir_qp);
>   	rss_map->indir_qp = NULL;
>   rss_err:
> 

Thanks for your patch.
Reviewed-by: Tariq Toukan <tariqt@mellanox.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] net/mlx4_en: fix a memory leak bug
  2019-08-12 19:11 [PATCH v2] net/mlx4_en: fix a memory leak bug Wenwen Wang
  2019-08-13 14:39 ` Tariq Toukan
@ 2019-08-14  2:46 ` Jakub Kicinski
  1 sibling, 0 replies; 3+ messages in thread
From: Jakub Kicinski @ 2019-08-14  2:46 UTC (permalink / raw)
  To: Wenwen Wang
  Cc: Tariq Toukan, David S. Miller, netdev, linux-rdma, linux-kernel

On Mon, 12 Aug 2019 14:11:35 -0500, Wenwen Wang wrote:
> In mlx4_en_config_rss_steer(), 'rss_map->indir_qp' is allocated through
> kzalloc(). After that, mlx4_qp_alloc() is invoked to configure RSS
> indirection. However, if mlx4_qp_alloc() fails, the allocated
> 'rss_map->indir_qp' is not deallocated, leading to a memory leak bug.
> 
> To fix the above issue, add the 'qp_alloc_err' label to free
> 'rss_map->indir_qp'.
> 
> Fixes: 4931c6ef04b4 ("net/mlx4_en: Optimized single ring steering")
> Signed-off-by: Wenwen Wang <wenwen@cs.uga.edu>

Applied, thanks.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-12 19:11 [PATCH v2] net/mlx4_en: fix a memory leak bug Wenwen Wang
2019-08-13 14:39 ` Tariq Toukan
2019-08-14  2:46 ` Jakub Kicinski

Linux-RDMA Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-rdma/0 linux-rdma/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-rdma linux-rdma/ https://lore.kernel.org/linux-rdma \
		linux-rdma@vger.kernel.org linux-rdma@archiver.kernel.org
	public-inbox-index linux-rdma


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-rdma


AGPL code for this site: git clone https://public-inbox.org/ public-inbox