[PATCH V2] staging: mt7621-eth: Fix memory leak in mtk_add_mac() error path

Greg Kroah-Hartman gregkh at linuxfoundation.org
Mon Jun 18 08:52:01 UTC 2018


On Sat, Jun 16, 2018 at 01:01:27PM +0300, Kamal Heib wrote:
> Fix memory leak in error path of mtk_add_mac() by make sure to free
> the allocated netdev.
> 
> Fixes: e3cbf478f846 ('staging: mt7621-eth: add the drivers core files')
> Signed-off-by: Kamal Heib <kamalheib1 at gmail.com>
> ---
> Changes from v1:
> 	No need to free the hw_stats.
> 
>  drivers/staging/mt7621-eth/mtk_eth_soc.c | 14 +++++++++++---
>  1 file changed, 11 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/staging/mt7621-eth/mtk_eth_soc.c b/drivers/staging/mt7621-eth/mtk_eth_soc.c
> index 2c7a2e666bfb..c240c27dc654 100644
> --- a/drivers/staging/mt7621-eth/mtk_eth_soc.c
> +++ b/drivers/staging/mt7621-eth/mtk_eth_soc.c
> @@ -2012,8 +2012,11 @@ static int mtk_add_mac(struct mtk_eth *eth, struct device_node *np)
>  		mac->hw_stats = devm_kzalloc(eth->dev,
>  					     sizeof(*mac->hw_stats),
>  					     GFP_KERNEL);
> -		if (!mac->hw_stats)
> -			return -ENOMEM;
> +		if (!mac->hw_stats) {
> +			dev_err(eth->dev, "failed to allocate hw_stats\n");

No need to shout about an error, when memory allocation fails, there
will be a message sent to the kernel log about it.

thanks,

greg k-h


More information about the devel mailing list