Patchwork bnx2x: fix mem leak when command is unknown

login
register
mail settings
Submitter Jesper Juhl
Date July 31, 2012, 9:39 p.m.
Message ID <alpine.LNX.2.00.1207312337590.7100@swampdragon.chaosbits.net>
Download mbox | patch
Permalink /patch/174346/
State Accepted
Delegated to: David Miller
Headers show

Comments

Jesper Juhl - July 31, 2012, 9:39 p.m.
In bnx2x_mcast_enqueue_cmd() we'll leak the memory allocated to
'new_cmd' if we hit the deafault case of the 'switch (cmd)'.
Add a 'kfree(new_cmd)' to that case to avoid the leak.

Signed-off-by: Jesper Juhl <jj@chaosbits.net>
---
 drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c | 1 +
 1 file changed, 1 insertion(+)

  note: due to lack of hardware this patch is compile tested only.
Dmitry Kravkov - Aug. 1, 2012, 7:41 a.m.
On Tue, 2012-07-31 at 23:39 +0200, Jesper Juhl wrote:
> In bnx2x_mcast_enqueue_cmd() we'll leak the memory allocated to
> 'new_cmd' if we hit the deafault case of the 'switch (cmd)'.
> Add a 'kfree(new_cmd)' to that case to avoid the leak.
> 
> Signed-off-by: Jesper Juhl <jj@chaosbits.net>
> ---
>  drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c | 1 +
>  1 file changed, 1 insertion(+)
> 
>   note: due to lack of hardware this patch is compile tested only.
> 
> diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
> index 734fd87..62f754b 100644
> --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
> +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
> @@ -2485,6 +2485,7 @@ static int bnx2x_mcast_enqueue_cmd(struct bnx2x *bp,
>  		break;
>  
>  	default:
> +		kfree(new_cmd);
>  		BNX2X_ERR("Unknown command: %d\n", cmd);
>  		return -EINVAL;
>  	}
> -- 
> 1.7.11.3
> 
Thanks a lot, Jesper.

Acked-by: Dmitry Kravkov <dmitry@broadcom.com>
> 



--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
David Miller - Aug. 2, 2012, 7:21 a.m.
From: Jesper Juhl <jj@chaosbits.net>
Date: Tue, 31 Jul 2012 23:39:37 +0200 (CEST)

> In bnx2x_mcast_enqueue_cmd() we'll leak the memory allocated to
> 'new_cmd' if we hit the deafault case of the 'switch (cmd)'.
> Add a 'kfree(new_cmd)' to that case to avoid the leak.
> 
> Signed-off-by: Jesper Juhl <jj@chaosbits.net>

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

Patch

diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
index 734fd87..62f754b 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
@@ -2485,6 +2485,7 @@  static int bnx2x_mcast_enqueue_cmd(struct bnx2x *bp,
 		break;
 
 	default:
+		kfree(new_cmd);
 		BNX2X_ERR("Unknown command: %d\n", cmd);
 		return -EINVAL;
 	}