Commit f589a15c authored by Stephen Hemminger's avatar Stephen Hemminger

[PATCH] (41/42) sun3_lance

NE67-sun3lance
	* switched to dynamic allocation
	* fixed resource leaks on failure exits
parent e77928f2
...@@ -75,7 +75,7 @@ extern struct net_device *SK_init(int unit); ...@@ -75,7 +75,7 @@ extern struct net_device *SK_init(int unit);
extern struct net_device *seeq8005_probe(int unit); extern struct net_device *seeq8005_probe(int unit);
extern struct net_device *smc_init(int unit); extern struct net_device *smc_init(int unit);
extern int atarilance_probe(struct net_device *); extern int atarilance_probe(struct net_device *);
extern int sun3lance_probe(struct net_device *); extern struct net_device *sun3lance_probe(int unit);
extern struct net_device *sun3_82586_probe(int unit); extern struct net_device *sun3_82586_probe(int unit);
extern struct net_device *apne_probe(int unit); extern struct net_device *apne_probe(int unit);
extern struct net_device *bionet_probe(int unit); extern struct net_device *bionet_probe(int unit);
...@@ -298,14 +298,14 @@ static struct devprobe2 parport_probes[] __initdata = { ...@@ -298,14 +298,14 @@ static struct devprobe2 parport_probes[] __initdata = {
static struct devprobe m68k_probes[] __initdata = { static struct devprobe m68k_probes[] __initdata = {
#ifdef CONFIG_ATARILANCE /* Lance-based Atari ethernet boards */ #ifdef CONFIG_ATARILANCE /* Lance-based Atari ethernet boards */
{atarilance_probe, 0}, {atarilance_probe, 0},
#endif
#ifdef CONFIG_SUN3LANCE /* sun3 onboard Lance chip */
{sun3lance_probe, 0},
#endif #endif
{NULL, 0}, {NULL, 0},
}; };
static struct devprobe2 m68k_probes2[] __initdata = { static struct devprobe2 m68k_probes2[] __initdata = {
#ifdef CONFIG_SUN3LANCE /* sun3 onboard Lance chip */
{sun3lance_probe, 0},
#endif
#ifdef CONFIG_SUN3_82586 /* sun3 onboard Intel 82586 chip */ #ifdef CONFIG_SUN3_82586 /* sun3 onboard Intel 82586 chip */
{sun3_82586_probe, 0}, {sun3_82586_probe, 0},
#endif #endif
......
...@@ -246,9 +246,11 @@ static void set_multicast_list( struct net_device *dev ); ...@@ -246,9 +246,11 @@ static void set_multicast_list( struct net_device *dev );
/************************* End of Prototypes **************************/ /************************* End of Prototypes **************************/
int __init sun3lance_probe( struct net_device *dev ) struct net_device * __init sun3lance_probe(int unit)
{ {
struct net_device *dev;
static int found; static int found;
int err = -ENODEV;
/* check that this machine has an onboard lance */ /* check that this machine has an onboard lance */
switch(idprom->id_machtype) { switch(idprom->id_machtype) {
...@@ -259,18 +261,37 @@ int __init sun3lance_probe( struct net_device *dev ) ...@@ -259,18 +261,37 @@ int __init sun3lance_probe( struct net_device *dev )
break; break;
default: default:
return(-ENODEV); return ERR_PTR(-ENODEV);
} }
if(found) if (found)
return(-ENODEV); return ERR_PTR(-ENODEV);
if (lance_probe(dev)) { dev = alloc_etherdev(sizeof(struct lance_private));
found = 1; if (!dev)
return( 0 ); return ERR_PTR(-ENOMEM);
if (unit >= 0) {
sprintf(dev->name, "eth%d", unit);
netdev_boot_setup_check(dev);
} }
SET_MODULE_OWNER(dev);
if (!lance_probe(dev))
goto out;
return( -ENODEV ); err = register_netdev(dev);
if (err)
goto out1;
found = 1;
return dev;
out1:
#ifdef CONFIG_SUN3
iounmap(dev->base_addr);
#endif
out:
free_netdev(dev);
return ERR_PTR(err);
} }
static int __init lance_probe( struct net_device *dev) static int __init lance_probe( struct net_device *dev)
...@@ -285,6 +306,8 @@ static int __init lance_probe( struct net_device *dev) ...@@ -285,6 +306,8 @@ static int __init lance_probe( struct net_device *dev)
#ifdef CONFIG_SUN3 #ifdef CONFIG_SUN3
ioaddr = (unsigned long)ioremap(LANCE_OBIO, PAGE_SIZE); ioaddr = (unsigned long)ioremap(LANCE_OBIO, PAGE_SIZE);
if (!ioaddr)
return 0;
#else #else
ioaddr = SUN3X_LANCE; ioaddr = SUN3X_LANCE;
#endif #endif
...@@ -303,17 +326,15 @@ static int __init lance_probe( struct net_device *dev) ...@@ -303,17 +326,15 @@ static int __init lance_probe( struct net_device *dev)
ioaddr_probe[0] = tmp1; ioaddr_probe[0] = tmp1;
ioaddr_probe[1] = tmp2; ioaddr_probe[1] = tmp2;
#ifdef CONFIG_SUN3
iounmap(ioaddr);
#endif
return 0; return 0;
} }
init_etherdev( dev, sizeof(struct lance_private) );
if (!dev->priv) {
dev->priv = kmalloc( sizeof(struct lance_private), GFP_KERNEL );
if (!dev->priv)
return 0;
}
lp = (struct lance_private *)dev->priv; lp = (struct lance_private *)dev->priv;
/* XXX - leak? */
MEM = dvma_malloc_align(sizeof(struct lance_memory), 0x10000); MEM = dvma_malloc_align(sizeof(struct lance_memory), 0x10000);
lp->iobase = (volatile unsigned short *)ioaddr; lp->iobase = (volatile unsigned short *)ioaddr;
...@@ -921,32 +942,24 @@ static void set_multicast_list( struct net_device *dev ) ...@@ -921,32 +942,24 @@ static void set_multicast_list( struct net_device *dev )
#ifdef MODULE #ifdef MODULE
static char devicename[9];
static struct net_device sun3lance_dev = static struct net_device *sun3lance_dev;
{
devicename, /* filled in by register_netdev() */
0, 0, 0, 0, /* memory */
0, 0, /* base, irq */
0, 0, 0, NULL, sun3lance_probe,
};
int init_module(void) int init_module(void)
{ {
int err; sun3lance_dev = sun3lance_probe(-1);
if (IS_ERR(sun3lance_dev))
if ((err = register_netdev( &sun3lance_dev ))) { return PTR_ERR(sun3lance_dev);
if (err == -EIO) { return 0;
printk( "SUN3 Lance not detected. Module not loaded.\n");
}
return( err );
}
return( 0 );
} }
void cleanup_module(void) void cleanup_module(void)
{ {
unregister_netdev( &sun3lance_dev ); unregister_netdev(sun3lance_dev);
#ifdef CONFIG_SUN3
iounmap(sun3lance_dev->base_addr);
#endif
free_netdev(sun3lance_dev);
} }
#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