Commit 72517c81 authored by Stephen Hemminger's avatar Stephen Hemminger

[PATCH] convert plip to alloc_netdev

This converts the parallel network driver to use alloc_netdev instead
of doing it's own allocation.

Tested (load/unload) on 2.5.74
parent f62d3d40
...@@ -277,27 +277,10 @@ inline static unsigned char read_status (struct net_device *dev) ...@@ -277,27 +277,10 @@ inline static unsigned char read_status (struct net_device *dev)
then calls us here. then calls us here.
*/ */
int __init static int
plip_init_dev(struct net_device *dev, struct parport *pb) plip_init_netdev(struct net_device *dev)
{ {
struct net_local *nl; struct net_local *nl = dev->priv;
struct pardevice *pardev;
SET_MODULE_OWNER(dev);
dev->irq = pb->irq;
dev->base_addr = pb->base;
if (pb->irq == -1) {
printk(KERN_INFO "plip: %s has no IRQ. Using IRQ-less mode,"
"which is fairly inefficient!\n", pb->name);
}
pardev = parport_register_device(pb, dev->name, plip_preempt,
plip_wakeup, plip_interrupt,
0, dev);
if (!pardev)
return -ENODEV;
printk(KERN_INFO "%s", version); printk(KERN_INFO "%s", version);
if (dev->irq != -1) if (dev->irq != -1)
...@@ -307,9 +290,6 @@ plip_init_dev(struct net_device *dev, struct parport *pb) ...@@ -307,9 +290,6 @@ plip_init_dev(struct net_device *dev, struct parport *pb)
printk(KERN_INFO "%s: Parallel port at %#3lx, not using IRQ.\n", printk(KERN_INFO "%s: Parallel port at %#3lx, not using IRQ.\n",
dev->name, dev->base_addr); dev->name, dev->base_addr);
/* Fill in the generic fields of the device structure. */
ether_setup(dev);
/* Then, override parts of it */ /* Then, override parts of it */
dev->hard_start_xmit = plip_tx_packet; dev->hard_start_xmit = plip_tx_packet;
dev->open = plip_open; dev->open = plip_open;
...@@ -322,22 +302,12 @@ plip_init_dev(struct net_device *dev, struct parport *pb) ...@@ -322,22 +302,12 @@ plip_init_dev(struct net_device *dev, struct parport *pb)
memset(dev->dev_addr, 0xfc, ETH_ALEN); memset(dev->dev_addr, 0xfc, ETH_ALEN);
/* Set the private structure */ /* Set the private structure */
dev->priv = kmalloc(sizeof (struct net_local), GFP_KERNEL);
if (dev->priv == NULL) {
printk(KERN_ERR "%s: out of memory\n", dev->name);
parport_unregister_device(pardev);
return -ENOMEM;
}
memset(dev->priv, 0, sizeof(struct net_local));
nl = (struct net_local *) dev->priv;
nl->orig_hard_header = dev->hard_header; nl->orig_hard_header = dev->hard_header;
dev->hard_header = plip_hard_header; dev->hard_header = plip_hard_header;
nl->orig_hard_header_cache = dev->hard_header_cache; nl->orig_hard_header_cache = dev->hard_header_cache;
dev->hard_header_cache = plip_hard_header_cache; dev->hard_header_cache = plip_hard_header_cache;
nl->pardev = pardev;
nl->port_owner = 0; nl->port_owner = 0;
...@@ -1299,29 +1269,52 @@ plip_searchfor(int list[], int a) ...@@ -1299,29 +1269,52 @@ plip_searchfor(int list[], int a)
* available to use. */ * available to use. */
static void plip_attach (struct parport *port) static void plip_attach (struct parport *port)
{ {
static int i; static int unit;
struct net_device *dev;
struct net_local *nl;
char name[IFNAMSIZ];
if ((parport[0] == -1 && (!timid || !port->devices)) || if ((parport[0] == -1 && (!timid || !port->devices)) ||
plip_searchfor(parport, port->number)) { plip_searchfor(parport, port->number)) {
if (i == PLIP_MAX) { if (unit == PLIP_MAX) {
printk(KERN_ERR "plip: too many devices\n"); printk(KERN_ERR "plip: too many devices\n");
return; return;
} }
dev_plip[i] = kmalloc(sizeof(struct net_device),
GFP_KERNEL); sprintf(name, "plip%d", unit);
if (!dev_plip[i]) { dev = alloc_netdev(sizeof(struct net_local), name,
ether_setup);
if (!dev) {
printk(KERN_ERR "plip: memory squeeze\n"); printk(KERN_ERR "plip: memory squeeze\n");
return; return;
} }
memset(dev_plip[i], 0, sizeof(struct net_device));
sprintf(dev_plip[i]->name, "plip%d", i); dev->init = plip_init_netdev;
dev_plip[i]->priv = port;
if (plip_init_dev(dev_plip[i],port) || SET_MODULE_OWNER(dev);
register_netdev(dev_plip[i])) { dev->irq = port->irq;
kfree(dev_plip[i]); dev->base_addr = port->base;
dev_plip[i] = NULL; if (port->irq == -1) {
printk(KERN_INFO "plip: %s has no IRQ. Using IRQ-less mode,"
"which is fairly inefficient!\n", port->name);
}
nl = dev->priv;
nl->pardev = parport_register_device(port, name, plip_preempt,
plip_wakeup, plip_interrupt,
0, dev);
if (!nl->pardev) {
printk(KERN_ERR "%s: parport_register failed\n", name);
kfree(dev);
return;
}
if (register_netdev(dev)) {
printk(KERN_ERR "%s: network register failed\n", name);
kfree(dev);
} else { } else {
i++; dev_plip[unit++] = dev;
} }
} }
} }
...@@ -1341,20 +1334,19 @@ static struct parport_driver plip_driver = { ...@@ -1341,20 +1334,19 @@ static struct parport_driver plip_driver = {
static void __exit plip_cleanup_module (void) static void __exit plip_cleanup_module (void)
{ {
struct net_device *dev;
int i; int i;
parport_unregister_driver (&plip_driver); parport_unregister_driver (&plip_driver);
for (i=0; i < PLIP_MAX; i++) { for (i=0; i < PLIP_MAX; i++) {
if (dev_plip[i]) { if ((dev = dev_plip[i])) {
struct net_local *nl = struct net_local *nl = dev->priv;
(struct net_local *)dev_plip[i]->priv; unregister_netdev(dev);
unregister_netdev(dev_plip[i]);
if (nl->port_owner) if (nl->port_owner)
parport_release(nl->pardev); parport_release(nl->pardev);
parport_unregister_device(nl->pardev); parport_unregister_device(nl->pardev);
kfree(dev_plip[i]->priv); kfree(dev);
kfree(dev_plip[i]);
dev_plip[i] = NULL; dev_plip[i] = NULL;
} }
} }
......
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