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 <kamalhe...@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
_______________________________________________
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

Reply via email to