From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-bn3nam01on0109.outbound.protection.outlook.com ([104.47.33.109]:29664 "EHLO NAM01-BN3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729322AbeIQI1Z (ORCPT ); Mon, 17 Sep 2018 04:27:25 -0400 From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: Kamal Heib , Greg Kroah-Hartman , Sasha Levin Subject: [PATCH AUTOSEL 4.18 077/136] staging: mt7621-eth: Fix memory leak in mtk_add_mac() error path Date: Mon, 17 Sep 2018 03:01:00 +0000 Message-ID: <20180917030006.245495-77-alexander.levin@microsoft.com> References: <20180917030006.245495-1-alexander.levin@microsoft.com> In-Reply-To: <20180917030006.245495-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: Kamal Heib [ Upstream commit 85e1d42663a0c163002961d2685be952067b0dc2 ] 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 Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/staging/mt7621-eth/mtk_eth_soc.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/drivers/staging/mt7621-eth/mtk_eth_soc.c b/drivers/staging/mt7= 621-eth/mtk_eth_soc.c index 2c7a2e666bfb..381d9d270bf5 100644 --- a/drivers/staging/mt7621-eth/mtk_eth_soc.c +++ b/drivers/staging/mt7621-eth/mtk_eth_soc.c @@ -2012,8 +2012,10 @@ static int mtk_add_mac(struct mtk_eth *eth, struct d= evice_node *np) mac->hw_stats =3D devm_kzalloc(eth->dev, sizeof(*mac->hw_stats), GFP_KERNEL); - if (!mac->hw_stats) - return -ENOMEM; + if (!mac->hw_stats) { + err =3D -ENOMEM; + goto free_netdev; + } spin_lock_init(&mac->hw_stats->stats_lock); mac->hw_stats->reg_offset =3D id * MTK_STAT_OFFSET; } @@ -2037,7 +2039,8 @@ static int mtk_add_mac(struct mtk_eth *eth, struct de= vice_node *np) err =3D register_netdev(eth->netdev[id]); if (err) { dev_err(eth->dev, "error bringing up device\n"); - return err; + err =3D -ENOMEM; + goto free_netdev; } eth->netdev[id]->irq =3D eth->irq; netif_info(eth, probe, eth->netdev[id], @@ -2045,6 +2048,10 @@ static int mtk_add_mac(struct mtk_eth *eth, struct d= evice_node *np) eth->netdev[id]->base_addr, eth->netdev[id]->irq); =20 return 0; + +free_netdev: + free_netdev(eth->netdev[id]); + return err; } =20 static int mtk_probe(struct platform_device *pdev) --=20 2.17.1