]> git.hungrycats.org Git - linux/commitdiff
[PATCH] USB: fix bug for multiple opens on ttyUSB devices.
authorGreg Kroah-Hartman <greg@kroah.com>
Wed, 10 Dec 2003 06:39:48 +0000 (22:39 -0800)
committerGreg Kroah-Hartman <greg@kroah.com>
Wed, 10 Dec 2003 06:39:48 +0000 (22:39 -0800)
This patch fixes the bug where running ppp over a ttyUSB device would fail.

drivers/usb/serial/usb-serial.c

index ec610ee4aa1cdd54d372c3d4517b2154ad246d4b..c7a96102a73ee8329bfaf01b88b330031ea9f0a1 100644 (file)
@@ -493,12 +493,15 @@ bailout:
        return retval;
 }
 
-static void __serial_close(struct usb_serial_port *port, struct file *filp)
+static void serial_close(struct tty_struct *tty, struct file * filp)
 {
-       if (!port->open_count) {
-               dbg ("%s - port not opened", __FUNCTION__);
+       struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data;
+       struct usb_serial *serial = get_usb_serial (port, __FUNCTION__);
+
+       if (!serial)
                return;
-       }
+
+       dbg("%s - port %d", __FUNCTION__, port->number);
 
        --port->open_count;
        if (port->open_count <= 0) {
@@ -506,30 +509,18 @@ static void __serial_close(struct usb_serial_port *port, struct file *filp)
                 * port is being closed by the last owner */
                port->serial->type->close(port, filp);
                port->open_count = 0;
+
+               if (port->tty) {
+                       if (port->tty->driver_data)
+                               port->tty->driver_data = NULL;
+                       port->tty = NULL;
+               }
        }
 
        module_put(port->serial->type->owner);
        kobject_put(&port->serial->kobj);
 }
 
-static void serial_close(struct tty_struct *tty, struct file * filp)
-{
-       struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data;
-       struct usb_serial *serial = get_usb_serial (port, __FUNCTION__);
-
-       if (!serial)
-               return;
-
-       dbg("%s - port %d", __FUNCTION__, port->number);
-
-       /* if disconnect beat us to the punch here, there's nothing to do */
-       if (tty && tty->driver_data) {
-               __serial_close(port, filp);
-               tty->driver_data = NULL;
-       }
-       port->tty = NULL;
-}
-
 static int serial_write (struct tty_struct * tty, int from_user, const unsigned char *buf, int count)
 {
        struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data;
@@ -848,19 +839,6 @@ static void destroy_serial (struct kobject *kobj)
        dbg ("%s - %s", __FUNCTION__, kobj->name);
 
        serial = to_usb_serial(kobj);
-
-       /* fail all future close/read/write/ioctl/etc calls */
-       for (i = 0; i < serial->num_ports; ++i) {
-               port = serial->port[i];
-               if (port->tty != NULL) {
-                       port->tty->driver_data = NULL;
-                       while (port->open_count > 0) {
-                               __serial_close(port, NULL);
-                       }
-                       port->tty = NULL;
-               }
-       }
-
        serial_shutdown (serial);
 
        /* return the minor range that this device had */