net: smc91x: Fix possible memory leak in smc_drv_probe()
authorWang Hai <wanghai38@huawei.com>
Thu, 16 Jul 2020 03:50:38 +0000 (11:50 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 29 Jul 2020 05:42:54 +0000 (07:42 +0200)
[ Upstream commit bca9749b1aa23d964d3ab930938af66dbf887f15 ]

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")
Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Wang Hai <wanghai38@huawei.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/net/ethernet/smsc/smc91x.c

index 96ac0d3af6f5b0eb15c8636021bce42e5da80a13..f570a37c68c23eb884ad8327daba943076220a6b 100644 (file)
@@ -2294,7 +2294,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
@@ -2303,7 +2303,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