net: korina: Use devres functions
Simplify probe/remove code by using devm_ functions. Reviewed-by: Andrew Lunn <andrew@lunn.ch> Signed-off-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
Родитель
89f9d5400b
Коммит
b4cd249a8c
|
@ -105,9 +105,9 @@ enum chain_status {
|
||||||
|
|
||||||
/* Information that need to be kept for each board. */
|
/* Information that need to be kept for each board. */
|
||||||
struct korina_private {
|
struct korina_private {
|
||||||
struct eth_regs *eth_regs;
|
struct eth_regs __iomem *eth_regs;
|
||||||
struct dma_reg *rx_dma_regs;
|
struct dma_reg __iomem *rx_dma_regs;
|
||||||
struct dma_reg *tx_dma_regs;
|
struct dma_reg __iomem *tx_dma_regs;
|
||||||
struct dma_desc *td_ring; /* transmit descriptor ring */
|
struct dma_desc *td_ring; /* transmit descriptor ring */
|
||||||
struct dma_desc *rd_ring; /* receive descriptor ring */
|
struct dma_desc *rd_ring; /* receive descriptor ring */
|
||||||
|
|
||||||
|
@ -1044,10 +1044,10 @@ static int korina_probe(struct platform_device *pdev)
|
||||||
struct korina_device *bif = platform_get_drvdata(pdev);
|
struct korina_device *bif = platform_get_drvdata(pdev);
|
||||||
struct korina_private *lp;
|
struct korina_private *lp;
|
||||||
struct net_device *dev;
|
struct net_device *dev;
|
||||||
struct resource *r;
|
void __iomem *p;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
dev = alloc_etherdev(sizeof(struct korina_private));
|
dev = devm_alloc_etherdev(&pdev->dev, sizeof(struct korina_private));
|
||||||
if (!dev)
|
if (!dev)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
|
@ -1060,36 +1060,30 @@ static int korina_probe(struct platform_device *pdev)
|
||||||
lp->rx_irq = platform_get_irq_byname(pdev, "korina_rx");
|
lp->rx_irq = platform_get_irq_byname(pdev, "korina_rx");
|
||||||
lp->tx_irq = platform_get_irq_byname(pdev, "korina_tx");
|
lp->tx_irq = platform_get_irq_byname(pdev, "korina_tx");
|
||||||
|
|
||||||
r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "korina_regs");
|
p = devm_platform_ioremap_resource_byname(pdev, "korina_regs");
|
||||||
dev->base_addr = r->start;
|
if (!p) {
|
||||||
lp->eth_regs = ioremap(r->start, resource_size(r));
|
|
||||||
if (!lp->eth_regs) {
|
|
||||||
printk(KERN_ERR DRV_NAME ": cannot remap registers\n");
|
printk(KERN_ERR DRV_NAME ": cannot remap registers\n");
|
||||||
rc = -ENXIO;
|
return -ENOMEM;
|
||||||
goto probe_err_out;
|
|
||||||
}
|
}
|
||||||
|
lp->eth_regs = p;
|
||||||
|
|
||||||
r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "korina_dma_rx");
|
p = devm_platform_ioremap_resource_byname(pdev, "korina_dma_rx");
|
||||||
lp->rx_dma_regs = ioremap(r->start, resource_size(r));
|
if (!p) {
|
||||||
if (!lp->rx_dma_regs) {
|
|
||||||
printk(KERN_ERR DRV_NAME ": cannot remap Rx DMA registers\n");
|
printk(KERN_ERR DRV_NAME ": cannot remap Rx DMA registers\n");
|
||||||
rc = -ENXIO;
|
return -ENOMEM;
|
||||||
goto probe_err_dma_rx;
|
|
||||||
}
|
}
|
||||||
|
lp->rx_dma_regs = p;
|
||||||
|
|
||||||
r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "korina_dma_tx");
|
p = devm_platform_ioremap_resource_byname(pdev, "korina_dma_tx");
|
||||||
lp->tx_dma_regs = ioremap(r->start, resource_size(r));
|
if (!p) {
|
||||||
if (!lp->tx_dma_regs) {
|
|
||||||
printk(KERN_ERR DRV_NAME ": cannot remap Tx DMA registers\n");
|
printk(KERN_ERR DRV_NAME ": cannot remap Tx DMA registers\n");
|
||||||
rc = -ENXIO;
|
return -ENOMEM;
|
||||||
goto probe_err_dma_tx;
|
|
||||||
}
|
}
|
||||||
|
lp->tx_dma_regs = p;
|
||||||
|
|
||||||
lp->td_ring = kmalloc(TD_RING_SIZE + RD_RING_SIZE, GFP_KERNEL);
|
lp->td_ring = kmalloc(TD_RING_SIZE + RD_RING_SIZE, GFP_KERNEL);
|
||||||
if (!lp->td_ring) {
|
if (!lp->td_ring)
|
||||||
rc = -ENXIO;
|
return -ENOMEM;
|
||||||
goto probe_err_td_ring;
|
|
||||||
}
|
|
||||||
|
|
||||||
dma_cache_inv((unsigned long)(lp->td_ring),
|
dma_cache_inv((unsigned long)(lp->td_ring),
|
||||||
TD_RING_SIZE + RD_RING_SIZE);
|
TD_RING_SIZE + RD_RING_SIZE);
|
||||||
|
@ -1119,7 +1113,8 @@ static int korina_probe(struct platform_device *pdev)
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
printk(KERN_ERR DRV_NAME
|
printk(KERN_ERR DRV_NAME
|
||||||
": cannot register net device: %d\n", rc);
|
": cannot register net device: %d\n", rc);
|
||||||
goto probe_err_register;
|
kfree((struct dma_desc *)KSEG0ADDR(lp->td_ring));
|
||||||
|
return rc;
|
||||||
}
|
}
|
||||||
timer_setup(&lp->media_check_timer, korina_poll_media, 0);
|
timer_setup(&lp->media_check_timer, korina_poll_media, 0);
|
||||||
|
|
||||||
|
@ -1127,20 +1122,7 @@ static int korina_probe(struct platform_device *pdev)
|
||||||
|
|
||||||
printk(KERN_INFO "%s: " DRV_NAME "-" DRV_VERSION " " DRV_RELDATE "\n",
|
printk(KERN_INFO "%s: " DRV_NAME "-" DRV_VERSION " " DRV_RELDATE "\n",
|
||||||
dev->name);
|
dev->name);
|
||||||
out:
|
|
||||||
return rc;
|
return rc;
|
||||||
|
|
||||||
probe_err_register:
|
|
||||||
kfree((struct dma_desc *)KSEG0ADDR(lp->td_ring));
|
|
||||||
probe_err_td_ring:
|
|
||||||
iounmap(lp->tx_dma_regs);
|
|
||||||
probe_err_dma_tx:
|
|
||||||
iounmap(lp->rx_dma_regs);
|
|
||||||
probe_err_dma_rx:
|
|
||||||
iounmap(lp->eth_regs);
|
|
||||||
probe_err_out:
|
|
||||||
free_netdev(dev);
|
|
||||||
goto out;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int korina_remove(struct platform_device *pdev)
|
static int korina_remove(struct platform_device *pdev)
|
||||||
|
@ -1148,13 +1130,9 @@ static int korina_remove(struct platform_device *pdev)
|
||||||
struct korina_device *bif = platform_get_drvdata(pdev);
|
struct korina_device *bif = platform_get_drvdata(pdev);
|
||||||
struct korina_private *lp = netdev_priv(bif->dev);
|
struct korina_private *lp = netdev_priv(bif->dev);
|
||||||
|
|
||||||
iounmap(lp->eth_regs);
|
|
||||||
iounmap(lp->rx_dma_regs);
|
|
||||||
iounmap(lp->tx_dma_regs);
|
|
||||||
kfree((struct dma_desc *)KSEG0ADDR(lp->td_ring));
|
kfree((struct dma_desc *)KSEG0ADDR(lp->td_ring));
|
||||||
|
|
||||||
unregister_netdev(bif->dev);
|
unregister_netdev(bif->dev);
|
||||||
free_netdev(bif->dev);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче