Commit 9e569c9a authored by Stephen Hemminger's avatar Stephen Hemminger

[IrDA] via-ircc -- dev_alloc cleanout

Convert via-ircc 2.6.0-test5
	- use alloc_net_dev not dev_alloc
	- allocate private data at same time
	- cleanup error unwinds
	- call free_netdev.

Builds and loads, but don't have real hardware.
parent a30fff7c
...@@ -94,7 +94,6 @@ static irqreturn_t via_ircc_interrupt(int irq, void *dev_id, ...@@ -94,7 +94,6 @@ static irqreturn_t via_ircc_interrupt(int irq, void *dev_id,
static int via_ircc_is_receiving(struct via_ircc_cb *self); static int via_ircc_is_receiving(struct via_ircc_cb *self);
static int via_ircc_read_dongle_id(int iobase); static int via_ircc_read_dongle_id(int iobase);
static int via_ircc_net_init(struct net_device *dev);
static int via_ircc_net_open(struct net_device *dev); static int via_ircc_net_open(struct net_device *dev);
static int via_ircc_net_close(struct net_device *dev); static int via_ircc_net_close(struct net_device *dev);
static int via_ircc_net_ioctl(struct net_device *dev, struct ifreq *rq, static int via_ircc_net_ioctl(struct net_device *dev, struct ifreq *rq,
...@@ -330,18 +329,19 @@ static __devinit int via_ircc_open(int i, chipio_t * info, unsigned int id) ...@@ -330,18 +329,19 @@ static __devinit int via_ircc_open(int i, chipio_t * info, unsigned int id)
{ {
struct net_device *dev; struct net_device *dev;
struct via_ircc_cb *self; struct via_ircc_cb *self;
int ret;
int err; int err;
if ((via_ircc_setup(info, id)) == -1) if ((via_ircc_setup(info, id)) == -1)
return -1; return -1;
/* Allocate new instance of the driver */ /* Allocate new instance of the driver */
self = kmalloc(sizeof(struct via_ircc_cb), GFP_KERNEL); dev = alloc_netdev(sizeof(struct via_ircc_cb), "irda%d",
if (self == NULL) { irda_device_setup);
if (dev == NULL)
return -ENOMEM; return -ENOMEM;
}
memset(self, 0, sizeof(struct via_ircc_cb)); self = dev->priv;
self->netdev = dev;
spin_lock_init(&self->lock); spin_lock_init(&self->lock);
/* Need to store self somewhere */ /* Need to store self somewhere */
...@@ -360,14 +360,12 @@ static __devinit int via_ircc_open(int i, chipio_t * info, unsigned int id) ...@@ -360,14 +360,12 @@ static __devinit int via_ircc_open(int i, chipio_t * info, unsigned int id)
self->RxDataReady = 0; self->RxDataReady = 0;
/* Reserve the ioports that we need */ /* Reserve the ioports that we need */
ret = check_region(self->io.fir_base, self->io.fir_ext); if (!request_region(self->io.fir_base, self->io.fir_ext, driver_name)) {
if (ret < 0) {
// WARNING(__FUNCTION__ "(), can't get iobase of 0x%03x\n",self->io.fir_base); // WARNING(__FUNCTION__ "(), can't get iobase of 0x%03x\n",self->io.fir_base);
dev_self[i] = NULL; err = -ENODEV;
kfree(self); goto err_out1;
return -ENODEV;
} }
request_region(self->io.fir_base, self->io.fir_ext, driver_name);
/* Initialize QoS for this device */ /* Initialize QoS for this device */
irda_init_max_qos_capabilies(&self->qos); irda_init_max_qos_capabilies(&self->qos);
/* The only value we must override it the baudrate */ /* The only value we must override it the baudrate */
...@@ -391,17 +389,16 @@ static __devinit int via_ircc_open(int i, chipio_t * info, unsigned int id) ...@@ -391,17 +389,16 @@ static __devinit int via_ircc_open(int i, chipio_t * info, unsigned int id)
self->rx_buff.head = self->rx_buff.head =
(__u8 *) kmalloc(self->rx_buff.truesize, GFP_KERNEL | GFP_DMA); (__u8 *) kmalloc(self->rx_buff.truesize, GFP_KERNEL | GFP_DMA);
if (self->rx_buff.head == NULL) { if (self->rx_buff.head == NULL) {
kfree(self); err = -ENOMEM;
return -ENOMEM; goto err_out2;
} }
memset(self->rx_buff.head, 0, self->rx_buff.truesize); memset(self->rx_buff.head, 0, self->rx_buff.truesize);
self->tx_buff.head = self->tx_buff.head =
(__u8 *) kmalloc(self->tx_buff.truesize, GFP_KERNEL | GFP_DMA); (__u8 *) kmalloc(self->tx_buff.truesize, GFP_KERNEL | GFP_DMA);
if (self->tx_buff.head == NULL) { if (self->tx_buff.head == NULL) {
kfree(self->rx_buff.head); err = -ENOMEM;
kfree(self); goto err_out3;
return -ENOMEM;
} }
memset(self->tx_buff.head, 0, self->tx_buff.truesize); memset(self->tx_buff.head, 0, self->tx_buff.truesize);
...@@ -414,30 +411,20 @@ static __devinit int via_ircc_open(int i, chipio_t * info, unsigned int id) ...@@ -414,30 +411,20 @@ static __devinit int via_ircc_open(int i, chipio_t * info, unsigned int id)
self->tx_fifo.len = self->tx_fifo.ptr = self->tx_fifo.free = 0; self->tx_fifo.len = self->tx_fifo.ptr = self->tx_fifo.free = 0;
self->tx_fifo.tail = self->tx_buff.head; self->tx_fifo.tail = self->tx_buff.head;
if (!(dev = dev_alloc("irda%d", &err))) { /* Keep track of module usage */
kfree(self->tx_buff.head); SET_MODULE_OWNER(dev);
kfree(self->rx_buff.head);
kfree(self);
return -ENOMEM;
}
dev->priv = (void *) self;
self->netdev = dev;
/* Override the network functions we need to use */ /* Override the network functions we need to use */
dev->init = via_ircc_net_init;
dev->hard_start_xmit = via_ircc_hard_xmit_sir; dev->hard_start_xmit = via_ircc_hard_xmit_sir;
dev->open = via_ircc_net_open; dev->open = via_ircc_net_open;
dev->stop = via_ircc_net_close; dev->stop = via_ircc_net_close;
dev->do_ioctl = via_ircc_net_ioctl; dev->do_ioctl = via_ircc_net_ioctl;
dev->get_stats = via_ircc_net_get_stats; dev->get_stats = via_ircc_net_get_stats;
rtnl_lock(); err = register_netdev(dev);
err = register_netdevice(dev); if (err)
rtnl_unlock(); goto err_out4;
if (err) {
return -1;
}
MESSAGE("IrDA: Registered device %s\n", dev->name); MESSAGE("IrDA: Registered device %s\n", dev->name);
/* Check if user has supplied the dongle id or not */ /* Check if user has supplied the dongle id or not */
...@@ -448,6 +435,16 @@ static __devinit int via_ircc_open(int i, chipio_t * info, unsigned int id) ...@@ -448,6 +435,16 @@ static __devinit int via_ircc_open(int i, chipio_t * info, unsigned int id)
self->io.dongle_id); self->io.dongle_id);
return 0; return 0;
err_out4:
kfree(self->tx_buff.head);
err_out3:
kfree(self->rx_buff.head);
err_out2:
release_region(self->io.fir_base, self->io.fir_ext);
err_out1:
free_netdev(dev);
dev_self[i] = NULL;
return err;
} }
/* /*
...@@ -468,11 +465,7 @@ static int __exit via_ircc_close(struct via_ircc_cb *self) ...@@ -468,11 +465,7 @@ static int __exit via_ircc_close(struct via_ircc_cb *self)
ResetChip(iobase, 5); //hardware reset. ResetChip(iobase, 5); //hardware reset.
/* Remove netdevice */ /* Remove netdevice */
if (self->netdev) { unregister_netdev(self->netdev);
rtnl_lock();
unregister_netdevice(self->netdev);
rtnl_unlock();
}
/* Release the PORT that this driver is using */ /* Release the PORT that this driver is using */
IRDA_DEBUG(4, "%s(), Releasing Region %03x\n", IRDA_DEBUG(4, "%s(), Releasing Region %03x\n",
...@@ -483,7 +476,8 @@ static int __exit via_ircc_close(struct via_ircc_cb *self) ...@@ -483,7 +476,8 @@ static int __exit via_ircc_close(struct via_ircc_cb *self)
if (self->rx_buff.head) if (self->rx_buff.head)
kfree(self->rx_buff.head); kfree(self->rx_buff.head);
dev_self[self->index] = NULL; dev_self[self->index] = NULL;
kfree(self);
free_netdev(self->netdev);
return 0; return 0;
} }
...@@ -1456,26 +1450,6 @@ static int via_ircc_is_receiving(struct via_ircc_cb *self) ...@@ -1456,26 +1450,6 @@ static int via_ircc_is_receiving(struct via_ircc_cb *self)
return status; return status;
} }
/*
* Function via_ircc_net_init (dev)
*
* Initialize network device
*
*/
static int via_ircc_net_init(struct net_device *dev)
{
IRDA_DEBUG(4, "%s()\n", __FUNCTION__);
/* Keep track of module usage */
SET_MODULE_OWNER(dev);
/* Setup to be a normal IrDA network device driver */
irda_device_setup(dev);
/* Insert overrides below this line! */
return 0;
}
/* /*
* Function via_ircc_net_open (dev) * Function via_ircc_net_open (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