forked from Minki/linux
pxa168_eth: fix error handling in prope
A couple issues here: * Some resources weren't released. * If alloc_etherdev() failed it would have caused a NULL dereference because "pep" would be null when we checked "if (pep->clk)". * Also it's better to propagate the error codes from mdiobus_register() instead of just returning -ENOMEM. Signed-off-by: Dan Carpenter <error27@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
4169591fd7
commit
945c7c73e2
@ -1497,7 +1497,7 @@ static int pxa168_eth_probe(struct platform_device *pdev)
|
|||||||
dev = alloc_etherdev(sizeof(struct pxa168_eth_private));
|
dev = alloc_etherdev(sizeof(struct pxa168_eth_private));
|
||||||
if (!dev) {
|
if (!dev) {
|
||||||
err = -ENOMEM;
|
err = -ENOMEM;
|
||||||
goto out;
|
goto err_clk;
|
||||||
}
|
}
|
||||||
|
|
||||||
platform_set_drvdata(pdev, dev);
|
platform_set_drvdata(pdev, dev);
|
||||||
@ -1507,12 +1507,12 @@ static int pxa168_eth_probe(struct platform_device *pdev)
|
|||||||
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
||||||
if (res == NULL) {
|
if (res == NULL) {
|
||||||
err = -ENODEV;
|
err = -ENODEV;
|
||||||
goto out;
|
goto err_netdev;
|
||||||
}
|
}
|
||||||
pep->base = ioremap(res->start, res->end - res->start + 1);
|
pep->base = ioremap(res->start, res->end - res->start + 1);
|
||||||
if (pep->base == NULL) {
|
if (pep->base == NULL) {
|
||||||
err = -ENOMEM;
|
err = -ENOMEM;
|
||||||
goto out;
|
goto err_netdev;
|
||||||
}
|
}
|
||||||
res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
|
res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
|
||||||
BUG_ON(!res);
|
BUG_ON(!res);
|
||||||
@ -1549,7 +1549,7 @@ static int pxa168_eth_probe(struct platform_device *pdev)
|
|||||||
pep->smi_bus = mdiobus_alloc();
|
pep->smi_bus = mdiobus_alloc();
|
||||||
if (pep->smi_bus == NULL) {
|
if (pep->smi_bus == NULL) {
|
||||||
err = -ENOMEM;
|
err = -ENOMEM;
|
||||||
goto out;
|
goto err_base;
|
||||||
}
|
}
|
||||||
pep->smi_bus->priv = pep;
|
pep->smi_bus->priv = pep;
|
||||||
pep->smi_bus->name = "pxa168_eth smi";
|
pep->smi_bus->name = "pxa168_eth smi";
|
||||||
@ -1558,31 +1558,31 @@ static int pxa168_eth_probe(struct platform_device *pdev)
|
|||||||
snprintf(pep->smi_bus->id, MII_BUS_ID_SIZE, "%d", pdev->id);
|
snprintf(pep->smi_bus->id, MII_BUS_ID_SIZE, "%d", pdev->id);
|
||||||
pep->smi_bus->parent = &pdev->dev;
|
pep->smi_bus->parent = &pdev->dev;
|
||||||
pep->smi_bus->phy_mask = 0xffffffff;
|
pep->smi_bus->phy_mask = 0xffffffff;
|
||||||
if (mdiobus_register(pep->smi_bus) < 0) {
|
err = mdiobus_register(pep->smi_bus);
|
||||||
err = -ENOMEM;
|
if (err)
|
||||||
goto out;
|
goto err_free_mdio;
|
||||||
}
|
|
||||||
pxa168_init_hw(pep);
|
pxa168_init_hw(pep);
|
||||||
err = ethernet_phy_setup(dev);
|
err = ethernet_phy_setup(dev);
|
||||||
if (err)
|
if (err)
|
||||||
goto out;
|
goto err_mdiobus;
|
||||||
SET_NETDEV_DEV(dev, &pdev->dev);
|
SET_NETDEV_DEV(dev, &pdev->dev);
|
||||||
err = register_netdev(dev);
|
err = register_netdev(dev);
|
||||||
if (err)
|
if (err)
|
||||||
goto out;
|
goto err_mdiobus;
|
||||||
return 0;
|
return 0;
|
||||||
out:
|
|
||||||
if (pep->clk) {
|
err_mdiobus:
|
||||||
clk_disable(pep->clk);
|
mdiobus_unregister(pep->smi_bus);
|
||||||
clk_put(pep->clk);
|
err_free_mdio:
|
||||||
pep->clk = NULL;
|
mdiobus_free(pep->smi_bus);
|
||||||
}
|
err_base:
|
||||||
if (pep->base) {
|
iounmap(pep->base);
|
||||||
iounmap(pep->base);
|
err_netdev:
|
||||||
pep->base = NULL;
|
free_netdev(dev);
|
||||||
}
|
err_clk:
|
||||||
if (dev)
|
clk_disable(clk);
|
||||||
free_netdev(dev);
|
clk_put(clk);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user