diff mbox series

[net] net: gemini: Fix missing free_netdev() in error path of gemini_ethernet_port_probe()

Message ID 20200818134404.63828-1-wanghai38@huawei.com (mailing list archive)
State New, archived
Headers show
Series [net] net: gemini: Fix missing free_netdev() in error path of gemini_ethernet_port_probe() | expand

Commit Message

Wang Hai Aug. 18, 2020, 1:44 p.m. UTC
Fix the missing free_netdev() before return from
gemini_ethernet_port_probe() in the error handling case.

Fixes: 4d5ae32f5e1e ("net: ethernet: Add a driver for Gemini gigabit ethernet")
Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Wang Hai <wanghai38@huawei.com>
---
 drivers/net/ethernet/cortina/gemini.c | 35 ++++++++++++++++++---------
 1 file changed, 23 insertions(+), 12 deletions(-)

Comments

David Miller Aug. 18, 2020, 7:54 p.m. UTC | #1
From: Wang Hai <wanghai38@huawei.com>
Date: Tue, 18 Aug 2020 21:44:04 +0800

> Fix the missing free_netdev() before return from
> gemini_ethernet_port_probe() in the error handling case.
> 
> Fixes: 4d5ae32f5e1e ("net: ethernet: Add a driver for Gemini gigabit ethernet")
> Reported-by: Hulk Robot <hulkci@huawei.com>
> Signed-off-by: Wang Hai <wanghai38@huawei.com>

You can just convert this function to use 'devm_alloc_etherdev_mqs', which
is a one line fix.
Wang Hai Aug. 19, 2020, 2:41 a.m. UTC | #2
在 2020/8/19 3:54, David Miller 写道:
> From: Wang Hai <wanghai38@huawei.com>
> Date: Tue, 18 Aug 2020 21:44:04 +0800
>
>> Fix the missing free_netdev() before return from
>> gemini_ethernet_port_probe() in the error handling case.
>>
>> Fixes: 4d5ae32f5e1e ("net: ethernet: Add a driver for Gemini gigabit ethernet")
>> Reported-by: Hulk Robot <hulkci@huawei.com>
>> Signed-off-by: Wang Hai <wanghai38@huawei.com>
> You can just convert this function to use 'devm_alloc_etherdev_mqs', which
> is a one line fix.
>
> .
Thanks for your advice, I just sent a v2 patch.
"[PATCH net v2] net: gemini: Fix missing free_netdev() in error path of 
gemini_ethernet_port_probe()"
diff mbox series

Patch

diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c
index 66e67b24a887..d8de50fde27d 100644
--- a/drivers/net/ethernet/cortina/gemini.c
+++ b/drivers/net/ethernet/cortina/gemini.c
@@ -2407,37 +2407,46 @@  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");
-		return -ENODEV;
+		ret = -ENODEV;
+		goto err_out_free;
 	}
 	port->dma_base = devm_ioremap_resource(dev, dmares);
-	if (IS_ERR(port->dma_base))
-		return PTR_ERR(port->dma_base);
+	if (IS_ERR(port->dma_base)) {
+		ret = PTR_ERR(port->dma_base);
+		goto err_out_free;
+	}
 
 	/* GMAC config memory */
 	gmacres = platform_get_resource(pdev, IORESOURCE_MEM, 1);
 	if (!gmacres) {
 		dev_err(dev, "no GMAC resource\n");
-		return -ENODEV;
+		ret = -ENODEV;
+		goto err_out_free;
 	}
 	port->gmac_base = devm_ioremap_resource(dev, gmacres);
-	if (IS_ERR(port->gmac_base))
-		return PTR_ERR(port->gmac_base);
+	if (IS_ERR(port->gmac_base)) {
+		ret = PTR_ERR(port->gmac_base);
+		goto err_out_free;
+	}
 
 	/* Interrupt */
 	irq = platform_get_irq(pdev, 0);
-	if (irq <= 0)
-		return irq ? irq : -ENODEV;
+	if (irq <= 0) {
+		ret = irq ? irq : -ENODEV;
+		goto err_out_free;
+	}
 	port->irq = irq;
 
 	/* Clock the port */
 	port->pclk = devm_clk_get(dev, "PCLK");
 	if (IS_ERR(port->pclk)) {
 		dev_err(dev, "no PCLK\n");
-		return PTR_ERR(port->pclk);
+		ret = PTR_ERR(port->pclk);
+		goto err_out_free;
 	}
 	ret = clk_prepare_enable(port->pclk);
 	if (ret)
-		return ret;
+		goto err_out_free;
 
 	/* Maybe there is a nice ethernet address we should use */
 	gemini_port_save_mac_addr(port);
@@ -2447,7 +2456,8 @@  static int gemini_ethernet_port_probe(struct platform_device *pdev)
 	if (IS_ERR(port->reset)) {
 		dev_err(dev, "no reset\n");
 		clk_disable_unprepare(port->pclk);
-		return PTR_ERR(port->reset);
+		ret = PTR_ERR(port->reset);
+		goto err_out_free;
 	}
 	reset_control_reset(port->reset);
 	usleep_range(100, 500);
@@ -2504,7 +2514,7 @@  static int gemini_ethernet_port_probe(struct platform_device *pdev)
 					port);
 	if (ret) {
 		clk_disable_unprepare(port->pclk);
-		return ret;
+		goto err_out_free;
 	}
 
 	ret = register_netdev(netdev);
@@ -2520,6 +2530,7 @@  static int gemini_ethernet_port_probe(struct platform_device *pdev)
 		return 0;
 	}
 
+err_out_free:
 	port->netdev = NULL;
 	free_netdev(netdev);
 	return ret;