netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH][next] net/mlx4_core: fix memory leaks on error exit path
@ 2017-08-31 16:30 Colin King
  2017-09-03  7:19 ` Tariq Toukan
  2017-09-03 17:57 ` David Miller
  0 siblings, 2 replies; 3+ messages in thread
From: Colin King @ 2017-08-31 16:30 UTC (permalink / raw)
  To: Tariq Toukan, netdev-u79uwXL29TY76Z2rM5mHXA,
	linux-rdma-u79uwXL29TY76Z2rM5mHXA
  Cc: kernel-janitors-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA

From: Colin Ian King <colin.king-Z7WLFzj8eWMS+FvcfC7Uqw@public.gmane.org>

The structures hca_param and func_cap are not being kfree'd on an error
exit path causing two memory leaks. Fix this by jumping to the existing
free memory error exit path.

Detected by CoverityScan, CID#1455219, CID#1455224 ("Resource Leak")

Fixes: c73c8b1e47ca ("net/mlx4_core: Dynamically allocate structs at mlx4_slave_cap")
Signed-off-by: Colin Ian King <colin.king-Z7WLFzj8eWMS+FvcfC7Uqw@public.gmane.org>
---
 drivers/net/ethernet/mellanox/mlx4/main.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/mellanox/mlx4/main.c b/drivers/net/ethernet/mellanox/mlx4/main.c
index 1c92101b3ec2..d46f3283ec36 100644
--- a/drivers/net/ethernet/mellanox/mlx4/main.c
+++ b/drivers/net/ethernet/mellanox/mlx4/main.c
@@ -977,7 +977,8 @@ static int mlx4_slave_cap(struct mlx4_dev *dev)
 	if (dev->caps.num_ports > MLX4_MAX_PORTS) {
 		mlx4_err(dev, "HCA has %d ports, but we only support %d, aborting\n",
 			 dev->caps.num_ports, MLX4_MAX_PORTS);
-		return -ENODEV;
+		err = -ENODEV;
+		goto free_mem;
 	}
 
 	mlx4_replace_zero_macs(dev);
-- 
2.14.1

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH][next] net/mlx4_core: fix memory leaks on error exit path
  2017-08-31 16:30 [PATCH][next] net/mlx4_core: fix memory leaks on error exit path Colin King
@ 2017-09-03  7:19 ` Tariq Toukan
  2017-09-03 17:57 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: Tariq Toukan @ 2017-09-03  7:19 UTC (permalink / raw)
  To: Colin King, Tariq Toukan, netdev, linux-rdma
  Cc: kernel-janitors, linux-kernel


On 31/08/2017 7:30 PM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> The structures hca_param and func_cap are not being kfree'd on an error
> exit path causing two memory leaks. Fix this by jumping to the existing
> free memory error exit path.
> 
> Detected by CoverityScan, CID#1455219, CID#1455224 ("Resource Leak")
> 
> Fixes: c73c8b1e47ca ("net/mlx4_core: Dynamically allocate structs at mlx4_slave_cap")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   drivers/net/ethernet/mellanox/mlx4/main.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/ethernet/mellanox/mlx4/main.c b/drivers/net/ethernet/mellanox/mlx4/main.c
> index 1c92101b3ec2..d46f3283ec36 100644
> --- a/drivers/net/ethernet/mellanox/mlx4/main.c
> +++ b/drivers/net/ethernet/mellanox/mlx4/main.c
> @@ -977,7 +977,8 @@ static int mlx4_slave_cap(struct mlx4_dev *dev)
>   	if (dev->caps.num_ports > MLX4_MAX_PORTS) {
>   		mlx4_err(dev, "HCA has %d ports, but we only support %d, aborting\n",
>   			 dev->caps.num_ports, MLX4_MAX_PORTS);
> -		return -ENODEV;
> +		err = -ENODEV;
> +		goto free_mem;
>   	}
>   
>   	mlx4_replace_zero_macs(dev);
> 

Acked-by: Tariq Toukan <tariqt@mellanox.com>

Thanks Colin!

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

* Re: [PATCH][next] net/mlx4_core: fix memory leaks on error exit path
  2017-08-31 16:30 [PATCH][next] net/mlx4_core: fix memory leaks on error exit path Colin King
  2017-09-03  7:19 ` Tariq Toukan
@ 2017-09-03 17:57 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2017-09-03 17:57 UTC (permalink / raw)
  To: colin.king; +Cc: tariqt, netdev, linux-rdma, kernel-janitors, linux-kernel

From: Colin King <colin.king@canonical.com>
Date: Thu, 31 Aug 2017 17:30:53 +0100

> From: Colin Ian King <colin.king@canonical.com>
> 
> The structures hca_param and func_cap are not being kfree'd on an error
> exit path causing two memory leaks. Fix this by jumping to the existing
> free memory error exit path.
> 
> Detected by CoverityScan, CID#1455219, CID#1455224 ("Resource Leak")
> 
> Fixes: c73c8b1e47ca ("net/mlx4_core: Dynamically allocate structs at mlx4_slave_cap")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>

Applied.

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

end of thread, other threads:[~2017-09-03 17:57 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-31 16:30 [PATCH][next] net/mlx4_core: fix memory leaks on error exit path Colin King
2017-09-03  7:19 ` Tariq Toukan
2017-09-03 17:57 ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).