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

[netdrvr oaknet] use alloc_etherdev, fix leaks

parent c3019156
......@@ -94,8 +94,8 @@ static int __init oaknet_init(void)
{
register int i;
int reg0, regd;
int ret;
struct net_device tmp, *dev = NULL;
int ret = -ENOMEM;
struct net_device *dev;
#if 0
unsigned long ioaddr = OAKNET_IO_BASE;
#else
......@@ -105,17 +105,15 @@ static int __init oaknet_init(void)
if (!ioaddr)
return -ENOMEM;
/*
* This MUST happen here because of the nic_* macros
* which have an implicit dependency on dev->base_addr.
*/
tmp.base_addr = ioaddr;
dev = &tmp;
dev = alloc_etherdev(0);
if (!dev)
goto out_unmap;
dev->priv = NULL;
ret = -EBUSY;
if (!request_region(OAKNET_IO_BASE, OAKNET_IO_SIZE, name))
goto out_unmap;
goto out_dev;
/* Quick register check to see if the device is really there. */
......@@ -144,17 +142,7 @@ static int __init oaknet_init(void)
goto out_region;
}
/*
* We're not using the old-style probing API, so we have to allocate
* our own device structure.
*/
dev = init_etherdev(NULL, 0);
ret = -ENOMEM;
if (!dev)
goto out_region;
SET_MODULE_OWNER(dev);
oaknet_devs = dev;
/*
* This controller is on an embedded board, so the base address
......@@ -169,7 +157,7 @@ static int __init oaknet_init(void)
ret = -ENOMEM;
if (ethdev_init(dev)) {
printk(" unable to get memory for dev->priv.\n");
goto out_dev;
goto out_region;
}
/*
......@@ -215,15 +203,21 @@ static int __init oaknet_init(void)
dev->stop = oaknet_close;
NS8390_init(dev, FALSE);
ret = register_netdev(dev);
if (ret)
goto out_irq;
oaknet_devs = dev;
return 0;
return (0);
out_irq;
free_irq(dev->irq, dev);
out_priv:
kfree(dev->priv);
out_dev:
unregister_netdev(dev);
kfree(dev);
out_region:
release_region(OAKNET_IO_BASE, OAKNET_IO_SIZE);
out_dev:
free_netdev(dev);
out_unmap:
iounmap(ioaddr);
return ret;
......@@ -661,17 +655,6 @@ oaknet_dma_error(struct net_device *dev, const char *name)
dev->interrupt);
}
/*
* Oak Ethernet module load interface.
*/
static int __init oaknet_init_module (void)
{
if (oaknet_devs != NULL)
return (-EBUSY);
return (oaknet_init());
}
/*
* Oak Ethernet module unload interface.
*/
......@@ -683,17 +666,17 @@ static void __exit oaknet_cleanup_module (void)
if (oaknet_devs->priv != NULL) {
int ioaddr = oaknet_devs->base_addr;
void *priv = oaknet_devs->priv;
unregister_netdev(oaknet_dev);
free_irq(oaknet_devs->irq, oaknet_devs);
kfree(priv);
release_region(ioaddr, OAKNET_IO_SIZE);
iounmap(ioaddr);
unregister_netdev(oaknet_dev);
free_netdev(priv);
}
/* Convert to loop once driver supports multiple devices. */
kfree(oaknet_devs);
free_netdev(oaknet_devs);
}
module_init(oaknet_init_module);
module_init(oaknet_init);
module_exit(oaknet_cleanup_module);
MODULE_LICENSE("GPL");
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