]> err.no Git - linux-2.6/blobdiff - drivers/net/wan/cosa.c
Merge branch 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4
[linux-2.6] / drivers / net / wan / cosa.c
index 1d706eae30526003183555c0f897cc9f2e30fea9..5827324e9d9f94a2abde26a450c1b4be90c941cf 100644 (file)
@@ -90,7 +90,9 @@
 #include <linux/ioport.h>
 #include <linux/netdevice.h>
 #include <linux/spinlock.h>
+#include <linux/mutex.h>
 #include <linux/device.h>
+#include <linux/smp_lock.h>
 
 #undef COSA_SLOW_IO    /* for testing purposes only */
 
@@ -127,7 +129,8 @@ struct channel_data {
        int (*tx_done)(struct channel_data *channel, int size);
 
        /* Character device parts */
-       struct semaphore rsem, wsem;
+       struct mutex rlock;
+       struct semaphore wsem;
        char *rxdata;
        int rxsize;
        wait_queue_head_t txwaitq, rxwaitq;
@@ -627,7 +630,7 @@ static void sppp_channel_init(struct channel_data *chan)
        d->base_addr = chan->cosa->datareg;
        d->irq = chan->cosa->irq;
        d->dma = chan->cosa->dma;
-       d->priv = chan;
+       d->ml_priv = chan;
        sppp_attach(&chan->pppdev);
        if (register_netdev(d)) {
                printk(KERN_WARNING "%s: register_netdev failed.\n", d->name);
@@ -648,7 +651,7 @@ static void sppp_channel_delete(struct channel_data *chan)
 
 static int cosa_sppp_open(struct net_device *d)
 {
-       struct channel_data *chan = d->priv;
+       struct channel_data *chan = d->ml_priv;
        int err;
        unsigned long flags;
 
@@ -688,7 +691,7 @@ static int cosa_sppp_open(struct net_device *d)
 
 static int cosa_sppp_tx(struct sk_buff *skb, struct net_device *dev)
 {
-       struct channel_data *chan = dev->priv;
+       struct channel_data *chan = dev->ml_priv;
 
        netif_stop_queue(dev);
 
@@ -699,7 +702,7 @@ static int cosa_sppp_tx(struct sk_buff *skb, struct net_device *dev)
 
 static void cosa_sppp_timeout(struct net_device *dev)
 {
-       struct channel_data *chan = dev->priv;
+       struct channel_data *chan = dev->ml_priv;
 
        if (test_bit(RXBIT, &chan->cosa->rxtx)) {
                chan->stats.rx_errors++;
@@ -718,7 +721,7 @@ static void cosa_sppp_timeout(struct net_device *dev)
 
 static int cosa_sppp_close(struct net_device *d)
 {
-       struct channel_data *chan = d->priv;
+       struct channel_data *chan = d->ml_priv;
        unsigned long flags;
 
        netif_stop_queue(d);
@@ -798,7 +801,7 @@ static int sppp_tx_done(struct channel_data *chan, int size)
 
 static struct net_device_stats *cosa_net_stats(struct net_device *dev)
 {
-       struct channel_data *chan = dev->priv;
+       struct channel_data *chan = dev->ml_priv;
        return &chan->stats;
 }
 
@@ -807,7 +810,7 @@ static struct net_device_stats *cosa_net_stats(struct net_device *dev)
 
 static void chardev_channel_init(struct channel_data *chan)
 {
-       init_MUTEX(&chan->rsem);
+       mutex_init(&chan->rlock);
        init_MUTEX(&chan->wsem);
 }
 
@@ -825,12 +828,12 @@ static ssize_t cosa_read(struct file *file,
                        cosa->name, cosa->firmware_status);
                return -EPERM;
        }
-       if (down_interruptible(&chan->rsem))
+       if (mutex_lock_interruptible(&chan->rlock))
                return -ERESTARTSYS;
        
        if ((chan->rxdata = kmalloc(COSA_MTU, GFP_DMA|GFP_KERNEL)) == NULL) {
                printk(KERN_INFO "%s: cosa_read() - OOM\n", cosa->name);
-               up(&chan->rsem);
+               mutex_unlock(&chan->rlock);
                return -ENOMEM;
        }
 
@@ -848,7 +851,7 @@ static ssize_t cosa_read(struct file *file,
                        remove_wait_queue(&chan->rxwaitq, &wait);
                        current->state = TASK_RUNNING;
                        spin_unlock_irqrestore(&cosa->lock, flags);
-                       up(&chan->rsem);
+                       mutex_unlock(&chan->rlock);
                        return -ERESTARTSYS;
                }
        }
@@ -857,7 +860,7 @@ static ssize_t cosa_read(struct file *file,
        kbuf = chan->rxdata;
        count = chan->rxsize;
        spin_unlock_irqrestore(&cosa->lock, flags);
-       up(&chan->rsem);
+       mutex_unlock(&chan->rlock);
 
        if (copy_to_user(buf, kbuf, count)) {
                kfree(kbuf);
@@ -968,15 +971,21 @@ static int cosa_open(struct inode *inode, struct file *file)
        struct channel_data *chan;
        unsigned long flags;
        int n;
+       int ret = 0;
 
+       lock_kernel();
        if ((n=iminor(file->f_path.dentry->d_inode)>>CARD_MINOR_BITS)
-               >= nr_cards)
-               return -ENODEV;
+               >= nr_cards) {
+               ret = -ENODEV;
+               goto out;
+       }
        cosa = cosa_cards+n;
 
        if ((n=iminor(file->f_path.dentry->d_inode)
-               & ((1<<CARD_MINOR_BITS)-1)) >= cosa->nchannels)
-               return -ENODEV;
+               & ((1<<CARD_MINOR_BITS)-1)) >= cosa->nchannels) {
+               ret = -ENODEV;
+               goto out;
+       }
        chan = cosa->chan + n;
        
        file->private_data = chan;
@@ -985,7 +994,8 @@ static int cosa_open(struct inode *inode, struct file *file)
 
        if (chan->usage < 0) { /* in netdev mode */
                spin_unlock_irqrestore(&cosa->lock, flags);
-               return -EBUSY;
+               ret = -EBUSY;
+               goto out;
        }
        cosa->usage++;
        chan->usage++;
@@ -994,7 +1004,9 @@ static int cosa_open(struct inode *inode, struct file *file)
        chan->setup_rx = chrdev_setup_rx;
        chan->rx_done = chrdev_rx_done;
        spin_unlock_irqrestore(&cosa->lock, flags);
-       return 0;
+out:
+       unlock_kernel();
+       return ret;
 }
 
 static int cosa_release(struct inode *inode, struct file *file)
@@ -1215,7 +1227,7 @@ static int cosa_sppp_ioctl(struct net_device *dev, struct ifreq *ifr,
        int cmd)
 {
        int rv;
-       struct channel_data *chan = dev->priv;
+       struct channel_data *chan = dev->ml_priv;
        rv = cosa_ioctl_common(chan->cosa, chan, cmd, (unsigned long)ifr->ifr_data);
        if (rv == -ENOIOCTLCMD) {
                return sppp_do_ioctl(dev, ifr, cmd);