Commit d26ee832 authored by Stephen Hemminger's avatar Stephen Hemminger

[PATCH] (31/42) mac89x0

NE56-mac8390
	* switched mac8390 to dynamic allocation
	* mac8390: fixed resource leaks on failure exits
parent 93b40e80
...@@ -89,7 +89,7 @@ extern struct net_device *lance_probe(int unit); ...@@ -89,7 +89,7 @@ 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 int mac8390_probe(struct net_device *dev);
extern int mac89x0_probe(struct net_device *dev); 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);
extern struct net_device *ltpc_probe(void); extern struct net_device *ltpc_probe(void);
...@@ -329,6 +329,10 @@ static struct devprobe m68k_probes[] __initdata = { ...@@ -329,6 +329,10 @@ static struct devprobe m68k_probes[] __initdata = {
#ifdef CONFIG_MAC8390 /* NuBus NS8390-based cards */ #ifdef CONFIG_MAC8390 /* NuBus NS8390-based cards */
{mac8390_probe, 0}, {mac8390_probe, 0},
#endif #endif
{NULL, 0},
};
static struct devprobe2 m68k_probes2[] __initdata = {
#ifdef CONFIG_MAC89x0 #ifdef CONFIG_MAC89x0
{mac89x0_probe, 0}, {mac89x0_probe, 0},
#endif #endif
...@@ -391,6 +395,7 @@ static void __init ethif_probe2(int unit) ...@@ -391,6 +395,7 @@ static void __init ethif_probe2(int unit)
if (base_addr == 1) if (base_addr == 1)
return; return;
probe_list2(unit, m68k_probes2, base_addr == 0) &&
probe_list2(unit, mips_probes, base_addr == 0) && probe_list2(unit, mips_probes, base_addr == 0) &&
probe_list2(unit, eisa_probes, base_addr == 0) && probe_list2(unit, eisa_probes, base_addr == 0) &&
probe_list2(unit, mca_probes, base_addr == 0) && probe_list2(unit, mca_probes, base_addr == 0) &&
......
...@@ -123,7 +123,6 @@ struct net_local { ...@@ -123,7 +123,6 @@ struct net_local {
/* Index to functions, as function prototypes. */ /* Index to functions, as function prototypes. */
extern int mac89x0_probe(struct net_device *dev);
#if 0 #if 0
extern void reset_chip(struct net_device *dev); extern void reset_chip(struct net_device *dev);
#endif #endif
...@@ -170,8 +169,9 @@ writereg(struct net_device *dev, int portno, int value) ...@@ -170,8 +169,9 @@ writereg(struct net_device *dev, int portno, int value)
/* Probe for the CS8900 card in slot E. We won't bother looking /* Probe for the CS8900 card in slot E. We won't bother looking
anywhere else until we have a really good reason to do so. */ anywhere else until we have a really good reason to do so. */
int __init mac89x0_probe(struct net_device *dev) struct net_device * __init mac89x0_probe(int unit)
{ {
struct net_device *dev;
static int once_is_enough; static int once_is_enough;
struct net_local *lp; struct net_local *lp;
static unsigned version_printed; static unsigned version_printed;
...@@ -179,18 +179,28 @@ int __init mac89x0_probe(struct net_device *dev) ...@@ -179,18 +179,28 @@ int __init mac89x0_probe(struct net_device *dev)
unsigned rev_type = 0; unsigned rev_type = 0;
unsigned long ioaddr; unsigned long ioaddr;
unsigned short sig; unsigned short sig;
int err = -ENODEV;
dev = alloc_etherdev(sizeof(struct net_local));
if (!dev)
return ERR_PTR(-ENOMEM);
if (unit >= 0) {
sprintf(dev->name, "eth%d", unit);
netdev_boot_setup_check(dev);
}
SET_MODULE_OWNER(dev); SET_MODULE_OWNER(dev);
if (once_is_enough) if (once_is_enough)
return -ENODEV; goto out;
once_is_enough = 1; once_is_enough = 1;
/* We might have to parameterize this later */ /* We might have to parameterize this later */
slot = 0xE; slot = 0xE;
/* Get out now if there's a real NuBus card in slot E */ /* Get out now if there's a real NuBus card in slot E */
if (nubus_find_slot(slot, NULL) != NULL) if (nubus_find_slot(slot, NULL) != NULL)
return -ENODEV; goto out;
/* The pseudo-ISA bits always live at offset 0x300 (gee, /* The pseudo-ISA bits always live at offset 0x300 (gee,
wonder why...) */ wonder why...) */
...@@ -206,21 +216,15 @@ int __init mac89x0_probe(struct net_device *dev) ...@@ -206,21 +216,15 @@ int __init mac89x0_probe(struct net_device *dev)
local_irq_restore(flags); local_irq_restore(flags);
if (!card_present) if (!card_present)
return -ENODEV; goto out;
} }
nubus_writew(0, ioaddr + ADD_PORT); nubus_writew(0, ioaddr + ADD_PORT);
sig = nubus_readw(ioaddr + DATA_PORT); sig = nubus_readw(ioaddr + DATA_PORT);
if (sig != swab16(CHIP_EISA_ID_SIG)) if (sig != swab16(CHIP_EISA_ID_SIG))
return -ENODEV; goto out;
/* Initialize the net_device structure. */ /* Initialize the net_device structure. */
if (dev->priv == NULL) {
dev->priv = kmalloc(sizeof(struct net_local), GFP_KERNEL);
if (!dev->priv)
return -ENOMEM;
memset(dev->priv, 0, sizeof(struct net_local));
}
lp = (struct net_local *)dev->priv; lp = (struct net_local *)dev->priv;
/* Fill in the 'dev' fields. */ /* Fill in the 'dev' fields. */
...@@ -258,9 +262,7 @@ int __init mac89x0_probe(struct net_device *dev) ...@@ -258,9 +262,7 @@ int __init mac89x0_probe(struct net_device *dev)
/* Try to read the MAC address */ /* Try to read the MAC address */
if ((readreg(dev, PP_SelfST) & (EEPROM_PRESENT | EEPROM_OK)) == 0) { if ((readreg(dev, PP_SelfST) & (EEPROM_PRESENT | EEPROM_OK)) == 0) {
printk("\nmac89x0: No EEPROM, giving up now.\n"); printk("\nmac89x0: No EEPROM, giving up now.\n");
kfree(dev->priv); goto out1;
dev->priv = NULL;
return -ENODEV;
} else { } else {
for (i = 0; i < ETH_ALEN; i += 2) { for (i = 0; i < ETH_ALEN; i += 2) {
/* Big-endian (why??!) */ /* Big-endian (why??!) */
...@@ -277,6 +279,7 @@ int __init mac89x0_probe(struct net_device *dev) ...@@ -277,6 +279,7 @@ int __init mac89x0_probe(struct net_device *dev)
for (i = 0; i < ETH_ALEN; i++) for (i = 0; i < ETH_ALEN; i++)
printk("%2.2x%s", dev->dev_addr[i], printk("%2.2x%s", dev->dev_addr[i],
((i < ETH_ALEN-1) ? ":" : "")); ((i < ETH_ALEN-1) ? ":" : ""));
printk("\n");
dev->open = net_open; dev->open = net_open;
dev->stop = net_close; dev->stop = net_close;
...@@ -285,11 +288,15 @@ int __init mac89x0_probe(struct net_device *dev) ...@@ -285,11 +288,15 @@ int __init mac89x0_probe(struct net_device *dev)
dev->set_multicast_list = &set_multicast_list; dev->set_multicast_list = &set_multicast_list;
dev->set_mac_address = &set_mac_address; dev->set_mac_address = &set_mac_address;
/* Fill in the fields of the net_device structure with ethernet values. */ err = register_netdev(dev);
ether_setup(dev); if (err)
goto out1;
printk("\n");
return 0; return 0;
out1:
nubus_writew(0, dev->base_addr + ADD_PORT);
out:
free_netdev(dev);
return ERR_PTR(err);
} }
#if 0 #if 0
...@@ -619,7 +626,7 @@ static int set_mac_address(struct net_device *dev, void *addr) ...@@ -619,7 +626,7 @@ static int set_mac_address(struct net_device *dev, void *addr)
#ifdef MODULE #ifdef MODULE
static struct net_device dev_cs89x0; static struct net_device *dev_cs89x0;
static int debug; static int debug;
MODULE_PARM(debug, "i"); MODULE_PARM(debug, "i");
...@@ -630,16 +637,10 @@ int ...@@ -630,16 +637,10 @@ int
init_module(void) init_module(void)
{ {
net_debug = debug; net_debug = debug;
dev_cs89x0.init = mac89x0_probe; dev_cs89x0 = mac89x0_probe(-1);
dev_cs89x0.priv = kmalloc(sizeof(struct net_local), GFP_KERNEL); if (IS_ERR(dev_cs89x0)) {
if (!dev_cs89x0.priv)
return -ENOMEM;
memset(dev_cs89x0.priv, 0, sizeof(struct net_local));
if (register_netdev(&dev_cs89x0) != 0) {
printk(KERN_WARNING "mac89x0.c: No card found\n"); printk(KERN_WARNING "mac89x0.c: No card found\n");
kfree(dev_cs89x0.priv); return PTR_ERR(dev_cs89x0);
return -ENXIO;
} }
return 0; return 0;
} }
...@@ -647,19 +648,9 @@ init_module(void) ...@@ -647,19 +648,9 @@ init_module(void)
void void
cleanup_module(void) cleanup_module(void)
{ {
unregister_netdev(dev_cs89x0);
#endif nubus_writew(0, dev_cs89x0->base_addr + ADD_PORT);
#ifdef MODULE free_netdev(dev_cs89x0);
nubus_writew(0, dev_cs89x0.base_addr + ADD_PORT);
#endif
#ifdef MODULE
if (dev_cs89x0.priv != NULL) {
/* Free up the private structure, or leak memory :-) */
unregister_netdev(&dev_cs89x0);
kfree(dev_cs89x0.priv);
dev_cs89x0.priv = NULL; /* gets re-allocated by cs89x0_probe1 */
}
} }
#endif /* MODULE */ #endif /* MODULE */
......
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