Commit d5e07e69 authored by Sergei Shtylyov's avatar Sergei Shtylyov Committed by David S. Miller

sh_eth: use managed device API

Switch the driver to the managed device API by replacing ioremap() calls with
devm_ioremap_resource() (that will also result in calling request_mem_region()
which the driver forgot to do until now) and k[mz]alloc() with devm_kzalloc() --
this permits to simplify driver's probe()/remove() method cleanup. We can now
remove the ioremap() error messages since the error messages are printed by
 devm_ioremap_resource() itself. We can also remove the 'bitbang' field from
'struct sh_eth_private' as we don't need it anymore in order to free the memory
behind it...
Signed-off-by: default avatarSergei Shtylyov <sergei.shtylyov@cogentembedded.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 564044b0
...@@ -2215,7 +2215,6 @@ static void sh_eth_tsu_init(struct sh_eth_private *mdp) ...@@ -2215,7 +2215,6 @@ static void sh_eth_tsu_init(struct sh_eth_private *mdp)
/* MDIO bus release function */ /* MDIO bus release function */
static int sh_mdio_release(struct net_device *ndev) static int sh_mdio_release(struct net_device *ndev)
{ {
struct sh_eth_private *mdp = netdev_priv(ndev);
struct mii_bus *bus = dev_get_drvdata(&ndev->dev); struct mii_bus *bus = dev_get_drvdata(&ndev->dev);
/* unregister mdio bus */ /* unregister mdio bus */
...@@ -2224,15 +2223,9 @@ static int sh_mdio_release(struct net_device *ndev) ...@@ -2224,15 +2223,9 @@ static int sh_mdio_release(struct net_device *ndev)
/* remove mdio bus info from net_device */ /* remove mdio bus info from net_device */
dev_set_drvdata(&ndev->dev, NULL); dev_set_drvdata(&ndev->dev, NULL);
/* free interrupts memory */
kfree(bus->irq);
/* free bitbang info */ /* free bitbang info */
free_mdio_bitbang(bus); free_mdio_bitbang(bus);
/* free bitbang memory */
kfree(mdp->bitbang);
return 0; return 0;
} }
...@@ -2245,7 +2238,8 @@ static int sh_mdio_init(struct net_device *ndev, int id, ...@@ -2245,7 +2238,8 @@ static int sh_mdio_init(struct net_device *ndev, int id,
struct sh_eth_private *mdp = netdev_priv(ndev); struct sh_eth_private *mdp = netdev_priv(ndev);
/* create bit control struct for PHY */ /* create bit control struct for PHY */
bitbang = kzalloc(sizeof(struct bb_info), GFP_KERNEL); bitbang = devm_kzalloc(&ndev->dev, sizeof(struct bb_info),
GFP_KERNEL);
if (!bitbang) { if (!bitbang) {
ret = -ENOMEM; ret = -ENOMEM;
goto out; goto out;
...@@ -2261,11 +2255,10 @@ static int sh_mdio_init(struct net_device *ndev, int id, ...@@ -2261,11 +2255,10 @@ static int sh_mdio_init(struct net_device *ndev, int id,
bitbang->ctrl.ops = &bb_ops; bitbang->ctrl.ops = &bb_ops;
/* MII controller setting */ /* MII controller setting */
mdp->bitbang = bitbang;
mdp->mii_bus = alloc_mdio_bitbang(&bitbang->ctrl); mdp->mii_bus = alloc_mdio_bitbang(&bitbang->ctrl);
if (!mdp->mii_bus) { if (!mdp->mii_bus) {
ret = -ENOMEM; ret = -ENOMEM;
goto out_free_bitbang; goto out;
} }
/* Hook up MII support for ethtool */ /* Hook up MII support for ethtool */
...@@ -2275,7 +2268,9 @@ static int sh_mdio_init(struct net_device *ndev, int id, ...@@ -2275,7 +2268,9 @@ static int sh_mdio_init(struct net_device *ndev, int id,
mdp->pdev->name, id); mdp->pdev->name, id);
/* PHY IRQ */ /* PHY IRQ */
mdp->mii_bus->irq = kmalloc(sizeof(int)*PHY_MAX_ADDR, GFP_KERNEL); mdp->mii_bus->irq = devm_kzalloc(&ndev->dev,
sizeof(int) * PHY_MAX_ADDR,
GFP_KERNEL);
if (!mdp->mii_bus->irq) { if (!mdp->mii_bus->irq) {
ret = -ENOMEM; ret = -ENOMEM;
goto out_free_bus; goto out_free_bus;
...@@ -2287,21 +2282,15 @@ static int sh_mdio_init(struct net_device *ndev, int id, ...@@ -2287,21 +2282,15 @@ static int sh_mdio_init(struct net_device *ndev, int id,
/* register mdio bus */ /* register mdio bus */
ret = mdiobus_register(mdp->mii_bus); ret = mdiobus_register(mdp->mii_bus);
if (ret) if (ret)
goto out_free_irq; goto out_free_bus;
dev_set_drvdata(&ndev->dev, mdp->mii_bus); dev_set_drvdata(&ndev->dev, mdp->mii_bus);
return 0; return 0;
out_free_irq:
kfree(mdp->mii_bus->irq);
out_free_bus: out_free_bus:
free_mdio_bitbang(mdp->mii_bus); free_mdio_bitbang(mdp->mii_bus);
out_free_bitbang:
kfree(bitbang);
out: out:
return ret; return ret;
} }
...@@ -2389,10 +2378,9 @@ static int sh_eth_drv_probe(struct platform_device *pdev) ...@@ -2389,10 +2378,9 @@ static int sh_eth_drv_probe(struct platform_device *pdev)
mdp = netdev_priv(ndev); mdp = netdev_priv(ndev);
mdp->num_tx_ring = TX_RING_SIZE; mdp->num_tx_ring = TX_RING_SIZE;
mdp->num_rx_ring = RX_RING_SIZE; mdp->num_rx_ring = RX_RING_SIZE;
mdp->addr = ioremap(res->start, resource_size(res)); mdp->addr = devm_ioremap_resource(&pdev->dev, res);
if (mdp->addr == NULL) { if (IS_ERR(mdp->addr)) {
ret = -ENOMEM; ret = PTR_ERR(mdp->addr);
dev_err(&pdev->dev, "ioremap failed.\n");
goto out_release; goto out_release;
} }
...@@ -2438,11 +2426,9 @@ static int sh_eth_drv_probe(struct platform_device *pdev) ...@@ -2438,11 +2426,9 @@ static int sh_eth_drv_probe(struct platform_device *pdev)
ret = -ENODEV; ret = -ENODEV;
goto out_release; goto out_release;
} }
mdp->tsu_addr = ioremap(rtsu->start, mdp->tsu_addr = devm_ioremap_resource(&pdev->dev, rtsu);
resource_size(rtsu)); if (IS_ERR(mdp->tsu_addr)) {
if (mdp->tsu_addr == NULL) { ret = PTR_ERR(mdp->tsu_addr);
ret = -ENOMEM;
dev_err(&pdev->dev, "TSU ioremap failed.\n");
goto out_release; goto out_release;
} }
mdp->port = devno % 2; mdp->port = devno % 2;
...@@ -2483,10 +2469,6 @@ static int sh_eth_drv_probe(struct platform_device *pdev) ...@@ -2483,10 +2469,6 @@ static int sh_eth_drv_probe(struct platform_device *pdev)
out_release: out_release:
/* net_dev free */ /* net_dev free */
if (mdp && mdp->addr)
iounmap(mdp->addr);
if (mdp && mdp->tsu_addr)
iounmap(mdp->tsu_addr);
if (ndev) if (ndev)
free_netdev(ndev); free_netdev(ndev);
...@@ -2499,12 +2481,9 @@ static int sh_eth_drv_remove(struct platform_device *pdev) ...@@ -2499,12 +2481,9 @@ static int sh_eth_drv_remove(struct platform_device *pdev)
struct net_device *ndev = platform_get_drvdata(pdev); struct net_device *ndev = platform_get_drvdata(pdev);
struct sh_eth_private *mdp = netdev_priv(ndev); struct sh_eth_private *mdp = netdev_priv(ndev);
if (mdp->cd->tsu)
iounmap(mdp->tsu_addr);
sh_mdio_release(ndev); sh_mdio_release(ndev);
unregister_netdev(ndev); unregister_netdev(ndev);
pm_runtime_disable(&pdev->dev); pm_runtime_disable(&pdev->dev);
iounmap(mdp->addr);
free_netdev(ndev); free_netdev(ndev);
platform_set_drvdata(pdev, NULL); platform_set_drvdata(pdev, NULL);
......
...@@ -705,7 +705,6 @@ struct sh_eth_private { ...@@ -705,7 +705,6 @@ struct sh_eth_private {
const u16 *reg_offset; const u16 *reg_offset;
void __iomem *addr; void __iomem *addr;
void __iomem *tsu_addr; void __iomem *tsu_addr;
struct bb_info *bitbang;
u32 num_rx_ring; u32 num_rx_ring;
u32 num_tx_ring; u32 num_tx_ring;
dma_addr_t rx_desc_dma; dma_addr_t rx_desc_dma;
......
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