Commit e394dc33 authored by Stephen Hemminger's avatar Stephen Hemminger

[PATCH] (18/42) ultra

Based on viro NE42-ultra
	* switched smc-ultra to dynamic allocation
	* smc-ultra: fixed order of freeing bugs
	* smc-ultra: fixed resource leaks on failure exits
	* smc-ultra: fixed clobbering on autoprobe
parent 131641c5
...@@ -42,7 +42,7 @@ ...@@ -42,7 +42,7 @@
extern int ne2_probe(struct net_device *dev); extern int ne2_probe(struct net_device *dev);
extern int hp100_probe(struct net_device *dev); extern int hp100_probe(struct net_device *dev);
extern int ultra_probe(struct net_device *dev); extern struct net_device *ultra_probe(int unit);
extern int ultra32_probe(struct net_device *dev); extern int ultra32_probe(struct net_device *dev);
extern struct net_device *wd_probe(int unit); extern struct net_device *wd_probe(int unit);
extern struct net_device *el2_probe(int unit); extern struct net_device *el2_probe(int unit);
...@@ -203,14 +203,14 @@ static struct devprobe isa_probes[] __initdata = { ...@@ -203,14 +203,14 @@ static struct devprobe isa_probes[] __initdata = {
#endif #endif
#ifdef CONFIG_3C515 #ifdef CONFIG_3C515
{tc515_probe, 0}, {tc515_probe, 0},
#endif
#ifdef CONFIG_ULTRA
{ultra_probe, 0},
#endif #endif
{NULL, 0}, {NULL, 0},
}; };
static struct devprobe2 isa_probes2[] __initdata = { static struct devprobe2 isa_probes2[] __initdata = {
#ifdef CONFIG_ULTRA
{ultra_probe, 0},
#endif
#ifdef CONFIG_WD80x3 #ifdef CONFIG_WD80x3
{wd_probe, 0}, {wd_probe, 0},
#endif #endif
......
...@@ -76,7 +76,6 @@ static const char version[] = ...@@ -76,7 +76,6 @@ static const char version[] =
static unsigned int ultra_portlist[] __initdata = static unsigned int ultra_portlist[] __initdata =
{0x200, 0x220, 0x240, 0x280, 0x300, 0x340, 0x380, 0}; {0x200, 0x220, 0x240, 0x280, 0x300, 0x340, 0x380, 0};
int ultra_probe(struct net_device *dev);
static int ultra_probe1(struct net_device *dev, int ioaddr); static int ultra_probe1(struct net_device *dev, int ioaddr);
#ifdef __ISAPNP__ #ifdef __ISAPNP__
...@@ -127,10 +126,11 @@ MODULE_DEVICE_TABLE(isapnp, ultra_device_ids); ...@@ -127,10 +126,11 @@ MODULE_DEVICE_TABLE(isapnp, ultra_device_ids);
following. following.
*/ */
int __init ultra_probe(struct net_device *dev) static int __init do_ultra_probe(struct net_device *dev)
{ {
int i; int i;
int base_addr = dev->base_addr; int base_addr = dev->base_addr;
int irq = dev->irq;
SET_MODULE_OWNER(dev); SET_MODULE_OWNER(dev);
...@@ -147,13 +147,54 @@ int __init ultra_probe(struct net_device *dev) ...@@ -147,13 +147,54 @@ int __init ultra_probe(struct net_device *dev)
printk(KERN_NOTICE "smc-ultra.c: No ISAPnP cards found, trying standard ones...\n"); printk(KERN_NOTICE "smc-ultra.c: No ISAPnP cards found, trying standard ones...\n");
#endif #endif
for (i = 0; ultra_portlist[i]; i++) for (i = 0; ultra_portlist[i]; i++) {
dev->irq = irq;
if (ultra_probe1(dev, ultra_portlist[i]) == 0) if (ultra_probe1(dev, ultra_portlist[i]) == 0)
return 0; return 0;
}
return -ENODEV; return -ENODEV;
} }
static void cleanup_card(struct net_device *dev)
{
/* NB: ultra_close_card() does free_irq */
#ifdef __ISAPNP__
struct pnp_dev *idev = (struct pnp_dev *)ei_status.priv;
if (idev)
pnp_device_detach(idev);
#endif
release_region(dev->base_addr - ULTRA_NIC_OFFSET, ULTRA_IO_EXTENT);
kfree(dev->priv);
}
struct net_device * __init ultra_probe(int unit)
{
struct net_device *dev = alloc_etherdev(0);
int err;
if (!dev)
return ERR_PTR(-ENOMEM);
sprintf(dev->name, "eth%d", unit);
netdev_boot_setup_check(dev);
dev->priv = NULL; /* until all 8390-based use alloc_etherdev() */
err = do_ultra_probe(dev);
if (err)
goto out;
err = register_netdev(dev);
if (err)
goto out1;
return dev;
out1:
cleanup_card(dev);
out:
free_netdev(dev);
return ERR_PTR(err);
}
static int __init ultra_probe1(struct net_device *dev, int ioaddr) static int __init ultra_probe1(struct net_device *dev, int ioaddr)
{ {
int i, retval; int i, retval;
...@@ -500,7 +541,7 @@ ultra_close_card(struct net_device *dev) ...@@ -500,7 +541,7 @@ ultra_close_card(struct net_device *dev)
#ifdef MODULE #ifdef MODULE
#define MAX_ULTRA_CARDS 4 /* Max number of Ultra cards per module */ #define MAX_ULTRA_CARDS 4 /* Max number of Ultra cards per module */
static struct net_device dev_ultra[MAX_ULTRA_CARDS]; static struct net_device *dev_ultra[MAX_ULTRA_CARDS];
static int io[MAX_ULTRA_CARDS]; static int io[MAX_ULTRA_CARDS];
static int irq[MAX_ULTRA_CARDS]; static int irq[MAX_ULTRA_CARDS];
...@@ -516,26 +557,34 @@ ISA device autoprobes on a running machine are not recommended. */ ...@@ -516,26 +557,34 @@ ISA device autoprobes on a running machine are not recommended. */
int int
init_module(void) init_module(void)
{ {
struct net_device *dev;
int this_dev, found = 0; int this_dev, found = 0;
for (this_dev = 0; this_dev < MAX_ULTRA_CARDS; this_dev++) { for (this_dev = 0; this_dev < MAX_ULTRA_CARDS; this_dev++) {
struct net_device *dev = &dev_ultra[this_dev];
dev->irq = irq[this_dev];
dev->base_addr = io[this_dev];
dev->init = ultra_probe;
if (io[this_dev] == 0) { if (io[this_dev] == 0) {
if (this_dev != 0) break; /* only autoprobe 1st one */ if (this_dev != 0) break; /* only autoprobe 1st one */
printk(KERN_NOTICE "smc-ultra.c: Presently autoprobing (not recommended) for a single card.\n"); printk(KERN_NOTICE "smc-ultra.c: Presently autoprobing (not recommended) for a single card.\n");
} }
if (register_netdev(dev) != 0) { dev = alloc_etherdev(0);
printk(KERN_WARNING "smc-ultra.c: No SMC Ultra card found (i/o = 0x%x).\n", io[this_dev]); if (!dev)
if (found != 0) return 0; /* Got at least one. */ break;
return -ENXIO; dev->priv = NULL;
dev->irq = irq[this_dev];
dev->base_addr = io[this_dev];
if (do_ultra_probe(dev) == 0) {
if (register_netdev(dev) == 0) {
dev_ultra[found++] = dev;
continue;
}
cleanup_card(dev);
} }
found++; free_netdev(dev);
printk(KERN_WARNING "smc-ultra.c: No SMC Ultra card found (i/o = 0x%x).\n", io[this_dev]);
break;
} }
if (found)
return 0; return 0;
return -ENXIO;
} }
void void
...@@ -544,20 +593,11 @@ cleanup_module(void) ...@@ -544,20 +593,11 @@ cleanup_module(void)
int this_dev; int this_dev;
for (this_dev = 0; this_dev < MAX_ULTRA_CARDS; this_dev++) { for (this_dev = 0; this_dev < MAX_ULTRA_CARDS; this_dev++) {
struct net_device *dev = &dev_ultra[this_dev]; struct net_device *dev = dev_ultra[this_dev];
if (dev->priv != NULL) { if (dev) {
/* NB: ultra_close_card() does free_irq */
int ioaddr = dev->base_addr - ULTRA_NIC_OFFSET;
#ifdef __ISAPNP__
struct pnp_dev *idev = (struct pnp_dev *)ei_status.priv;
if (idev)
pnp_device_detach(idev);
#endif
unregister_netdev(dev); unregister_netdev(dev);
release_region(ioaddr, ULTRA_IO_EXTENT); cleanup_card(dev);
kfree(dev->priv); free_netdev(dev);
} }
} }
} }
......
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