Commit e0d6b499 authored by Stephen Hemminger's avatar Stephen Hemminger

[PATCH] (13/42) e2100

Based on viro NE37-e2100
	* switched e2100 to dynamic allocation
	* e2100: fixed order of freeing bugs
	* e2100: fixed resource leaks on failure exits
	* e2100: fixed clobbering on autoprobe
parent 4e8a1fcb
......@@ -66,7 +66,7 @@ extern struct net_device *elplus_probe(int unit);
extern int ac3200_probe(struct net_device *);
extern int es_probe(struct net_device *);
extern int lne390_probe(struct net_device *);
extern int e2100_probe(struct net_device *);
extern struct net_device *e2100_probe(int unit);
extern struct net_device *ni5010_probe(int unit);
extern struct net_device *ni52_probe(int unit);
extern struct net_device *ni65_probe(int unit);
......@@ -218,14 +218,14 @@ static struct devprobe isa_probes[] __initdata = {
#endif
#ifdef CONFIG_HPLAN_PLUS
{hp_plus_probe, 0},
#endif
#ifdef CONFIG_E2100 /* Cabletron E21xx series. */
{e2100_probe, 0},
#endif
{NULL, 0},
};
static struct devprobe2 isa_probes2[] __initdata = {
#ifdef CONFIG_E2100 /* Cabletron E21xx series. */
{e2100_probe, 0},
#endif
#if defined(CONFIG_NE2000) || defined(CONFIG_NE2K_CBUS) /* ISA & PC-9800 CBUS (use ne2k-pci for PCI cards) */
{ne_probe, 0},
#endif
......
......@@ -95,7 +95,6 @@ static inline void mem_off(short port)
#define E21_BIG_RX_STOP_PG 0xF0 /* Last page +1 of RX ring */
#define E21_TX_START_PG E21_RX_STOP_PG /* First page of TX buffer */
int e2100_probe(struct net_device *dev);
static int e21_probe1(struct net_device *dev, int ioaddr);
static int e21_open(struct net_device *dev);
......@@ -117,10 +116,11 @@ static int e21_close(struct net_device *dev);
station address).
*/
int __init e2100_probe(struct net_device *dev)
static int __init do_e2100_probe(struct net_device *dev)
{
int *port;
int base_addr = dev->base_addr;
int irq = dev->irq;
SET_MODULE_OWNER(dev);
......@@ -129,13 +129,50 @@ int __init e2100_probe(struct net_device *dev)
else if (base_addr != 0) /* Don't probe at all. */
return -ENXIO;
for (port = e21_probe_list; *port; port++)
for (port = e21_probe_list; *port; port++) {
dev->irq = irq;
if (e21_probe1(dev, *port) == 0)
return 0;
}
return -ENODEV;
}
static void cleanup_card(struct net_device *dev)
{
void *priv = dev->priv;
/* NB: e21_close() handles free_irq */
release_region(dev->base_addr, E21_IO_EXTENT);
kfree(priv);
}
struct net_device * __init e2100_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_e2100_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 e21_probe1(struct net_device *dev, int ioaddr)
{
int i, status, retval;
......@@ -376,7 +413,7 @@ e21_close(struct net_device *dev)
#ifdef MODULE
#define MAX_E21_CARDS 4 /* Max number of E21 cards per module */
static struct net_device dev_e21[MAX_E21_CARDS];
static struct net_device *dev_e21[MAX_E21_CARDS];
static int io[MAX_E21_CARDS];
static int irq[MAX_E21_CARDS];
static int mem[MAX_E21_CARDS];
......@@ -398,29 +435,36 @@ ISA device autoprobes on a running machine are not recommended. */
int
init_module(void)
{
struct net_device *dev;
int this_dev, found = 0;
for (this_dev = 0; this_dev < MAX_E21_CARDS; this_dev++) {
struct net_device *dev = &dev_e21[this_dev];
dev->irq = irq[this_dev];
dev->base_addr = io[this_dev];
dev->mem_start = mem[this_dev];
dev->mem_end = xcvr[this_dev]; /* low 4bits = xcvr sel. */
dev->init = e2100_probe;
if (io[this_dev] == 0) {
if (this_dev != 0) break; /* only autoprobe 1st one */
printk(KERN_NOTICE "e2100.c: Presently autoprobing (not recommended) for a single card.\n");
}
if (register_netdev(dev) != 0) {
printk(KERN_WARNING "e2100.c: No E2100 card found (i/o = 0x%x).\n", io[this_dev]);
if (found != 0) { /* Got at least one. */
return 0;
dev = alloc_etherdev(0);
if (!dev)
break;
dev->priv = NULL;
dev->irq = irq[this_dev];
dev->base_addr = io[this_dev];
dev->mem_start = mem[this_dev];
dev->mem_end = xcvr[this_dev]; /* low 4bits = xcvr sel. */
if (do_e2100_probe(dev) == 0) {
if (register_netdev(dev) == 0) {
dev_e21[found++] = dev;
continue;
}
return -ENXIO;
cleanup_card(dev);
}
found++;
free_netdev(dev);
printk(KERN_WARNING "e2100.c: No E2100 card found (i/o = 0x%x).\n", io[this_dev]);
break;
}
return 0;
if (found)
return 0;
return -ENXIO;
}
void
......@@ -429,13 +473,11 @@ cleanup_module(void)
int this_dev;
for (this_dev = 0; this_dev < MAX_E21_CARDS; this_dev++) {
struct net_device *dev = &dev_e21[this_dev];
if (dev->priv != NULL) {
void *priv = dev->priv;
/* NB: e21_close() handles free_irq */
release_region(dev->base_addr, E21_IO_EXTENT);
struct net_device *dev = dev_e21[this_dev];
if (dev) {
unregister_netdev(dev);
kfree(priv);
cleanup_card(dev);
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