]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/usb/serial/usb-serial.c
tty: Fix USB kref leak
[linux-2.6-omap-h63xx.git] / drivers / usb / serial / usb-serial.c
index 4f7f9e3ae0a43fe0fd630aaf4f436637383b0e4d..794b5ffe4397bcfd84f38c3d7affaebac6be77af 100644 (file)
@@ -214,7 +214,7 @@ static int serial_open (struct tty_struct *tty, struct file *filp)
        /* set up our port structure making the tty driver
         * remember our port object, and us it */
        tty->driver_data = port;
-       port->port.tty = tty;
+       tty_port_tty_set(&port->port, tty);
 
        if (port->port.count == 1) {
 
@@ -246,7 +246,7 @@ bailout_module_put:
 bailout_mutex_unlock:
        port->port.count = 0;
        tty->driver_data = NULL;
-       port->port.tty = NULL;
+       tty_port_tty_set(&port->port, NULL);
        mutex_unlock(&port->mutex);
 bailout_kref_put:
        usb_serial_put(serial);
@@ -276,10 +276,12 @@ static void serial_close(struct tty_struct *tty, struct file *filp)
                port->serial->type->close(tty, port, filp);
 
        if (port->port.count == (port->console? 1 : 0)) {
-               if (port->port.tty) {
-                       if (port->port.tty->driver_data)
-                               port->port.tty->driver_data = NULL;
-                       port->port.tty = NULL;
+               struct tty_struct *tty = tty_port_tty_get(&port->port);
+               if (tty) {
+                       if (tty->driver_data)
+                               tty->driver_data = NULL;
+                       tty_port_tty_set(&port->port, NULL);
+                       tty_kref_put(tty);
                }
        }
 
@@ -508,11 +510,12 @@ static void usb_serial_port_work(struct work_struct *work)
        if (!port)
                return;
 
-       tty = port->port.tty;
+       tty = tty_port_tty_get(&port->port);
        if (!tty)
                return;
 
        tty_wakeup(tty);
+       tty_kref_put(tty);
 }
 
 static void port_release(struct device *dev)
@@ -819,6 +822,7 @@ int usb_serial_probe(struct usb_interface *interface,
                port = kzalloc(sizeof(struct usb_serial_port), GFP_KERNEL);
                if (!port)
                        goto probe_error;
+               tty_port_init(&port->port);
                port->serial = serial;
                spin_lock_init(&port->lock);
                mutex_init(&port->mutex);
@@ -1040,8 +1044,11 @@ void usb_serial_disconnect(struct usb_interface *interface)
        for (i = 0; i < serial->num_ports; ++i) {
                port = serial->port[i];
                if (port) {
-                       if (port->port.tty)
-                               tty_hangup(port->port.tty);
+                       struct tty_struct *tty = tty_port_tty_get(&port->port);
+                       if (tty) {
+                               tty_hangup(tty);
+                               tty_kref_put(tty);
+                       }
                        kill_traffic(port);
                }
        }
@@ -1115,7 +1122,8 @@ static int __init usb_serial_init(void)
 
        result = bus_register(&usb_serial_bus_type);
        if (result) {
-               err("%s - registering bus driver failed", __func__);
+               printk(KERN_ERR "usb-serial: %s - registering bus driver "
+                      "failed\n", __func__);
                goto exit_bus;
        }
 
@@ -1136,25 +1144,28 @@ static int __init usb_serial_init(void)
        tty_set_operations(usb_serial_tty_driver, &serial_ops);
        result = tty_register_driver(usb_serial_tty_driver);
        if (result) {
-               err("%s - tty_register_driver failed", __func__);
+               printk(KERN_ERR "usb-serial: %s - tty_register_driver failed\n",
+                      __func__);
                goto exit_reg_driver;
        }
 
        /* register the USB driver */
        result = usb_register(&usb_serial_driver);
        if (result < 0) {
-               err("%s - usb_register failed", __func__);
+               printk(KERN_ERR "usb-serial: %s - usb_register failed\n",
+                      __func__);
                goto exit_tty;
        }
 
        /* register the generic driver, if we should */
        result = usb_serial_generic_register(debug);
        if (result < 0) {
-               err("%s - registering generic driver failed", __func__);
+               printk(KERN_ERR "usb-serial: %s - registering generic "
+                      "driver failed\n", __func__);
                goto exit_generic;
        }
 
-       info(DRIVER_DESC);
+       printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_DESC "\n");
 
        return result;
 
@@ -1168,7 +1179,8 @@ exit_reg_driver:
        bus_unregister(&usb_serial_bus_type);
 
 exit_bus:
-       err("%s - returning with error %d", __func__, result);
+       printk(KERN_ERR "usb-serial: %s - returning with error %d\n",
+              __func__, result);
        put_tty_driver(usb_serial_tty_driver);
        return result;
 }
@@ -1227,11 +1239,11 @@ int usb_serial_register(struct usb_serial_driver *driver)
 
        retval = usb_serial_bus_register(driver);
        if (retval) {
-               err("problem %d when registering driver %s",
-                                               retval, driver->description);
+               printk(KERN_ERR "usb-serial: problem %d when registering "
+                      "driver %s\n", retval, driver->description);
                list_del(&driver->driver_list);
        } else
-               info("USB Serial support registered for %s",
+               printk(KERN_INFO "USB Serial support registered for %s\n",
                                                driver->description);
 
        return retval;
@@ -1242,7 +1254,8 @@ EXPORT_SYMBOL_GPL(usb_serial_register);
 void usb_serial_deregister(struct usb_serial_driver *device)
 {
        /* must be called with BKL held */
-       info("USB Serial deregistering driver %s", device->description);
+       printk(KERN_INFO "USB Serial deregistering driver %s\n",
+              device->description);
        list_del(&device->driver_list);
        usb_serial_bus_deregister(device);
 }