fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / drivers / isdn / capi / capi.c
index 623adbb..d22c022 100644 (file)
@@ -9,7 +9,6 @@
  *
  */
 
-#include <linux/config.h>
 #include <linux/module.h>
 #include <linux/errno.h>
 #include <linux/kernel.h>
@@ -39,7 +38,6 @@
 #include <linux/init.h>
 #include <linux/device.h>
 #include <linux/moduleparam.h>
-#include <linux/devfs_fs_kernel.h>
 #include <linux/isdn/capiutil.h>
 #include <linux/isdn/capicmd.h>
 #if defined(CONFIG_ISDN_CAPI_CAPIFS) || defined(CONFIG_ISDN_CAPI_CAPIFS_MODULE)
@@ -87,6 +85,11 @@ struct capincci;
 #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
 struct capiminor;
 
+struct datahandle_queue {
+       struct list_head        list;
+       u16                     datahandle;
+};
+
 struct capiminor {
        struct list_head list;
        struct capincci  *nccip;
@@ -109,12 +112,9 @@ struct capiminor {
        int                 outbytes;
 
        /* transmit path */
-       struct datahandle_queue {
-                   struct datahandle_queue *next;
-                   u16                    datahandle;
-       } *ackqueue;
+       struct list_head ackqueue;
        int nack;
-
+       spinlock_t ackqlock;
 };
 #endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
 
@@ -156,48 +156,54 @@ static LIST_HEAD(capiminor_list);
 
 static int capincci_add_ack(struct capiminor *mp, u16 datahandle)
 {
-       struct datahandle_queue *n, **pp;
+       struct datahandle_queue *n;
+       unsigned long flags;
 
        n = kmalloc(sizeof(*n), GFP_ATOMIC);
-       if (!n) {
-          printk(KERN_ERR "capi: alloc datahandle failed\n");
-          return -1;
+       if (unlikely(!n)) {
+               printk(KERN_ERR "capi: alloc datahandle failed\n");
+               return -1;
        }
-       n->next = NULL;
        n->datahandle = datahandle;
-       for (pp = &mp->ackqueue; *pp; pp = &(*pp)->next) ;
-       *pp = n;
+       INIT_LIST_HEAD(&n->list);
+       spin_lock_irqsave(&mp->ackqlock, flags);
+       list_add_tail(&n->list, &mp->ackqueue);
        mp->nack++;
+       spin_unlock_irqrestore(&mp->ackqlock, flags);
        return 0;
 }
 
 static int capiminor_del_ack(struct capiminor *mp, u16 datahandle)
 {
-       struct datahandle_queue **pp, *p;
+       struct datahandle_queue *p, *tmp;
+       unsigned long flags;
 
-       for (pp = &mp->ackqueue; *pp; pp = &(*pp)->next) {
-               if ((*pp)->datahandle == datahandle) {
-                       p = *pp;
-                       *pp = (*pp)->next;
+       spin_lock_irqsave(&mp->ackqlock, flags);
+       list_for_each_entry_safe(p, tmp, &mp->ackqueue, list) {
+               if (p->datahandle == datahandle) {
+                       list_del(&p->list);
                        kfree(p);
                        mp->nack--;
+                       spin_unlock_irqrestore(&mp->ackqlock, flags);
                        return 0;
                }
        }
+       spin_unlock_irqrestore(&mp->ackqlock, flags);
        return -1;
 }
 
 static void capiminor_del_all_ack(struct capiminor *mp)
 {
-       struct datahandle_queue **pp, *p;
+       struct datahandle_queue *p, *tmp;
+       unsigned long flags;
 
-       pp = &mp->ackqueue;
-       while (*pp) {
-               p = *pp;
-               *pp = (*pp)->next;
+       spin_lock_irqsave(&mp->ackqlock, flags);
+       list_for_each_entry_safe(p, tmp, &mp->ackqueue, list) {
+               list_del(&p->list);
                kfree(p);
                mp->nack--;
        }
+       spin_unlock_irqrestore(&mp->ackqlock, flags);
 }
 
 
@@ -209,17 +215,18 @@ static struct capiminor *capiminor_alloc(struct capi20_appl *ap, u32 ncci)
        unsigned int minor = 0;
        unsigned long flags;
 
-       mp = kmalloc(sizeof(*mp), GFP_ATOMIC);
+       mp = kzalloc(sizeof(*mp), GFP_ATOMIC);
        if (!mp) {
                printk(KERN_ERR "capi: can't alloc capiminor\n");
                return NULL;
        }
 
-       memset(mp, 0, sizeof(struct capiminor));
        mp->ap = ap;
        mp->ncci = ncci;
        mp->msgid = 0;
        atomic_set(&mp->ttyopencount,0);
+       INIT_LIST_HEAD(&mp->ackqueue);
+       spin_lock_init(&mp->ackqlock);
 
        skb_queue_head_init(&mp->inqueue);
        skb_queue_head_init(&mp->outqueue);
@@ -296,10 +303,9 @@ static struct capincci *capincci_alloc(struct capidev *cdev, u32 ncci)
        struct capiminor *mp = NULL;
 #endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
 
-       np = kmalloc(sizeof(*np), GFP_ATOMIC);
+       np = kzalloc(sizeof(*np), GFP_ATOMIC);
        if (!np)
                return NULL;
-       memset(np, 0, sizeof(struct capincci));
        np->ncci = ncci;
        np->cdev = cdev;
 #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
@@ -376,10 +382,9 @@ static struct capidev *capidev_alloc(void)
        struct capidev *cdev;
        unsigned long flags;
 
-       cdev = kmalloc(sizeof(*cdev), GFP_KERNEL);
+       cdev = kzalloc(sizeof(*cdev), GFP_KERNEL);
        if (!cdev)
                return NULL;
-       memset(cdev, 0, sizeof(struct capidev));
 
        init_MUTEX(&cdev->ncci_list_sem);
        skb_queue_head_init(&cdev->recvqueue);
@@ -1002,7 +1007,7 @@ static int capinc_tty_open(struct tty_struct * tty, struct file * file)
 {
        struct capiminor *mp;
 
-       if ((mp = capiminor_find(iminor(file->f_dentry->d_inode))) == 0)
+       if ((mp = capiminor_find(iminor(file->f_path.dentry->d_inode))) == 0)
                return -ENXIO;
        if (mp->nccip == 0)
                return -ENXIO;
@@ -1195,7 +1200,7 @@ static int capinc_tty_ioctl(struct tty_struct *tty, struct file * file,
        return error;
 }
 
-static void capinc_tty_set_termios(struct tty_struct *tty, struct termios * old)
+static void capinc_tty_set_termios(struct tty_struct *tty, struct ktermios * old)
 {
 #ifdef _DEBUG_TTYFUNCS
        printk(KERN_DEBUG "capinc_tty_set_termios\n");
@@ -1290,7 +1295,7 @@ static int capinc_tty_read_proc(char *page, char **start, off_t off,
 
 static struct tty_driver *capinc_tty_driver;
 
-static struct tty_operations capinc_ops = {
+static const struct tty_operations capinc_ops = {
        .open = capinc_tty_open,
        .close = capinc_tty_close,
        .write = capinc_tty_write,
@@ -1327,7 +1332,6 @@ static int capinc_tty_init(void)
 
        drv->owner = THIS_MODULE;
        drv->driver_name = "capi_nc";
-       drv->devfs_name = "capi/";
        drv->name = "capi";
        drv->major = capi_ttymajor;
        drv->minor_start = 0;
@@ -1485,6 +1489,7 @@ static int __init capi_init(void)
 {
        char *p;
        char *compileinfo;
+       int major_ret;
 
        if ((p = strchr(revision, ':')) != 0 && p[1]) {
                strlcpy(rev, p + 2, sizeof(rev));
@@ -1493,11 +1498,11 @@ static int __init capi_init(void)
        } else
                strcpy(rev, "1.0");
 
-       if (register_chrdev(capi_major, "capi20", &capi_fops)) {
+       major_ret = register_chrdev(capi_major, "capi20", &capi_fops);
+       if (major_ret < 0) {
                printk(KERN_ERR "capi20: unable to get major %d\n", capi_major);
-               return -EIO;
+               return major_ret;
        }
-
        capi_class = class_create(THIS_MODULE, "capi");
        if (IS_ERR(capi_class)) {
                unregister_chrdev(capi_major, "capi20");
@@ -1505,8 +1510,6 @@ static int __init capi_init(void)
        }
 
        class_device_create(capi_class, NULL, MKDEV(capi_major, 0), NULL, "capi");
-       devfs_mk_cdev(MKDEV(capi_major, 0), S_IFCHR | S_IRUSR | S_IWUSR,
-                       "isdn/capi20");
 
 #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
        if (capinc_tty_init() < 0) {
@@ -1541,7 +1544,6 @@ static void __exit capi_exit(void)
        class_device_destroy(capi_class, MKDEV(capi_major, 0));
        class_destroy(capi_class);
        unregister_chrdev(capi_major, "capi20");
-       devfs_remove("isdn/capi20");
 
 #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
        capinc_tty_exit();