]> git.neil.brown.name Git - history.git/commitdiff
ISDN: Kill drvid[] array
authorKai Germaschewski <kai@tp1.ruhr-uni-bochum.de>
Tue, 29 Oct 2002 14:39:24 +0000 (08:39 -0600)
committerKai Germaschewski <kai@tp1.ruhr-uni-bochum.de>
Tue, 29 Oct 2002 14:39:24 +0000 (08:39 -0600)
We know the driver ids via drivers[]->interface->id already, no need
to keep them around a second time.

drivers/isdn/i4l/isdn_common.c
drivers/isdn/i4l/isdn_common.h
include/linux/isdn.h

index 9ce6b2af541b320963b10b104152226ef91e505f..6f7b9c11ad7ded1cac259fc9b6c27db7f35a3f46 100644 (file)
@@ -109,6 +109,42 @@ isdn_drv_hdrlen(int di)
        return drivers[di]->interface->hl_hdrlen;
 }
 
+int
+__isdn_drv_lookup(char *drvid)
+{
+       int drvidx;
+
+       for (drvidx = 0; drvidx < ISDN_MAX_DRIVERS; drvidx++) {
+               if (!drivers[drvidx])
+                       continue;
+
+               if (strcmp(drivers[drvidx]->interface->id, drvid) == 0)
+                       return drvidx;
+       }
+       return -1;
+}
+
+int
+isdn_drv_lookup(char *drvid)
+{
+       unsigned long flags;
+       int drvidx;
+
+       spin_lock_irqsave(&drivers_lock, flags);
+       drvidx = __isdn_drv_lookup(drvid);
+       spin_unlock_irqrestore(&drivers_lock, flags);
+       return drvidx;
+}
+
+char *isdn_drv_drvid(int di)
+{
+       if (!drivers[di]) {
+               isdn_BUG();
+               return "";
+       }
+       return drivers[di]->interface->id;
+}
+
 static int  isdn_add_channels(struct isdn_driver *, int, int, int);
 static void isdn_receive_skb_callback(int di, int ch, struct sk_buff *skb);
 static int  isdn_status_callback(isdn_ctrl * c);
@@ -169,11 +205,8 @@ register_isdn(isdn_if *iif)
        if (!strlen(iif->id))
                sprintf(iif->id, "line%d", drvidx);
 
-       strcpy(dev->drvid[drvidx], iif->id);
-
-       for (drvidx = 0; drvidx < ISDN_MAX_DRIVERS; drvidx++)
-               if (strcmp(iif->id, dev->drvid[drvidx]) == 0)
-                       goto fail_unlock;
+       if (__isdn_drv_lookup(iif->id) >= 0)
+               goto fail_unlock;
 
        if (isdn_add_channels(drv, drvidx, iif->channels, 0))
                goto fail_unlock;
@@ -693,7 +726,7 @@ isdn_status_callback(isdn_ctrl * c)
                case ISDN_STAT_CAUSE:
                        dbg_statcallb("CAUSE: %d %s\n", i, c->parm.num);
                        printk(KERN_INFO "isdn: %s,ch%ld cause: %s\n",
-                              dev->drvid[di], c->arg, c->parm.num);
+                              isdn_drv_drvid(di), c->arg, c->parm.num);
                        isdn_tty_stat_callback(i, c);
                         if (divert_if)
                                divert_if->stat_callback(c); 
@@ -819,7 +852,6 @@ isdn_status_callback(isdn_ctrl * c)
                        kfree(drivers[di]->rpqueue);
                        kfree(drivers[di]);
                        drivers[di] = NULL;
-                       dev->drvid[di][0] = '\0';
                        isdn_info_update();
                        set_global_features();
                        restore_flags(flags);
@@ -987,7 +1019,7 @@ isdn_statstr(void)
        sprintf(istatbuf, "idmap:\t");
        p = istatbuf + strlen(istatbuf);
        for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
-               sprintf(p, "%s ", (slot[i].di < 0) ? "-" : dev->drvid[slot[i].di]);
+               sprintf(p, "%s ", (slot[i].di < 0) ? "-" : isdn_drv_drvid(slot[i].di));
                p = istatbuf + strlen(istatbuf);
        }
        sprintf(p, "\nchmap:\t");
@@ -1395,7 +1427,6 @@ isdn_ctrl_ioctl(struct inode *inode, struct file *file, uint cmd, ulong arg)
        case IIOCSETBRJ:
                drvidx = -1;
                if (arg) {
-                       int i;
                        char *p;
                        if (copy_from_user((char *) &iocts, (char *) arg,
                                           sizeof(isdn_ioctl_struct)))
@@ -1403,12 +1434,7 @@ isdn_ctrl_ioctl(struct inode *inode, struct file *file, uint cmd, ulong arg)
                        if (strlen(iocts.drvid)) {
                                if ((p = strchr(iocts.drvid, ',')))
                                        *p = 0;
-                               drvidx = -1;
-                               for (i = 0; i < ISDN_MAX_DRIVERS; i++)
-                                       if (!(strcmp(dev->drvid[i], iocts.drvid))) {
-                                               drvidx = i;
-                                               break;
-                                       }
+                               drvidx = isdn_drv_lookup(iocts.drvid);
                        }
                }
                if (drvidx == -1)
@@ -1485,15 +1511,7 @@ isdn_ctrl_ioctl(struct inode *inode, struct file *file, uint cmd, ulong arg)
                                           (char *) arg,
                                           sizeof(isdn_ioctl_struct)))
                                return -EFAULT;
-                       if (strlen(iocts.drvid)) {
-                               drvidx = -1;
-                               for (i = 0; i < ISDN_MAX_DRIVERS; i++)
-                                       if (!(strcmp(dev->drvid[i], iocts.drvid))) {
-                                               drvidx = i;
-                                               break;
-                                       }
-                       } else
-                               drvidx = 0;
+                       drvidx = isdn_drv_lookup(iocts.drvid);
                        if (drvidx == -1)
                                return -ENODEV;
                        if (cmd == IIOCSETMAP) {
@@ -1555,21 +1573,9 @@ isdn_ctrl_ioctl(struct inode *inode, struct file *file, uint cmd, ulong arg)
                else
                        return -EINVAL;
                if (arg) {
-                       int i;
-                       char *p;
                        if (copy_from_user((char *) &iocts, (char *) arg, sizeof(isdn_ioctl_struct)))
                                return -EFAULT;
-                       if (strlen(iocts.drvid)) {
-                               if ((p = strchr(iocts.drvid, ',')))
-                                       *p = 0;
-                               drvidx = -1;
-                               for (i = 0; i < ISDN_MAX_DRIVERS; i++)
-                                       if (!(strcmp(dev->drvid[i], iocts.drvid))) {
-                                               drvidx = i;
-                                               break;
-                                       }
-                       } else
-                               drvidx = 0;
+                       drvidx = isdn_drv_lookup(iocts.drvid);
                        if (drvidx == -1)
                                return -ENODEV;
                        if ((ret = verify_area(VERIFY_WRITE, (void *) arg,
index ee9d125e592c3e8a2ac576d819a88a4ebe9028fa..96aab20198f9ad8ab88bed7b7d106bd4c40146d5 100644 (file)
@@ -99,8 +99,10 @@ extern void  isdn_slot_set_priv(int sl, void *);
 extern void *isdn_slot_priv(int sl);
 extern int   isdn_hard_header_len(void);
 
-int  isdn_drv_queue_empty(int di, int ch);
-void isdn_drv_queue_tail(int di, int ch, struct sk_buff *skb, int len);
-int  isdn_drv_maxbufsize(int di);
-int  isdn_drv_writebuf_skb(int di, int ch, int x, struct sk_buff *skb);
-int  isdn_drv_hdrlen(int di);
+int   isdn_drv_queue_empty(int di, int ch);
+void  isdn_drv_queue_tail(int di, int ch, struct sk_buff *skb, int len);
+int   isdn_drv_maxbufsize(int di);
+int   isdn_drv_writebuf_skb(int di, int ch, int x, struct sk_buff *skb);
+int   isdn_drv_hdrlen(int di);
+int   isdn_drv_lookup(char *drvid);
+char *isdn_drv_drvid(int di);
index 1f71bd37a4db6b8d2ff052ddf3b0077cc3ab707c..ded1aad43e4cff163e42ad8a66e62c387e44877e 100644 (file)
@@ -426,7 +426,6 @@ typedef struct isdn_devt {
        infostruct        *infochain;                /* List of open info-devs.    */
        wait_queue_head_t info_waitq;               /* Wait-Queue for isdninfo    */
        struct timer_list timer;                       /* Misc.-function Timer       */
-       char              drvid[ISDN_MAX_DRIVERS][20];/* Driver-ID                 */
        struct task_struct *profd;                   /* For iprofd                 */
        modem             mdm;                 /* tty-driver-data            */
        struct semaphore  sem;                       /* serialize list access*/