Commit 43ba5fc8 authored by Stephen Hemminger's avatar Stephen Hemminger

[PATCH] (11/12) Probe2 -- 3c501

>From viro NE22-3c501
	* switched 3c501 to dynamic allocation
	* 3c501: embedded ->priv
	* 3c501: fixed clobbering on autoprobe
	* 3c501: fixed resource leaks on failure exits
Additional:
	* probe correctly when no device present
	* fix loop forever bug in probing
	* free_netdev
parent 80c883a4
...@@ -136,17 +136,14 @@ static const char version[] = ...@@ -136,17 +136,14 @@ static const char version[] =
#include "3c501.h" #include "3c501.h"
/* A zero-terminated list of I/O addresses to be probed.
The 3c501 can be at many locations, but here are the popular ones. */
static unsigned int netcard_portlist[] __initdata = {
0x280, 0x300, 0
};
/* /*
* The boilerplate probe code. * The boilerplate probe code.
*/ */
static int io=0x280;
static int irq=5;
static int mem_start;
/** /**
* el1_probe: - probe for a 3c501 * el1_probe: - probe for a 3c501
* @dev: The device structure passed in to probe. * @dev: The device structure passed in to probe.
...@@ -160,23 +157,47 @@ static unsigned int netcard_portlist[] __initdata = { ...@@ -160,23 +157,47 @@ static unsigned int netcard_portlist[] __initdata = {
* probe and failing to find anything. * probe and failing to find anything.
*/ */
int __init el1_probe(struct net_device *dev) struct net_device * __init el1_probe(int unit)
{ {
int i; struct net_device *dev = alloc_etherdev(sizeof(struct net_local));
int base_addr = dev->base_addr; static unsigned ports[] = { 0x280, 0x300, 0};
unsigned *port;
int err = 0;
if (!dev)
return ERR_PTR(-ENOMEM);
if (unit >= 0) {
sprintf(dev->name, "eth%d", unit);
netdev_boot_setup_check(dev);
io = dev->base_addr;
irq = dev->irq;
mem_start = dev->mem_start & 7;
}
SET_MODULE_OWNER(dev); SET_MODULE_OWNER(dev);
if (base_addr > 0x1ff) /* Check a single specified location. */ if (io > 0x1ff) { /* Check a single specified location. */
return el1_probe1(dev, base_addr); err = el1_probe1(dev, io);
else if (base_addr != 0) /* Don't probe at all. */ } else if (io != 0) {
return -ENXIO; err = -ENXIO; /* Don't probe at all. */
} else {
for (i = 0; netcard_portlist[i]; i++) for (port = ports; *port && el1_probe1(dev, *port); port++)
if (el1_probe1(dev, netcard_portlist[i]) == 0) ;
return 0; if (!*port)
err = -ENODEV;
return -ENODEV; }
if (err)
goto out;
err = register_netdev(dev);
if (err)
goto out1;
return dev;
out1:
release_region(dev->base_addr, EL1_IO_EXTENT);
out:
free_netdev(dev);
return ERR_PTR(err);
} }
/** /**
...@@ -240,6 +261,8 @@ static int __init el1_probe1(struct net_device *dev, int ioaddr) ...@@ -240,6 +261,8 @@ static int __init el1_probe1(struct net_device *dev, int ioaddr)
* high. * high.
*/ */
dev->irq = irq;
if (dev->irq < 2) if (dev->irq < 2)
{ {
unsigned long irq_mask; unsigned long irq_mask;
...@@ -267,8 +290,8 @@ static int __init el1_probe1(struct net_device *dev, int ioaddr) ...@@ -267,8 +290,8 @@ static int __init el1_probe1(struct net_device *dev, int ioaddr)
dev->base_addr = ioaddr; dev->base_addr = ioaddr;
memcpy(dev->dev_addr, station_addr, ETH_ALEN); memcpy(dev->dev_addr, station_addr, ETH_ALEN);
if (dev->mem_start & 0xf) if (mem_start & 0xf)
el_debug = dev->mem_start & 0x7; el_debug = mem_start & 0x7;
if (autoirq) if (autoirq)
dev->irq = autoirq; dev->irq = autoirq;
...@@ -282,17 +305,7 @@ static int __init el1_probe1(struct net_device *dev, int ioaddr) ...@@ -282,17 +305,7 @@ static int __init el1_probe1(struct net_device *dev, int ioaddr)
if (el_debug) if (el_debug)
printk(KERN_DEBUG "%s", version); printk(KERN_DEBUG "%s", version);
/*
* Initialize the device structure.
*/
dev->priv = kmalloc(sizeof(struct net_local), GFP_KERNEL);
if (dev->priv == NULL) {
release_region(ioaddr, EL1_IO_EXTENT);
return -ENOMEM;
}
memset(dev->priv, 0, sizeof(struct net_local)); memset(dev->priv, 0, sizeof(struct net_local));
lp=dev->priv; lp=dev->priv;
spin_lock_init(&lp->lock); spin_lock_init(&lp->lock);
...@@ -308,13 +321,6 @@ static int __init el1_probe1(struct net_device *dev, int ioaddr) ...@@ -308,13 +321,6 @@ static int __init el1_probe1(struct net_device *dev, int ioaddr)
dev->get_stats = &el1_get_stats; dev->get_stats = &el1_get_stats;
dev->set_multicast_list = &set_multicast_list; dev->set_multicast_list = &set_multicast_list;
dev->ethtool_ops = &netdev_ethtool_ops; dev->ethtool_ops = &netdev_ethtool_ops;
/*
* Setup the generic properties
*/
ether_setup(dev);
return 0; return 0;
} }
...@@ -884,14 +890,8 @@ static struct ethtool_ops netdev_ethtool_ops = { ...@@ -884,14 +890,8 @@ static struct ethtool_ops netdev_ethtool_ops = {
#ifdef MODULE #ifdef MODULE
static struct net_device dev_3c501 = { static struct net_device *dev_3c501;
.init = el1_probe,
.base_addr = 0x280,
.irq = 5,
};
static int io=0x280;
static int irq=5;
MODULE_PARM(io, "i"); MODULE_PARM(io, "i");
MODULE_PARM(irq, "i"); MODULE_PARM(irq, "i");
MODULE_PARM_DESC(io, "EtherLink I/O base address"); MODULE_PARM_DESC(io, "EtherLink I/O base address");
...@@ -911,10 +911,9 @@ MODULE_PARM_DESC(irq, "EtherLink IRQ number"); ...@@ -911,10 +911,9 @@ MODULE_PARM_DESC(irq, "EtherLink IRQ number");
int init_module(void) int init_module(void)
{ {
dev_3c501.irq=irq; dev_3c501 = el1_probe(-1);
dev_3c501.base_addr=io; if (IS_ERR(dev_3c501))
if (register_netdev(&dev_3c501) != 0) return PTR_ERR(dev_3c501);
return -EIO;
return 0; return 0;
} }
...@@ -927,19 +926,10 @@ int init_module(void) ...@@ -927,19 +926,10 @@ int init_module(void)
void cleanup_module(void) void cleanup_module(void)
{ {
unregister_netdev(&dev_3c501); struct net_device *dev = dev_3c501;
unregister_netdev(dev);
/* release_region(dev->base_addr, EL1_IO_EXTENT);
* Free up the private structure, or leak memory :-) free_netdev(dev);
*/
kfree(dev_3c501.priv);
dev_3c501.priv = NULL; /* gets re-allocated by el1_probe1 */
/*
* If we don't do this, we can't re-insmod it later.
*/
release_region(dev_3c501.base_addr, EL1_IO_EXTENT);
} }
#endif /* MODULE */ #endif /* MODULE */
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
* Index to functions. * Index to functions.
*/ */
int el1_probe(struct net_device *dev);
static int el1_probe1(struct net_device *dev, int ioaddr); static int el1_probe1(struct net_device *dev, int ioaddr);
static int el_open(struct net_device *dev); static int el_open(struct net_device *dev);
static void el_timeout(struct net_device *dev); static void el_timeout(struct net_device *dev);
......
...@@ -57,7 +57,7 @@ extern int fmv18x_probe(struct net_device *); ...@@ -57,7 +57,7 @@ extern int fmv18x_probe(struct net_device *);
extern int eth16i_probe(struct net_device *); extern int eth16i_probe(struct net_device *);
extern int i82596_probe(struct net_device *); extern int i82596_probe(struct net_device *);
extern int ewrk3_probe(struct net_device *); extern int ewrk3_probe(struct net_device *);
extern int el1_probe(struct net_device *); extern struct net_device *el1_probe(int unit);
extern struct net_device *wavelan_probe(int unit); extern struct net_device *wavelan_probe(int unit);
extern struct net_device *arlan_probe(int unit); extern struct net_device *arlan_probe(int unit);
extern struct net_device *el16_probe(int unit); extern struct net_device *el16_probe(int unit);
...@@ -261,14 +261,14 @@ static struct devprobe isa_probes[] __initdata = { ...@@ -261,14 +261,14 @@ static struct devprobe isa_probes[] __initdata = {
#endif #endif
#if defined(CONFIG_APRICOT) || defined(CONFIG_MVME16x_NET) || defined(CONFIG_BVME6000_NET) /* Intel I82596 */ #if defined(CONFIG_APRICOT) || defined(CONFIG_MVME16x_NET) || defined(CONFIG_BVME6000_NET) /* Intel I82596 */
{i82596_probe, 0}, {i82596_probe, 0},
#endif
#ifdef CONFIG_EL1 /* 3c501 */
{el1_probe, 0},
#endif #endif
{NULL, 0}, {NULL, 0},
}; };
static struct devprobe2 isa_probes2[] __initdata = { static struct devprobe2 isa_probes2[] __initdata = {
#ifdef CONFIG_EL1 /* 3c501 */
{el1_probe, 0},
#endif
#ifdef CONFIG_WAVELAN /* WaveLAN */ #ifdef CONFIG_WAVELAN /* WaveLAN */
{wavelan_probe, 0}, {wavelan_probe, 0},
#endif #endif
......
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