Commit 5068053f authored by Stephen Hemminger's avatar Stephen Hemminger

[PATCH] (37/42) pamsnet

NE62-pamsnet
	* switched to dynamic allocation
	* fixed resource leaks on failure exits
parent 2858176b
...@@ -79,7 +79,7 @@ extern int sun3lance_probe(struct net_device *); ...@@ -79,7 +79,7 @@ extern int sun3lance_probe(struct net_device *);
extern int sun3_82586_probe(struct net_device *); extern int sun3_82586_probe(struct net_device *);
extern int apne_probe(struct net_device *); extern int apne_probe(struct net_device *);
extern int bionet_probe(struct net_device *); extern int bionet_probe(struct net_device *);
extern int pamsnet_probe(struct net_device *); extern struct net_device *pamsnet_probe(int unit);
extern struct net_device *cs89x0_probe(int unit); extern struct net_device *cs89x0_probe(int unit);
extern struct net_device *hplance_probe(int unit); extern struct net_device *hplance_probe(int unit);
extern struct net_device *bagetlance_probe(int unit); extern struct net_device *bagetlance_probe(int unit);
...@@ -310,14 +310,14 @@ static struct devprobe m68k_probes[] __initdata = { ...@@ -310,14 +310,14 @@ static struct devprobe m68k_probes[] __initdata = {
#endif #endif
#ifdef CONFIG_ATARI_BIONET /* Atari Bionet Ethernet board */ #ifdef CONFIG_ATARI_BIONET /* Atari Bionet Ethernet board */
{bionet_probe, 0}, {bionet_probe, 0},
#endif
#ifdef CONFIG_ATARI_PAMSNET /* Atari PAMsNet Ethernet board */
{pamsnet_probe, 0},
#endif #endif
{NULL, 0}, {NULL, 0},
}; };
static struct devprobe2 m68k_probes2[] __initdata = { static struct devprobe2 m68k_probes2[] __initdata = {
#ifdef CONFIG_ATARI_PAMSNET /* Atari PAMsNet Ethernet board */
{pamsnet_probe, 0},
#endif
#ifdef CONFIG_HPLANCE /* HP300 internal Ethernet */ #ifdef CONFIG_HPLANCE /* HP300 internal Ethernet */
{hplance_probe, 0}, {hplance_probe, 0},
#endif #endif
......
...@@ -158,8 +158,6 @@ static int send_1_5 (int lun, unsigned char *command, int dma); ...@@ -158,8 +158,6 @@ static int send_1_5 (int lun, unsigned char *command, int dma);
static int get_status (void); static int get_status (void);
static int calc_received (void *start_address); static int calc_received (void *start_address);
extern int pamsnet_probe(struct net_device *dev);
static int pamsnet_open(struct net_device *dev); static int pamsnet_open(struct net_device *dev);
static int pamsnet_send_packet(struct sk_buff *skb, struct net_device *dev); static int pamsnet_send_packet(struct sk_buff *skb, struct net_device *dev);
static void pamsnet_poll_rx(struct net_device *); static void pamsnet_poll_rx(struct net_device *);
...@@ -562,12 +560,12 @@ sendpkt (target, buffer, length) ...@@ -562,12 +560,12 @@ sendpkt (target, buffer, length)
/* Check for a network adaptor of this type, and return '0' if one exists. /* Check for a network adaptor of this type, and return '0' if one exists.
*/ */
int __init struct net_device * __init pamsnet_probe (int unit)
pamsnet_probe (dev)
struct net_device *dev;
{ {
struct net_device *dev;
int i; int i;
HADDR *hwaddr; HADDR *hwaddr;
int err;
unsigned char station_addr[6]; unsigned char station_addr[6];
static unsigned version_printed; static unsigned version_printed;
...@@ -575,12 +573,18 @@ pamsnet_probe (dev) ...@@ -575,12 +573,18 @@ pamsnet_probe (dev)
static int no_more_found; static int no_more_found;
if (no_more_found) if (no_more_found)
return -ENODEV; return ERR_PTR(-ENODEV);
no_more_found = 1;
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);
no_more_found = 1;
printk("Probing for PAM's Net/GK Adapter...\n"); printk("Probing for PAM's Net/GK Adapter...\n");
/* Allocate the DMA buffer here since we need it for probing! */ /* Allocate the DMA buffer here since we need it for probing! */
...@@ -618,11 +622,12 @@ pamsnet_probe (dev) ...@@ -618,11 +622,12 @@ pamsnet_probe (dev)
ENABLE_IRQ(); ENABLE_IRQ();
stdma_release(); stdma_release();
if (lance_target < 0) if (lance_target < 0) {
printk("No PAM's Net/GK found.\n"); printk("No PAM's Net/GK found.\n");
free_netdev(dev);
return ERR_PTR(-ENODEV);
}
if ((dev == NULL) || (lance_target < 0))
return -ENODEV;
if (pamsnet_debug > 0 && version_printed++ == 0) if (pamsnet_debug > 0 && version_printed++ == 0)
printk(version); printk(version);
...@@ -632,12 +637,6 @@ pamsnet_probe (dev) ...@@ -632,12 +637,6 @@ pamsnet_probe (dev)
station_addr[3], station_addr[4], station_addr[5]); station_addr[3], station_addr[4], station_addr[5]);
/* Initialize the device structure. */ /* Initialize the 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));
dev->open = pamsnet_open; dev->open = pamsnet_open;
dev->stop = pamsnet_close; dev->stop = pamsnet_close;
dev->hard_start_xmit = pamsnet_send_packet; dev->hard_start_xmit = pamsnet_send_packet;
...@@ -653,9 +652,12 @@ pamsnet_probe (dev) ...@@ -653,9 +652,12 @@ pamsnet_probe (dev)
#endif #endif
dev->dev_addr[i] = station_addr[i]; dev->dev_addr[i] = station_addr[i];
} }
ether_setup(dev); err = register_netdev(dev);
if (!err)
return dev;
return(0); free_netdev(dev);
return ERR_PTR(err);
} }
/* Open/initialize the board. This is called (in the current kernel) /* Open/initialize the board. This is called (in the current kernel)
...@@ -866,25 +868,20 @@ static struct net_device_stats *net_get_stats(struct net_device *dev) ...@@ -866,25 +868,20 @@ static struct net_device_stats *net_get_stats(struct net_device *dev)
#ifdef MODULE #ifdef MODULE
static struct net_device pam_dev; static struct net_device *pam_dev;
int
init_module(void) {
int err;
pam_dev.init = pamsnet_probe; int init_module(void)
if ((err = register_netdev(&pam_dev))) { {
if (err == -EEXIST) { pam_dev = pamsnet_probe(-1);
printk("PAM's Net/GK: devices already present. Module not loaded.\n"); if (IS_ERR(pam_dev))
} return PTR_ERR(pam_dev);
return err;
}
return 0; return 0;
} }
void void cleanup_module(void)
cleanup_module(void) { {
unregister_netdev(&pam_dev); unregister_netdev(pam_dev);
free_netdev(pam_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