Commit 3c833f20 authored by Stephen Hemminger's avatar Stephen Hemminger

[PATCH] (27/42) ac3200

NE51-ac3200
	* switched ac3200 to dynamic allocation
	* ac3200: fixed order of freeing bugs
	* ac3200: fixed clobbering on autoprobe
	* ac3200: fixed resource leaks on failure exits
parent 71e6af69
...@@ -63,7 +63,7 @@ extern struct net_device *el16_probe(int unit); ...@@ -63,7 +63,7 @@ extern struct net_device *el16_probe(int unit);
extern struct net_device *elmc_probe(int unit); extern struct net_device *elmc_probe(int unit);
extern struct net_device *skmca_probe(int unit); extern struct net_device *skmca_probe(int unit);
extern struct net_device *elplus_probe(int unit); extern struct net_device *elplus_probe(int unit);
extern int ac3200_probe(struct net_device *); extern struct net_device *ac3200_probe(int unit);
extern struct net_device *es_probe(int unit); extern struct net_device *es_probe(int unit);
extern struct net_device *lne390_probe(int unit); extern struct net_device *lne390_probe(int unit);
extern struct net_device *e2100_probe(int unit); extern struct net_device *e2100_probe(int unit);
...@@ -163,14 +163,14 @@ static int __init probe_list2(int unit, struct devprobe2 *p, int autoprobe) ...@@ -163,14 +163,14 @@ static int __init probe_list2(int unit, struct devprobe2 *p, int autoprobe)
static struct devprobe eisa_probes[] __initdata = { static struct devprobe eisa_probes[] __initdata = {
#ifdef CONFIG_ULTRA32 #ifdef CONFIG_ULTRA32
{ultra32_probe, 0}, {ultra32_probe, 0},
#endif
#ifdef CONFIG_AC3200
{ac3200_probe, 0},
#endif #endif
{NULL, 0}, {NULL, 0},
}; };
static struct devprobe2 eisa_probes2[] __initdata = { static struct devprobe2 eisa_probes2[] __initdata = {
#ifdef CONFIG_AC3200
{ac3200_probe, 0},
#endif
#ifdef CONFIG_ES3210 #ifdef CONFIG_ES3210
{es_probe, 0}, {es_probe, 0},
#endif #endif
......
...@@ -75,7 +75,6 @@ static const char *port_name[4] = { "10baseT", "invalid", "AUI", "10base2"}; ...@@ -75,7 +75,6 @@ static const char *port_name[4] = { "10baseT", "invalid", "AUI", "10base2"};
#define AC_START_PG 0x00 /* First page of 8390 TX buffer */ #define AC_START_PG 0x00 /* First page of 8390 TX buffer */
#define AC_STOP_PG 0x80 /* Last page +1 of the 8390 RX ring */ #define AC_STOP_PG 0x80 /* Last page +1 of the 8390 RX ring */
int ac3200_probe(struct net_device *dev);
static int ac_probe1(int ioaddr, struct net_device *dev); static int ac_probe1(int ioaddr, struct net_device *dev);
static int ac_open(struct net_device *dev); static int ac_open(struct net_device *dev);
...@@ -96,9 +95,11 @@ static int ac_close_card(struct net_device *dev); ...@@ -96,9 +95,11 @@ static int ac_close_card(struct net_device *dev);
or the unique value in the station address PROM. or the unique value in the station address PROM.
*/ */
int __init ac3200_probe(struct net_device *dev) static int __init do_ac3200_probe(struct net_device *dev)
{ {
unsigned short ioaddr = dev->base_addr; unsigned short ioaddr = dev->base_addr;
int irq = dev->irq;
int mem_start = dev->mem_start;
SET_MODULE_OWNER(dev); SET_MODULE_OWNER(dev);
...@@ -110,13 +111,53 @@ int __init ac3200_probe(struct net_device *dev) ...@@ -110,13 +111,53 @@ int __init ac3200_probe(struct net_device *dev)
if ( ! EISA_bus) if ( ! EISA_bus)
return -ENXIO; return -ENXIO;
for (ioaddr = 0x1000; ioaddr < 0x9000; ioaddr += 0x1000) for (ioaddr = 0x1000; ioaddr < 0x9000; ioaddr += 0x1000) {
if (ac_probe1(ioaddr, dev) == 0) if (ac_probe1(ioaddr, dev) == 0)
return 0; return 0;
dev->irq = irq;
dev->mem_start = mem_start;
}
return -ENODEV; return -ENODEV;
} }
static void cleanup_card(struct net_device *dev)
{
/* Someday free_irq may be in ac_close_card() */
free_irq(dev->irq, dev);
release_region(dev->base_addr, AC_IO_EXTENT);
if (ei_status.reg0)
iounmap((void *)dev->mem_start);
kfree(dev->priv);
}
struct net_device * __init ac3200_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_ac3200_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 ac_probe1(int ioaddr, struct net_device *dev) static int __init ac_probe1(int ioaddr, struct net_device *dev)
{ {
int i, retval; int i, retval;
...@@ -338,7 +379,7 @@ static int ac_close_card(struct net_device *dev) ...@@ -338,7 +379,7 @@ static int ac_close_card(struct net_device *dev)
#ifdef MODULE #ifdef MODULE
#define MAX_AC32_CARDS 4 /* Max number of AC32 cards per module */ #define MAX_AC32_CARDS 4 /* Max number of AC32 cards per module */
static struct net_device dev_ac32[MAX_AC32_CARDS]; static struct net_device *dev_ac32[MAX_AC32_CARDS];
static int io[MAX_AC32_CARDS]; static int io[MAX_AC32_CARDS];
static int irq[MAX_AC32_CARDS]; static int irq[MAX_AC32_CARDS];
static int mem[MAX_AC32_CARDS]; static int mem[MAX_AC32_CARDS];
...@@ -354,26 +395,33 @@ MODULE_LICENSE("GPL"); ...@@ -354,26 +395,33 @@ MODULE_LICENSE("GPL");
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_AC32_CARDS; this_dev++) { for (this_dev = 0; this_dev < MAX_AC32_CARDS; this_dev++) {
struct net_device *dev = &dev_ac32[this_dev]; if (io[this_dev] == 0 && this_dev != 0)
break;
dev = alloc_etherdev(0);
if (!dev)
break;
dev->priv = NULL;
dev->irq = irq[this_dev]; dev->irq = irq[this_dev];
dev->base_addr = io[this_dev]; dev->base_addr = io[this_dev];
dev->mem_start = mem[this_dev]; /* Currently ignored by driver */ dev->mem_start = mem[this_dev]; /* Currently ignored by driver */
dev->init = ac3200_probe; if (do_ac3200_probe(dev) == 0) {
/* Default is to only install one card. */ if (register_netdev(dev) == 0) {
if (io[this_dev] == 0 && this_dev != 0) break; dev_ac32[found++] = dev;
if (register_netdev(dev) != 0) { continue;
printk(KERN_WARNING "ac3200.c: No ac3200 card found (i/o = 0x%x).\n", io[this_dev]);
if (found != 0) { /* Got at least one. */
return 0;
} }
return -ENXIO; cleanup_card(dev);
} }
found++; free_netdev(dev);
printk(KERN_WARNING "ac3200.c: No ac3200 card found (i/o = 0x%x).\n", io[this_dev]);
break;
} }
return 0; if (found)
return 0;
return -ENXIO;
} }
void void
...@@ -382,16 +430,11 @@ cleanup_module(void) ...@@ -382,16 +430,11 @@ cleanup_module(void)
int this_dev; int this_dev;
for (this_dev = 0; this_dev < MAX_AC32_CARDS; this_dev++) { for (this_dev = 0; this_dev < MAX_AC32_CARDS; this_dev++) {
struct net_device *dev = &dev_ac32[this_dev]; struct net_device *dev = dev_ac32[this_dev];
if (dev->priv != NULL) { if (dev) {
/* Someday free_irq may be in ac_close_card() */
free_irq(dev->irq, dev);
release_region(dev->base_addr, AC_IO_EXTENT);
if (ei_status.reg0)
iounmap((void *)dev->mem_start);
unregister_netdev(dev); unregister_netdev(dev);
kfree(dev->priv); cleanup_card(dev);
dev->priv = NULL; 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