Commit a63625d2 authored by Esben Haabendal's avatar Esben Haabendal Committed by David S. Miller

net: ll_temac: Fix and simplify error handling by using devres functions

As a side effect, a few error cases are fixed.

If of_iomap() of sdma_regs failed, no error code was returned.  Fixed to
return -ENOMEM similar to of_iomap() fail of regs.

If sysfs_create_group() or register_netdev() failed, lp->phy_node was not
released.

Finally, the order in remove function is corrected to be reverse order
of what is done in probe, i.e. calling temac_mdio_teardown() last, so we
unregister the netdev that most likely is using the mdio_bus first.
Signed-off-by: default avatarEsben Haabendal <esben@geanix.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent ac97a359
...@@ -378,7 +378,7 @@ void temac_indirect_out32(struct temac_local *lp, int reg, u32 value); ...@@ -378,7 +378,7 @@ void temac_indirect_out32(struct temac_local *lp, int reg, u32 value);
/* xilinx_temac_mdio.c */ /* xilinx_temac_mdio.c */
int temac_mdio_setup(struct temac_local *lp, struct device_node *np); int temac_mdio_setup(struct temac_local *lp, struct platform_device *pdev);
void temac_mdio_teardown(struct temac_local *lp); void temac_mdio_teardown(struct temac_local *lp);
#endif /* XILINX_LL_TEMAC_H */ #endif /* XILINX_LL_TEMAC_H */
...@@ -225,7 +225,6 @@ static void temac_dma_bd_release(struct net_device *ndev) ...@@ -225,7 +225,6 @@ static void temac_dma_bd_release(struct net_device *ndev)
dma_free_coherent(ndev->dev.parent, dma_free_coherent(ndev->dev.parent,
sizeof(*lp->tx_bd_v) * TX_BD_NUM, sizeof(*lp->tx_bd_v) * TX_BD_NUM,
lp->tx_bd_v, lp->tx_bd_p); lp->tx_bd_v, lp->tx_bd_p);
kfree(lp->rx_skb);
} }
/** /**
...@@ -237,7 +236,8 @@ static int temac_dma_bd_init(struct net_device *ndev) ...@@ -237,7 +236,8 @@ static int temac_dma_bd_init(struct net_device *ndev)
struct sk_buff *skb; struct sk_buff *skb;
int i; int i;
lp->rx_skb = kcalloc(RX_BD_NUM, sizeof(*lp->rx_skb), GFP_KERNEL); lp->rx_skb = devm_kcalloc(&ndev->dev, RX_BD_NUM, sizeof(*lp->rx_skb),
GFP_KERNEL);
if (!lp->rx_skb) if (!lp->rx_skb)
goto out; goto out;
...@@ -987,7 +987,7 @@ static int temac_of_probe(struct platform_device *op) ...@@ -987,7 +987,7 @@ static int temac_of_probe(struct platform_device *op)
int rc = 0; int rc = 0;
/* Init network device structure */ /* Init network device structure */
ndev = alloc_etherdev(sizeof(*lp)); ndev = devm_alloc_etherdev(&pdev->dev, sizeof(*lp));
if (!ndev) if (!ndev)
return -ENOMEM; return -ENOMEM;
...@@ -1020,11 +1020,10 @@ static int temac_of_probe(struct platform_device *op) ...@@ -1020,11 +1020,10 @@ static int temac_of_probe(struct platform_device *op)
mutex_init(&lp->indirect_mutex); mutex_init(&lp->indirect_mutex);
/* map device registers */ /* map device registers */
lp->regs = of_iomap(op->dev.of_node, 0); lp->regs = devm_of_iomap(&op->dev, op->dev.of_node, 0, NULL);
if (!lp->regs) { if (!lp->regs) {
dev_err(&op->dev, "could not map temac regs.\n"); dev_err(&op->dev, "could not map temac regs.\n");
rc = -ENOMEM; return -ENOMEM;
goto nodev;
} }
/* Setup checksum offload, but default to off if not specified */ /* Setup checksum offload, but default to off if not specified */
...@@ -1043,15 +1042,14 @@ static int temac_of_probe(struct platform_device *op) ...@@ -1043,15 +1042,14 @@ static int temac_of_probe(struct platform_device *op)
np = of_parse_phandle(op->dev.of_node, "llink-connected", 0); np = of_parse_phandle(op->dev.of_node, "llink-connected", 0);
if (!np) { if (!np) {
dev_err(&op->dev, "could not find DMA node\n"); dev_err(&op->dev, "could not find DMA node\n");
rc = -ENODEV; return -ENODEV;
goto err_iounmap;
} }
/* Setup the DMA register accesses, could be DCR or memory mapped */ /* Setup the DMA register accesses, could be DCR or memory mapped */
if (temac_dcr_setup(lp, op, np)) { if (temac_dcr_setup(lp, op, np)) {
/* no DCR in the device tree, try non-DCR */ /* no DCR in the device tree, try non-DCR */
lp->sdma_regs = of_iomap(np, 0); lp->sdma_regs = devm_of_iomap(&op->dev, np, 0, NULL);
if (lp->sdma_regs) { if (lp->sdma_regs) {
lp->dma_in = temac_dma_in32; lp->dma_in = temac_dma_in32;
lp->dma_out = temac_dma_out32; lp->dma_out = temac_dma_out32;
...@@ -1059,7 +1057,7 @@ static int temac_of_probe(struct platform_device *op) ...@@ -1059,7 +1057,7 @@ static int temac_of_probe(struct platform_device *op)
} else { } else {
dev_err(&op->dev, "unable to map DMA registers\n"); dev_err(&op->dev, "unable to map DMA registers\n");
of_node_put(np); of_node_put(np);
goto err_iounmap; return -ENOMEM;
} }
} }
...@@ -1070,8 +1068,7 @@ static int temac_of_probe(struct platform_device *op) ...@@ -1070,8 +1068,7 @@ static int temac_of_probe(struct platform_device *op)
if (!lp->rx_irq || !lp->tx_irq) { if (!lp->rx_irq || !lp->tx_irq) {
dev_err(&op->dev, "could not determine irqs\n"); dev_err(&op->dev, "could not determine irqs\n");
rc = -ENOMEM; return -ENOMEM;
goto err_iounmap_2;
} }
...@@ -1079,12 +1076,11 @@ static int temac_of_probe(struct platform_device *op) ...@@ -1079,12 +1076,11 @@ static int temac_of_probe(struct platform_device *op)
addr = of_get_mac_address(op->dev.of_node); addr = of_get_mac_address(op->dev.of_node);
if (!addr) { if (!addr) {
dev_err(&op->dev, "could not find MAC address\n"); dev_err(&op->dev, "could not find MAC address\n");
rc = -ENODEV; return -ENODEV;
goto err_iounmap_2;
} }
temac_init_mac_address(ndev, addr); temac_init_mac_address(ndev, addr);
rc = temac_mdio_setup(lp, op->dev.of_node); rc = temac_mdio_setup(lp, pdev);
if (rc) if (rc)
dev_warn(&op->dev, "error registering MDIO bus\n"); dev_warn(&op->dev, "error registering MDIO bus\n");
...@@ -1096,7 +1092,7 @@ static int temac_of_probe(struct platform_device *op) ...@@ -1096,7 +1092,7 @@ static int temac_of_probe(struct platform_device *op)
rc = sysfs_create_group(&lp->dev->kobj, &temac_attr_group); rc = sysfs_create_group(&lp->dev->kobj, &temac_attr_group);
if (rc) { if (rc) {
dev_err(lp->dev, "Error creating sysfs files\n"); dev_err(lp->dev, "Error creating sysfs files\n");
goto err_iounmap_2; goto err_sysfs_create;
} }
rc = register_netdev(lp->ndev); rc = register_netdev(lp->ndev);
...@@ -1107,16 +1103,11 @@ static int temac_of_probe(struct platform_device *op) ...@@ -1107,16 +1103,11 @@ static int temac_of_probe(struct platform_device *op)
return 0; return 0;
err_register_ndev: err_register_ndev:
sysfs_remove_group(&lp->dev->kobj, &temac_attr_group); sysfs_remove_group(&lp->dev->kobj, &temac_attr_group);
err_iounmap_2: err_sysfs_create:
if (lp->sdma_regs) of_node_put(lp->phy_node);
iounmap(lp->sdma_regs); temac_mdio_teardown(lp);
err_iounmap:
iounmap(lp->regs);
nodev:
free_netdev(ndev);
ndev = NULL;
return rc; return rc;
} }
...@@ -1125,15 +1116,10 @@ static int temac_of_remove(struct platform_device *op) ...@@ -1125,15 +1116,10 @@ static int temac_of_remove(struct platform_device *op)
struct net_device *ndev = platform_get_drvdata(op); struct net_device *ndev = platform_get_drvdata(op);
struct temac_local *lp = netdev_priv(ndev); struct temac_local *lp = netdev_priv(ndev);
temac_mdio_teardown(lp);
unregister_netdev(ndev); unregister_netdev(ndev);
sysfs_remove_group(&lp->dev->kobj, &temac_attr_group); sysfs_remove_group(&lp->dev->kobj, &temac_attr_group);
of_node_put(lp->phy_node); of_node_put(lp->phy_node);
lp->phy_node = NULL; temac_mdio_teardown(lp);
iounmap(lp->regs);
if (lp->sdma_regs)
iounmap(lp->sdma_regs);
free_netdev(ndev);
return 0; return 0;
} }
......
...@@ -57,8 +57,9 @@ static int temac_mdio_write(struct mii_bus *bus, int phy_id, int reg, u16 val) ...@@ -57,8 +57,9 @@ static int temac_mdio_write(struct mii_bus *bus, int phy_id, int reg, u16 val)
return 0; return 0;
} }
int temac_mdio_setup(struct temac_local *lp, struct device_node *np) int temac_mdio_setup(struct temac_local *lp, struct platform_device *pdev)
{ {
struct device_node *np = dev_of_node(&pdev->dev);
struct mii_bus *bus; struct mii_bus *bus;
u32 bus_hz; u32 bus_hz;
int clk_div; int clk_div;
...@@ -81,7 +82,7 @@ int temac_mdio_setup(struct temac_local *lp, struct device_node *np) ...@@ -81,7 +82,7 @@ int temac_mdio_setup(struct temac_local *lp, struct device_node *np)
temac_indirect_out32(lp, XTE_MC_OFFSET, 1 << 6 | clk_div); temac_indirect_out32(lp, XTE_MC_OFFSET, 1 << 6 | clk_div);
mutex_unlock(&lp->indirect_mutex); mutex_unlock(&lp->indirect_mutex);
bus = mdiobus_alloc(); bus = devm_mdiobus_alloc(&pdev->dev);
if (!bus) if (!bus)
return -ENOMEM; return -ENOMEM;
...@@ -98,23 +99,16 @@ int temac_mdio_setup(struct temac_local *lp, struct device_node *np) ...@@ -98,23 +99,16 @@ int temac_mdio_setup(struct temac_local *lp, struct device_node *np)
rc = of_mdiobus_register(bus, np); rc = of_mdiobus_register(bus, np);
if (rc) if (rc)
goto err_register; return rc;
mutex_lock(&lp->indirect_mutex); mutex_lock(&lp->indirect_mutex);
dev_dbg(lp->dev, "MDIO bus registered; MC:%x\n", dev_dbg(lp->dev, "MDIO bus registered; MC:%x\n",
temac_indirect_in32(lp, XTE_MC_OFFSET)); temac_indirect_in32(lp, XTE_MC_OFFSET));
mutex_unlock(&lp->indirect_mutex); mutex_unlock(&lp->indirect_mutex);
return 0; return 0;
err_register:
mdiobus_free(bus);
return rc;
} }
void temac_mdio_teardown(struct temac_local *lp) void temac_mdio_teardown(struct temac_local *lp)
{ {
mdiobus_unregister(lp->mii_bus); mdiobus_unregister(lp->mii_bus);
mdiobus_free(lp->mii_bus);
lp->mii_bus = NULL;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment