@@ -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;
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(-)