Commit 5828f47d authored by Stephen Hemminger's avatar Stephen Hemminger

[PATCH] (32/42) mac8390

NE57-mac8390
	* switched mac8390 to dynamic allocation
	* mac8390: fixed resource leaks on failure exits
	* get rid of MOD_INC/DEC
parent d26ee832
...@@ -88,7 +88,7 @@ extern struct net_device *tc515_probe(int unit); ...@@ -88,7 +88,7 @@ extern struct net_device *tc515_probe(int unit);
extern struct net_device *lance_probe(int unit); extern struct net_device *lance_probe(int unit);
extern int mace_probe(struct net_device *dev); extern int mace_probe(struct net_device *dev);
extern int macsonic_probe(struct net_device *dev); extern int macsonic_probe(struct net_device *dev);
extern int mac8390_probe(struct net_device *dev); extern struct net_device *mac8390_probe(int unit);
extern struct net_device *mac89x0_probe(int unit); extern struct net_device *mac89x0_probe(int unit);
extern struct net_device *mc32_probe(int unit); extern struct net_device *mc32_probe(int unit);
extern struct net_device *cops_probe(int unit); extern struct net_device *cops_probe(int unit);
...@@ -325,14 +325,14 @@ static struct devprobe m68k_probes[] __initdata = { ...@@ -325,14 +325,14 @@ static struct devprobe m68k_probes[] __initdata = {
#endif #endif
#ifdef CONFIG_MACSONIC /* Mac SONIC-based Ethernet of all sorts */ #ifdef CONFIG_MACSONIC /* Mac SONIC-based Ethernet of all sorts */
{macsonic_probe, 0}, {macsonic_probe, 0},
#endif
#ifdef CONFIG_MAC8390 /* NuBus NS8390-based cards */
{mac8390_probe, 0},
#endif #endif
{NULL, 0}, {NULL, 0},
}; };
static struct devprobe2 m68k_probes2[] __initdata = { static struct devprobe2 m68k_probes2[] __initdata = {
#ifdef CONFIG_MAC8390 /* NuBus NS8390-based cards */
{mac8390_probe, 0},
#endif
#ifdef CONFIG_MAC89x0 #ifdef CONFIG_MAC89x0
{mac89x0_probe, 0}, {mac89x0_probe, 0},
#endif #endif
......
...@@ -124,11 +124,10 @@ static int useresources[] = { ...@@ -124,11 +124,10 @@ static int useresources[] = {
static char version[] __initdata = static char version[] __initdata =
"mac8390.c: v0.4 2001-05-15 David Huggins-Daines <dhd@debian.org> and others\n"; "mac8390.c: v0.4 2001-05-15 David Huggins-Daines <dhd@debian.org> and others\n";
extern int mac8390_probe(struct net_device * dev);
extern enum mac8390_type mac8390_ident(struct nubus_dev * dev); extern enum mac8390_type mac8390_ident(struct nubus_dev * dev);
extern int mac8390_memsize(unsigned long membase); extern int mac8390_memsize(unsigned long membase);
extern int mac8390_memtest(struct net_device * dev); extern int mac8390_memtest(struct net_device * dev);
extern int mac8390_initdev(struct net_device * dev, struct nubus_dev * ndev, static int mac8390_initdev(struct net_device * dev, struct nubus_dev * ndev,
enum mac8390_type type); enum mac8390_type type);
static int mac8390_open(struct net_device * dev); static int mac8390_open(struct net_device * dev);
...@@ -223,14 +222,14 @@ int __init mac8390_memsize(unsigned long membase) ...@@ -223,14 +222,14 @@ int __init mac8390_memsize(unsigned long membase)
return i * 0x1000; return i * 0x1000;
} }
static int probed __initdata = 0; struct net_device * __init mac8390_probe(int unit)
int __init mac8390_probe(struct net_device * dev)
{ {
struct net_device *dev;
volatile unsigned short *i; volatile unsigned short *i;
int boards_found = 0;
int version_disp = 0; int version_disp = 0;
struct nubus_dev * ndev = NULL; struct nubus_dev * ndev = NULL;
static int probed;
int err = -ENDOEV;
struct nubus_dir dir; struct nubus_dir dir;
struct nubus_dirent ent; struct nubus_dirent ent;
...@@ -238,28 +237,29 @@ int __init mac8390_probe(struct net_device * dev) ...@@ -238,28 +237,29 @@ int __init mac8390_probe(struct net_device * dev)
enum mac8390_type cardtype; enum mac8390_type cardtype;
if (probed)
return -ENODEV;
probed++;
/* probably should check for Nubus instead */ /* probably should check for Nubus instead */
if (!MACH_IS_MAC) if (!MACH_IS_MAC)
return -ENODEV; return ERR_PTR(-ENODEV);
dev = alloc_etherdev(0);
if (!dev)
return ERR_PTR(-ENOMEM);
dev->priv = NULL;
if (unit >= 0)
sprintf(dev->name, "eth%d", unit);
SET_MODULE_OWNER(dev);
while ((ndev = nubus_find_type(NUBUS_CAT_NETWORK, NUBUS_TYPE_ETHERNET, ndev))) { while ((ndev = nubus_find_type(NUBUS_CAT_NETWORK, NUBUS_TYPE_ETHERNET, ndev))) {
/* Have we seen it already? */
dev = NULL; if (slots & (1<<ndev->board->slot))
if ((cardtype = mac8390_ident(ndev)) == MAC8390_NONE)
continue; continue;
slots |= 1<<ndev->board->slot;
dev = init_etherdev(dev, 0); if ((cardtype = mac8390_ident(ndev)) == MAC8390_NONE)
if (dev == NULL) { continue;
printk(KERN_ERR "Unable to allocate etherdev"
"structure!\n");
return -ENOMEM;
}
if (version_disp == 0) { if (version_disp == 0) {
version_disp = 1; version_disp = 1;
...@@ -358,21 +358,28 @@ int __init mac8390_probe(struct net_device * dev) ...@@ -358,21 +358,28 @@ int __init mac8390_probe(struct net_device * dev)
printk(KERN_ERR "Card type %s is" printk(KERN_ERR "Card type %s is"
" unsupported, sorry\n", " unsupported, sorry\n",
cardname[cardtype]); cardname[cardtype]);
return -ENODEV; continue;
} }
} }
/* Do the nasty 8390 stuff */ /* Do the nasty 8390 stuff */
if (mac8390_initdev(dev, ndev, cardtype)) if (!mac8390_initdev(dev, ndev, cardtype))
continue; break;
boards_found++;
} }
/* We're outta here */ if (!ndev)
if (boards_found > 0) goto out;
return 0; err = register_netdev(dev);
else if (err)
return -ENODEV; goto out1;
return dev;
out1:
kfree(dev->priv);
dev->priv = NULL;
out:
free_netdev(dev);
return ERR_PTE(err);
} }
#ifdef MODULE #ifdef MODULE
...@@ -380,26 +387,40 @@ MODULE_AUTHOR("David Huggins-Daines <dhd@debian.org> and others"); ...@@ -380,26 +387,40 @@ MODULE_AUTHOR("David Huggins-Daines <dhd@debian.org> and others");
MODULE_DESCRIPTION("Macintosh NS8390-based Nubus Ethernet driver"); MODULE_DESCRIPTION("Macintosh NS8390-based Nubus Ethernet driver");
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
/* overkill, of course */
static struct net_device *dev_mac8390[15];
int init_module(void) int init_module(void)
{ {
if (mac8390_probe(NULL)) { int i;
for (i = 0; i < 15; i++) {
struct net_device *dev = mac8390_probe(-1);
if (IS_ERR(dev))
break;
dev_mac890[i] = dev;
}
if (!i) {
printk(KERN_NOTICE "mac8390.c: No useable cards found, driver NOT installed.\n"); printk(KERN_NOTICE "mac8390.c: No useable cards found, driver NOT installed.\n");
return -ENODEV; return -ENODEV;
} }
lock_8390_module();
return 0; return 0;
} }
void cleanup_module(void) void cleanup_module(void)
{ {
/* FIXME: should probably keep track of net_device structs int i;
somewhere and unregister them here? */ for (i = 0; i < 15; i++) {
unlock_8390_module(); struct net_device *dev = dev_mac890[i];
if (dev) {
unregister_netdev(dev);
kfree(dev->priv);
free_netdev(dev);
}
}
} }
#endif /* MODULE */ #endif /* MODULE */
int __init mac8390_initdev(struct net_device * dev, struct nubus_dev * ndev, static int __init mac8390_initdev(struct net_device * dev, struct nubus_dev * ndev,
enum mac8390_type type) enum mac8390_type type)
{ {
static u32 fwrd4_offsets[16]={ static u32 fwrd4_offsets[16]={
...@@ -499,6 +520,8 @@ int __init mac8390_initdev(struct net_device * dev, struct nubus_dev * ndev, ...@@ -499,6 +520,8 @@ int __init mac8390_initdev(struct net_device * dev, struct nubus_dev * ndev,
break; break;
default: default:
printk(KERN_ERR "Card type %s is unsupported, sorry\n", cardname[type]); printk(KERN_ERR "Card type %s is unsupported, sorry\n", cardname[type]);
kfree(dev->priv);
dev->priv = NULL;
return -ENODEV; return -ENODEV;
} }
...@@ -529,7 +552,6 @@ static int mac8390_open(struct net_device *dev) ...@@ -529,7 +552,6 @@ static int mac8390_open(struct net_device *dev)
printk ("%s: unable to get IRQ %d.\n", dev->name, dev->irq); printk ("%s: unable to get IRQ %d.\n", dev->name, dev->irq);
return -EAGAIN; return -EAGAIN;
} }
MOD_INC_USE_COUNT;
return 0; return 0;
} }
...@@ -537,7 +559,6 @@ static int mac8390_close(struct net_device *dev) ...@@ -537,7 +559,6 @@ static int mac8390_close(struct net_device *dev)
{ {
free_irq(dev->irq, dev); free_irq(dev->irq, dev);
ei_close(dev); ei_close(dev);
MOD_DEC_USE_COUNT;
return 0; return 0;
} }
......
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