[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20200729034606.89041-1-luwei32@huawei.com>
Date: Wed, 29 Jul 2020 11:46:06 +0800
From: Lu Wei <luwei32@...wei.com>
To: <ulli.kroll@...glemail.com>, <linus.walleij@...aro.org>,
<davem@...emloft.net>, <kuba@...nel.org>,
<mirq-linux@...e.qmqm.pl>, <linux-arm-kernel@...ts.infradead.org>,
<netdev@...r.kernel.org>, <linux-kernel@...r.kernel.org>
Subject: [PATCH] net: ethernet: fix potential memory leak in gemini_ethernet_port_probe()
If some processes in gemini_ethernet_port_probe() fail,
free_netdev(dev) needs to be called to avoid a memory leak.
Fixes: 4d5ae32f5e1e ("net: ethernet: Add a driver for Gemini gigabit ethernet")
Reported-by: Hulk Robot <hulkci@...wei.com>
Signed-off-by: Lu Wei <luwei32@...wei.com>
---
drivers/net/ethernet/cortina/gemini.c | 24 +++++++++++++++++++-----
1 file changed, 19 insertions(+), 5 deletions(-)
diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c
index 8d13ea370db1..5e93a1a570b6 100644
--- a/drivers/net/ethernet/cortina/gemini.c
+++ b/drivers/net/ethernet/cortina/gemini.c
@@ -2407,37 +2407,48 @@ static int gemini_ethernet_port_probe(struct platform_device *pdev)
dmares = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!dmares) {
dev_err(dev, "no DMA resource\n");
+ free_netdev(netdev);
return -ENODEV;
}
port->dma_base = devm_ioremap_resource(dev, dmares);
- if (IS_ERR(port->dma_base))
+ if (IS_ERR(port->dma_base)) {
+ free_netdev(netdev);
return PTR_ERR(port->dma_base);
+ }
/* GMAC config memory */
gmacres = platform_get_resource(pdev, IORESOURCE_MEM, 1);
if (!gmacres) {
dev_err(dev, "no GMAC resource\n");
+ free_netdev(netdev);
return -ENODEV;
}
port->gmac_base = devm_ioremap_resource(dev, gmacres);
- if (IS_ERR(port->gmac_base))
+ if (IS_ERR(port->gmac_base)) {
+ free_netdev(netdev);
return PTR_ERR(port->gmac_base);
+ }
/* Interrupt */
irq = platform_get_irq(pdev, 0);
- if (irq <= 0)
+ if (irq <= 0) {
+ free_netdev(netdev);
return irq ? irq : -ENODEV;
+ }
port->irq = irq;
/* Clock the port */
port->pclk = devm_clk_get(dev, "PCLK");
if (IS_ERR(port->pclk)) {
dev_err(dev, "no PCLK\n");
+ free_netdev(netdev);
return PTR_ERR(port->pclk);
}
ret = clk_prepare_enable(port->pclk);
- if (ret)
+ if (ret) {
+ free_netdev(netdev);
return ret;
+ }
/* Maybe there is a nice ethernet address we should use */
gemini_port_save_mac_addr(port);
@@ -2446,6 +2457,7 @@ static int gemini_ethernet_port_probe(struct platform_device *pdev)
port->reset = devm_reset_control_get_exclusive(dev, NULL);
if (IS_ERR(port->reset)) {
dev_err(dev, "no reset\n");
+ free_netdev(netdev);
return PTR_ERR(port->reset);
}
reset_control_reset(port->reset);
@@ -2501,8 +2513,10 @@ static int gemini_ethernet_port_probe(struct platform_device *pdev)
IRQF_SHARED,
port_names[port->id],
port);
- if (ret)
+ if (ret) {
+ free_netdev(netdev);
return ret;
+ }
ret = register_netdev(netdev);
if (!ret) {
--
2.17.1
Powered by blists - more mailing lists