Commit ed947ded authored by Alexander Viro's avatar Alexander Viro Committed by Stephen Hemminger

[netdrvr gt96100eth] use alloc_etherdev, fix leaks

parent 530036d3
...@@ -729,10 +729,12 @@ gt96100_probe1(int port_num) ...@@ -729,10 +729,12 @@ gt96100_probe1(int port_num)
return -EBUSY; return -EBUSY;
} }
dev = init_etherdev(0, sizeof(struct gt96100_private)); dev = alloc_etherdev(sizeof(struct gt96100_private));
if (!dev)
goto out;
gtif->dev = dev; gtif->dev = dev;
/* private struct aligned and zeroed by init_etherdev */ /* private struct aligned and zeroed by alloc_etherdev */
/* Fill in the 'dev' fields. */ /* Fill in the 'dev' fields. */
dev->base_addr = gtif->iobase; dev->base_addr = gtif->iobase;
dev->irq = gtif->irq; dev->irq = gtif->irq;
...@@ -740,7 +742,7 @@ gt96100_probe1(int port_num) ...@@ -740,7 +742,7 @@ gt96100_probe1(int port_num)
if ((retval = parse_mac_addr(dev, gtif->mac_str))) { if ((retval = parse_mac_addr(dev, gtif->mac_str))) {
err("%s: MAC address parse failed\n", __FUNCTION__); err("%s: MAC address parse failed\n", __FUNCTION__);
retval = -EINVAL; retval = -EINVAL;
goto free_region; goto out1;
} }
gp = dev->priv; gp = dev->priv;
...@@ -768,7 +770,7 @@ gt96100_probe1(int port_num) ...@@ -768,7 +770,7 @@ gt96100_probe1(int port_num)
&gp->rx_ring_dma); &gp->rx_ring_dma);
if (gp->rx_ring == NULL) { if (gp->rx_ring == NULL) {
retval = -ENOMEM; retval = -ENOMEM;
goto free_region; goto out1;
} }
gp->tx_ring = (gt96100_td_t *)(gp->rx_ring + RX_RING_SIZE); gp->tx_ring = (gt96100_td_t *)(gp->rx_ring + RX_RING_SIZE);
...@@ -781,11 +783,8 @@ gt96100_probe1(int port_num) ...@@ -781,11 +783,8 @@ gt96100_probe1(int port_num)
gp->rx_buff = dmaalloc(PKT_BUF_SZ*RX_RING_SIZE, gp->rx_buff = dmaalloc(PKT_BUF_SZ*RX_RING_SIZE,
&gp->rx_buff_dma); &gp->rx_buff_dma);
if (gp->rx_buff == NULL) { if (gp->rx_buff == NULL) {
dmafree(sizeof(gt96100_rd_t) * RX_RING_SIZE
+ sizeof(gt96100_td_t) * TX_RING_SIZE,
gp->rx_ring);
retval = -ENOMEM; retval = -ENOMEM;
goto free_region; goto out2;
} }
} }
...@@ -797,12 +796,8 @@ gt96100_probe1(int port_num) ...@@ -797,12 +796,8 @@ gt96100_probe1(int port_num)
gp->hash_table = (char*)dmaalloc(RX_HASH_TABLE_SIZE, gp->hash_table = (char*)dmaalloc(RX_HASH_TABLE_SIZE,
&gp->hash_table_dma); &gp->hash_table_dma);
if (gp->hash_table == NULL) { if (gp->hash_table == NULL) {
dmafree(sizeof(gt96100_rd_t) * RX_RING_SIZE
+ sizeof(gt96100_td_t) * TX_RING_SIZE,
gp->rx_ring);
dmafree(PKT_BUF_SZ*RX_RING_SIZE, gp->rx_buff);
retval = -ENOMEM; retval = -ENOMEM;
goto free_region; goto out3;
} }
} }
...@@ -819,14 +814,23 @@ gt96100_probe1(int port_num) ...@@ -819,14 +814,23 @@ gt96100_probe1(int port_num)
dev->tx_timeout = gt96100_tx_timeout; dev->tx_timeout = gt96100_tx_timeout;
dev->watchdog_timeo = GT96100ETH_TX_TIMEOUT; dev->watchdog_timeo = GT96100ETH_TX_TIMEOUT;
/* Fill in the fields of the device structure with ethernet values. */ retval = register_netdev(dev);
ether_setup(dev); if (retval)
goto out4;
return 0; return 0;
free_region: out4:
release_region(gtif->iobase, GT96100_ETH_IO_SIZE); dmafree(RX_HASH_TABLE_SIZE, gp->hash_table_dma);
unregister_netdev(dev); out3:
dmafree(PKT_BUF_SZ*RX_RING_SIZE, gp->rx_buff);
out2:
dmafree(sizeof(gt96100_rd_t) * RX_RING_SIZE
+ sizeof(gt96100_td_t) * TX_RING_SIZE,
gp->rx_ring);
out1:
free_netdev (dev); free_netdev (dev);
out:
release_region(gtif->iobase, GT96100_ETH_IO_SIZE);
err("%s failed. Returns %d\n", __FUNCTION__, retval); err("%s failed. Returns %d\n", __FUNCTION__, retval);
return retval; return retval;
} }
...@@ -1573,9 +1577,14 @@ static void gt96100_cleanup_module(void) ...@@ -1573,9 +1577,14 @@ static void gt96100_cleanup_module(void)
if (gtif->dev != NULL) { if (gtif->dev != NULL) {
struct gt96100_private *gp = struct gt96100_private *gp =
(struct gt96100_private *)gtif->dev->priv; (struct gt96100_private *)gtif->dev->priv;
release_region(gtif->iobase, gp->io_size);
unregister_netdev(gtif->dev); unregister_netdev(gtif->dev);
free_netdev (gtif->dev); dmafree(RX_HASH_TABLE_SIZE, gp->hash_table_dma);
dmafree(PKT_BUF_SZ*RX_RING_SIZE, gp->rx_buff);
dmafree(sizeof(gt96100_rd_t) * RX_RING_SIZE
+ sizeof(gt96100_td_t) * TX_RING_SIZE,
gp->rx_ring);
free_netdev(gtif->dev);
release_region(gtif->iobase, gp->io_size);
} }
} }
} }
......
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