Pull esi-support into release branch
[powerpc.git] / drivers / isdn / gigaset / common.c
index d00acdd..aca165d 100644 (file)
@@ -460,6 +460,9 @@ void gigaset_freecs(struct cardstate *cs)
 
        switch (cs->cs_init) {
        default:
+               /* clear device sysfs */
+               gigaset_free_dev_sysfs(cs);
+
                gigaset_if_free(cs);
 
                gig_dbg(DEBUG_INIT, "clearing hw");
@@ -699,6 +702,7 @@ struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels,
        cs->open_count = 0;
        cs->dev = NULL;
        cs->tty = NULL;
+       cs->class = NULL;
        cs->cidmode = cidmode != 0;
 
        //if(onechannel) { //FIXME
@@ -760,6 +764,9 @@ struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels,
 
        gigaset_if_init(cs);
 
+       /* set up device sysfs */
+       gigaset_init_dev_sysfs(cs);
+
        spin_lock_irqsave(&cs->lock, flags);
        cs->running = 1;
        spin_unlock_irqrestore(&cs->lock, flags);
@@ -781,8 +788,7 @@ error:      if (cs)
 }
 EXPORT_SYMBOL_GPL(gigaset_initcs);
 
-/* ReInitialize the b-channel structure */
-/* e.g. called on hangup, disconnect */
+/* ReInitialize the b-channel structure on hangup */
 void gigaset_bcs_reinit(struct bc_state *bcs)
 {
        struct sk_buff *skb;
@@ -903,9 +909,6 @@ int gigaset_start(struct cardstate *cs)
 
        wait_event(cs->waitqueue, !cs->waiting);
 
-       /* set up device sysfs */
-       gigaset_init_dev_sysfs(cs);
-
        mutex_unlock(&cs->mutex);
        return 1;
 
@@ -970,9 +973,6 @@ void gigaset_stop(struct cardstate *cs)
                //FIXME
        }
 
-       /* clear device sysfs */
-       gigaset_free_dev_sysfs(cs);
-
        cleanup_cs(cs);
 
 exit:
@@ -981,7 +981,7 @@ exit:
 EXPORT_SYMBOL_GPL(gigaset_stop);
 
 static LIST_HEAD(drivers);
-static spinlock_t driver_lock = SPIN_LOCK_UNLOCKED;
+static DEFINE_SPINLOCK(driver_lock);
 
 struct cardstate *gigaset_get_cs_by_id(int id)
 {
@@ -1037,16 +1037,8 @@ void gigaset_debugdrivers(void)
        }
        spin_unlock_irqrestore(&driver_lock, flags);
 }
-EXPORT_SYMBOL_GPL(gigaset_debugdrivers);
 
-struct cardstate *gigaset_get_cs_by_tty(struct tty_struct *tty)
-{
-       if (tty->index < 0 || tty->index >= tty->driver->num)
-               return NULL;
-       return gigaset_get_cs_by_minor(tty->index + tty->driver->minor_start);
-}
-
-struct cardstate *gigaset_get_cs_by_minor(unsigned minor)
+static struct cardstate *gigaset_get_cs_by_minor(unsigned minor)
 {
        unsigned long flags;
        static struct cardstate *ret = NULL;
@@ -1069,6 +1061,13 @@ struct cardstate *gigaset_get_cs_by_minor(unsigned minor)
        return ret;
 }
 
+struct cardstate *gigaset_get_cs_by_tty(struct tty_struct *tty)
+{
+       if (tty->index < 0 || tty->index >= tty->driver->num)
+               return NULL;
+       return gigaset_get_cs_by_minor(tty->index + tty->driver->minor_start);
+}
+
 void gigaset_freedriver(struct gigaset_driver *drv)
 {
        unsigned long flags;
@@ -1093,14 +1092,12 @@ EXPORT_SYMBOL_GPL(gigaset_freedriver);
  *     minors          Number of minors this driver can handle
  *     procname        Name of the driver
  *     devname         Name of the device files (prefix without minor number)
- *     devfsname       Devfs name of the device files without %d
  * return value:
  *     Pointer to the gigaset_driver structure on success, NULL on failure.
  */
 struct gigaset_driver *gigaset_initdriver(unsigned minor, unsigned minors,
                                          const char *procname,
                                          const char *devname,
-                                         const char *devfsname,
                                          const struct gigaset_ops *ops,
                                          struct module *owner)
 {
@@ -1111,8 +1108,9 @@ struct gigaset_driver *gigaset_initdriver(unsigned minor, unsigned minors,
        drv = kmalloc(sizeof *drv, GFP_KERNEL);
        if (!drv)
                return NULL;
+
        if (!try_module_get(owner))
-               return NULL;
+               goto out1;
 
        drv->cs = NULL;
        drv->have_tty = 0;
@@ -1126,10 +1124,11 @@ struct gigaset_driver *gigaset_initdriver(unsigned minor, unsigned minors,
 
        drv->cs = kmalloc(minors * sizeof *drv->cs, GFP_KERNEL);
        if (!drv->cs)
-               goto out1;
+               goto out2;
+
        drv->flags = kmalloc(minors * sizeof *drv->flags, GFP_KERNEL);
        if (!drv->flags)
-               goto out2;
+               goto out3;
 
        for (i = 0; i < minors; ++i) {
                drv->flags[i] = 0;
@@ -1138,7 +1137,7 @@ struct gigaset_driver *gigaset_initdriver(unsigned minor, unsigned minors,
                drv->cs[i].minor_index = i;
        }
 
-       gigaset_if_initdriver(drv, procname, devname, devfsname);
+       gigaset_if_initdriver(drv, procname, devname);
 
        spin_lock_irqsave(&driver_lock, flags);
        list_add(&drv->list, &drivers);
@@ -1146,11 +1145,12 @@ struct gigaset_driver *gigaset_initdriver(unsigned minor, unsigned minors,
 
        return drv;
 
-out2:
+out3:
        kfree(drv->cs);
+out2:
+       module_put(owner);
 out1:
        kfree(drv);
-       module_put(owner);
        return NULL;
 }
 EXPORT_SYMBOL_GPL(gigaset_initdriver);