Commit 57332766 authored by Stephen Hemminger's avatar Stephen Hemminger

[PATCH] (25/42) lne390

NE49-lne390
	* switched lne390 to dynamic allocation
	* lne390: fixed order of freeing bugs
	* lne390: fixed clobbering on autoprobe
	* lne390: fixed resource leaks on failure exits
parent 0665bf6f
...@@ -65,7 +65,7 @@ extern struct net_device *skmca_probe(int unit); ...@@ -65,7 +65,7 @@ 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 int ac3200_probe(struct net_device *);
extern int es_probe(struct net_device *); extern int es_probe(struct net_device *);
extern int lne390_probe(struct net_device *); extern struct net_device *lne390_probe(int unit);
extern struct net_device *e2100_probe(int unit); extern struct net_device *e2100_probe(int unit);
extern struct net_device *ni5010_probe(int unit); extern struct net_device *ni5010_probe(int unit);
extern struct net_device *ni52_probe(int unit); extern struct net_device *ni52_probe(int unit);
...@@ -170,6 +170,10 @@ static struct devprobe eisa_probes[] __initdata = { ...@@ -170,6 +170,10 @@ static struct devprobe eisa_probes[] __initdata = {
#ifdef CONFIG_ES3210 #ifdef CONFIG_ES3210
{es_probe, 0}, {es_probe, 0},
#endif #endif
{NULL, 0},
};
static struct devprobe2 eisa_probes2[] __initdata = {
#ifdef CONFIG_LNE390 #ifdef CONFIG_LNE390
{lne390_probe, 0}, {lne390_probe, 0},
#endif #endif
...@@ -392,6 +396,7 @@ static void __init ethif_probe2(int unit) ...@@ -392,6 +396,7 @@ static void __init ethif_probe2(int unit)
if (base_addr == 1) if (base_addr == 1)
return; return;
probe_list2(unit, eisa_probes2, base_addr == 0) &&
probe_list2(unit, mca_probes, base_addr == 0) && probe_list2(unit, mca_probes, base_addr == 0) &&
probe_list2(unit, isa_probes, base_addr == 0) && probe_list2(unit, isa_probes, base_addr == 0) &&
probe_list2(unit, parport_probes, base_addr == 0); probe_list2(unit, parport_probes, base_addr == 0);
......
...@@ -49,7 +49,6 @@ static const char *version = ...@@ -49,7 +49,6 @@ static const char *version =
#include "8390.h" #include "8390.h"
int lne390_probe(struct net_device *dev);
static int lne390_probe1(struct net_device *dev, int ioaddr); static int lne390_probe1(struct net_device *dev, int ioaddr);
static int lne390_open(struct net_device *dev); static int lne390_open(struct net_device *dev);
...@@ -103,9 +102,11 @@ static unsigned int shmem_mapB[] __initdata = {0xff, 0xfe, 0x0e, 0xfff, 0xffe, 0 ...@@ -103,9 +102,11 @@ static unsigned int shmem_mapB[] __initdata = {0xff, 0xfe, 0x0e, 0xfff, 0xffe, 0
* PROM for a match against the value assigned to Mylex. * PROM for a match against the value assigned to Mylex.
*/ */
int __init lne390_probe(struct net_device *dev) static int __init do_lne390_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;
int ret; int ret;
SET_MODULE_OWNER(dev); SET_MODULE_OWNER(dev);
...@@ -135,11 +136,49 @@ int __init lne390_probe(struct net_device *dev) ...@@ -135,11 +136,49 @@ int __init lne390_probe(struct net_device *dev)
if (lne390_probe1(dev, ioaddr) == 0) if (lne390_probe1(dev, ioaddr) == 0)
return 0; return 0;
release_region(ioaddr, LNE390_IO_EXTENT); release_region(ioaddr, LNE390_IO_EXTENT);
dev->irq = irq;
dev->mem_start = mem_start;
} }
return -ENODEV; return -ENODEV;
} }
static void cleanup_card(struct net_device *dev)
{
free_irq(dev->irq, dev);
release_region(dev->base_addr, LNE390_IO_EXTENT);
if (ei_status.reg0)
iounmap((void *)dev->mem_start);
kfree(dev->priv);
}
struct net_device * __init lne390_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_lne390_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 lne390_probe1(struct net_device *dev, int ioaddr) static int __init lne390_probe1(struct net_device *dev, int ioaddr)
{ {
int i, revision, ret; int i, revision, ret;
...@@ -373,7 +412,7 @@ static int lne390_close(struct net_device *dev) ...@@ -373,7 +412,7 @@ static int lne390_close(struct net_device *dev)
#ifdef MODULE #ifdef MODULE
#define MAX_LNE_CARDS 4 /* Max number of LNE390 cards per module */ #define MAX_LNE_CARDS 4 /* Max number of LNE390 cards per module */
static struct net_device dev_lne[MAX_LNE_CARDS]; static struct net_device *dev_lne[MAX_LNE_CARDS];
static int io[MAX_LNE_CARDS]; static int io[MAX_LNE_CARDS];
static int irq[MAX_LNE_CARDS]; static int irq[MAX_LNE_CARDS];
static int mem[MAX_LNE_CARDS]; static int mem[MAX_LNE_CARDS];
...@@ -389,26 +428,33 @@ MODULE_LICENSE("GPL"); ...@@ -389,26 +428,33 @@ MODULE_LICENSE("GPL");
int init_module(void) int init_module(void)
{ {
struct net_device *dev;
int this_dev, found = 0; int this_dev, found = 0;
for (this_dev = 0; this_dev < MAX_LNE_CARDS; this_dev++) { for (this_dev = 0; this_dev < MAX_LNE_CARDS; this_dev++) {
struct net_device *dev = &dev_lne[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]; dev->mem_start = mem[this_dev];
dev->init = lne390_probe; if (do_lne390_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_lne[found++] = dev;
if (register_netdev(dev) != 0) { continue;
printk(KERN_WARNING "lne390.c: No LNE390 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 "lne390.c: No LNE390 card found (i/o = 0x%x).\n", io[this_dev]);
break;
} }
return 0; if (found)
return 0;
return -ENXIO;
} }
void cleanup_module(void) void cleanup_module(void)
...@@ -416,15 +462,11 @@ void cleanup_module(void) ...@@ -416,15 +462,11 @@ void cleanup_module(void)
int this_dev; int this_dev;
for (this_dev = 0; this_dev < MAX_LNE_CARDS; this_dev++) { for (this_dev = 0; this_dev < MAX_LNE_CARDS; this_dev++) {
struct net_device *dev = &dev_lne[this_dev]; struct net_device *dev = dev_lne[this_dev];
if (dev->priv != NULL) { if (dev) {
void *priv = dev->priv;
free_irq(dev->irq, dev);
release_region(dev->base_addr, LNE390_IO_EXTENT);
if (ei_status.reg0)
iounmap((void *)dev->mem_start);
unregister_netdev(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