Commit 4f17c24b authored by Stephen Hemminger's avatar Stephen Hemminger

[PATCH] (14/42) hpplus

Based on NE38-hpplus
	* switched hp-plus to dynamic allocation
	* hp-plus: fixed order of freeing bugs
	* hp-plus: fixed resource leaks on failure exits
	* hp-plus: fixed clobbering on autoprobe
parent e0d6b499
...@@ -48,7 +48,7 @@ extern int wd_probe(struct net_device *dev); ...@@ -48,7 +48,7 @@ extern int wd_probe(struct net_device *dev);
extern int el2_probe(struct net_device *dev); extern int el2_probe(struct net_device *dev);
extern struct net_device *ne_probe(int unit); extern struct net_device *ne_probe(int unit);
extern int hp_probe(struct net_device *dev); extern int hp_probe(struct net_device *dev);
extern int hp_plus_probe(struct net_device *dev); extern struct net_device *hp_plus_probe(int unit);
extern struct net_device *express_probe(int unit); extern struct net_device *express_probe(int unit);
extern struct net_device *eepro_probe(int unit); extern struct net_device *eepro_probe(int unit);
extern struct net_device *at1700_probe(int unit); extern struct net_device *at1700_probe(int unit);
...@@ -215,14 +215,14 @@ static struct devprobe isa_probes[] __initdata = { ...@@ -215,14 +215,14 @@ static struct devprobe isa_probes[] __initdata = {
#endif #endif
#ifdef CONFIG_HPLAN #ifdef CONFIG_HPLAN
{hp_probe, 0}, {hp_probe, 0},
#endif
#ifdef CONFIG_HPLAN_PLUS
{hp_plus_probe, 0},
#endif #endif
{NULL, 0}, {NULL, 0},
}; };
static struct devprobe2 isa_probes2[] __initdata = { static struct devprobe2 isa_probes2[] __initdata = {
#ifdef CONFIG_HPLAN_PLUS
{hp_plus_probe, 0},
#endif
#ifdef CONFIG_E2100 /* Cabletron E21xx series. */ #ifdef CONFIG_E2100 /* Cabletron E21xx series. */
{e2100_probe, 0}, {e2100_probe, 0},
#endif #endif
......
...@@ -92,7 +92,6 @@ enum HP_Option { ...@@ -92,7 +92,6 @@ enum HP_Option {
EnableIRQ = 4, FakeIntr = 8, BootROMEnb = 0x10, IOEnb = 0x20, EnableIRQ = 4, FakeIntr = 8, BootROMEnb = 0x10, IOEnb = 0x20,
MemEnable = 0x40, ZeroWait = 0x80, MemDisable = 0x1000, }; MemEnable = 0x40, ZeroWait = 0x80, MemDisable = 0x1000, };
int hp_plus_probe(struct net_device *dev);
static int hpp_probe1(struct net_device *dev, int ioaddr); static int hpp_probe1(struct net_device *dev, int ioaddr);
static void hpp_reset_8390(struct net_device *dev); static void hpp_reset_8390(struct net_device *dev);
...@@ -115,10 +114,11 @@ static void hpp_io_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hd ...@@ -115,10 +114,11 @@ static void hpp_io_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hd
/* Probe a list of addresses for an HP LAN+ adaptor. /* Probe a list of addresses for an HP LAN+ adaptor.
This routine is almost boilerplate. */ This routine is almost boilerplate. */
int __init hp_plus_probe(struct net_device *dev) static int __init do_hpp_probe(struct net_device *dev)
{ {
int i; int i;
int base_addr = dev->base_addr; int base_addr = dev->base_addr;
int irq = dev->irq;
SET_MODULE_OWNER(dev); SET_MODULE_OWNER(dev);
...@@ -127,13 +127,49 @@ int __init hp_plus_probe(struct net_device *dev) ...@@ -127,13 +127,49 @@ int __init hp_plus_probe(struct net_device *dev)
else if (base_addr != 0) /* Don't probe at all. */ else if (base_addr != 0) /* Don't probe at all. */
return -ENXIO; return -ENXIO;
for (i = 0; hpplus_portlist[i]; i++) for (i = 0; hpplus_portlist[i]; i++) {
if (hpp_probe1(dev, hpplus_portlist[i]) == 0) if (hpp_probe1(dev, hpplus_portlist[i]) == 0)
return 0; return 0;
dev->irq = irq;
}
return -ENODEV; return -ENODEV;
} }
static void cleanup_card(struct net_device *dev)
{
/* NB: hpp_close() handles free_irq */
release_region(dev->base_addr - NIC_OFFSET, HP_IO_EXTENT);
kfree(dev->priv);
}
struct net_device * __init hp_plus_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_hpp_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);
}
/* Do the interesting part of the probe at a single address. */ /* Do the interesting part of the probe at a single address. */
static int __init hpp_probe1(struct net_device *dev, int ioaddr) static int __init hpp_probe1(struct net_device *dev, int ioaddr)
{ {
...@@ -400,7 +436,7 @@ hpp_mem_block_output(struct net_device *dev, int count, ...@@ -400,7 +436,7 @@ hpp_mem_block_output(struct net_device *dev, int count,
#ifdef MODULE #ifdef MODULE
#define MAX_HPP_CARDS 4 /* Max number of HPP cards per module */ #define MAX_HPP_CARDS 4 /* Max number of HPP cards per module */
static struct net_device dev_hpp[MAX_HPP_CARDS]; static struct net_device *dev_hpp[MAX_HPP_CARDS];
static int io[MAX_HPP_CARDS]; static int io[MAX_HPP_CARDS];
static int irq[MAX_HPP_CARDS]; static int irq[MAX_HPP_CARDS];
...@@ -416,27 +452,34 @@ ISA device autoprobes on a running machine are not recommended. */ ...@@ -416,27 +452,34 @@ ISA device autoprobes on a running machine are not recommended. */
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_HPP_CARDS; this_dev++) { for (this_dev = 0; this_dev < MAX_HPP_CARDS; this_dev++) {
struct net_device *dev = &dev_hpp[this_dev];
dev->irq = irq[this_dev];
dev->base_addr = io[this_dev];
dev->init = hp_plus_probe;
if (io[this_dev] == 0) { if (io[this_dev] == 0) {
if (this_dev != 0) break; /* only autoprobe 1st one */ if (this_dev != 0) break; /* only autoprobe 1st one */
printk(KERN_NOTICE "hp-plus.c: Presently autoprobing (not recommended) for a single card.\n"); printk(KERN_NOTICE "hp-plus.c: Presently autoprobing (not recommended) for a single card.\n");
} }
if (register_netdev(dev) != 0) { dev = alloc_etherdev(0);
printk(KERN_WARNING "hp-plus.c: No HP-Plus card found (i/o = 0x%x).\n", io[this_dev]); if (!dev)
if (found != 0) { /* Got at least one. */ break;
return 0; dev->priv = NULL;
dev->irq = irq[this_dev];
dev->base_addr = io[this_dev];
if (do_hpp_probe(dev) == 0) {
if (register_netdev(dev) == 0) {
dev_hpp[found++] = dev;
continue;
} }
return -ENXIO; cleanup_card(dev);
} }
found++; free_netdev(dev);
printk(KERN_WARNING "hp-plus.c: No HP-Plus card found (i/o = 0x%x).\n", io[this_dev]);
break;
} }
return 0; if (found)
return 0;
return -ENXIO;
} }
void void
...@@ -445,14 +488,11 @@ cleanup_module(void) ...@@ -445,14 +488,11 @@ cleanup_module(void)
int this_dev; int this_dev;
for (this_dev = 0; this_dev < MAX_HPP_CARDS; this_dev++) { for (this_dev = 0; this_dev < MAX_HPP_CARDS; this_dev++) {
struct net_device *dev = &dev_hpp[this_dev]; struct net_device *dev = dev_hpp[this_dev];
if (dev->priv != NULL) { if (dev) {
int ioaddr = dev->base_addr - NIC_OFFSET;
void *priv = dev->priv;
/* NB: hpp_close() handles free_irq */
release_region(ioaddr, HP_IO_EXTENT);
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