Skip to contentSkip to conversation

net: smc91x: Fix possible memory leak in smc_drv_probe()

PATCH Applied Wang Hai 3 participants 3 messages Jul 16, 2020 – Jul 17, 2020

Subsystems (3)
lore
Share & tools
lore

Wang Hai

author
#0 lore raw

PATCH 1/1 net: smc91x: Fix possible memory leak in smc_drv_probe()

If try_toggle_control_gpio() failed in smc_drv_probe(), free_netdev(ndev) should be called to free the ndev created earlier. Otherwise, a memleak will occur.

Fixes 7d2911c43815 ("net: smc91x: Fix gpios for device tree based booting")
---
 drivers/net/ethernet/smsc/smc91x.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/smsc/smc91x.c +2 -2
index 90410f9d3b1a..1c4fea9c3ec4 100644
@@ -2274,7 +2274,7 @@ static int smc_drv_probe(struct platform_device *pdev)
 		ret = try_toggle_control_gpio(&pdev->dev, &lp->power_gpio,
 					      "power", 0, 0, 100);
 		if (ret)
-			return ret;
+			goto out_free_netdev;
 
 		/*
 		 * Optional reset GPIO configured? Minimum 100 ns reset needed
@@ -2283,7 +2283,7 @@ static int smc_drv_probe(struct platform_device *pdev)
 		ret = try_toggle_control_gpio(&pdev->dev, &lp->reset_gpio,
 					      "reset", 0, 0, 100);
 		if (ret)
-			return ret;
+			goto out_free_netdev;
 
 		/*
 		 * Need to wait for optional EEPROM to load, max 750 us according
Signature · 1 line
2.17.1
#1 lore raw
Quoted 3 lines

If try_toggle_control_gpio() failed in smc_drv_probe(), free_netdev(ndev) should be called to free the ndev created earlier. Otherwise, a memleak will occur.

* Will it be nicer to use the term “memory leak” also in this change description?

* Would another imperative wording be preferred for the commit message?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?id=f8456690ba8eb18ea4714e68554e242a04f65cff#n151

Regards,
Markus

maintainer Applied
#2 lore raw
In reply to Wang Hai

From: Wang Hai <[email protected]>
Date: Thu, 16 Jul 2020 11:50:38 +0800

Quoted 7 lines

If try_toggle_control_gpio() failed in smc_drv_probe(), free_netdev(ndev) should be called to free the ndev created earlier. Otherwise, a memleak will occur.

Fixes 7d2911c43815 ("net: smc91x: Fix gpios for device tree based booting")

Applied, thank you.