[PATCH] USB: fix usb reference count bug in cdc-acm driver

This increases the reference count on the usb cdc acm control interface
which is referred to by the tty interface provided by the driver. This
allows the deferred removal of the tty after the physical device is
disconnected if the tty is held open at the time of disconnection.

Signed-off-by: [EMAIL PROTECTED]
Signed-off-by: Greg Kroah-Hartman <[EMAIL PROTECTED]>

---
commit 83ef344a7539aa55a787790bc036f0bf3466e191
tree 3a49e9eb5e690a3b0f6609ef0f24f403b3828a39
parent a3fdf4ebe016ba756de3ca29a2a6117e9acd721c
author [EMAIL PROTECTED] <[EMAIL PROTECTED]> Wed, 29 Jun 2005 16:53:29 -0700
committer Greg Kroah-Hartman <[EMAIL PROTECTED]> Tue, 12 Jul 2005 11:52:57 -0700

 drivers/usb/class/cdc-acm.c |   31 ++++++++++++++++---------------
 1 files changed, 16 insertions(+), 15 deletions(-)

diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
--- a/drivers/usb/class/cdc-acm.c
+++ b/drivers/usb/class/cdc-acm.c
@@ -422,6 +422,17 @@ bail_out:
        return -EIO;
 }
 
+static void acm_tty_unregister(struct acm *acm)
+{
+       tty_unregister_device(acm_tty_driver, acm->minor);
+       usb_put_intf(acm->control);
+       acm_table[acm->minor] = NULL;
+       usb_free_urb(acm->ctrlurb);
+       usb_free_urb(acm->readurb);
+       usb_free_urb(acm->writeurb);
+       kfree(acm);
+}
+
 static void acm_tty_close(struct tty_struct *tty, struct file *filp)
 {
        struct acm *acm = tty->driver_data;
@@ -436,14 +447,8 @@ static void acm_tty_close(struct tty_str
                        usb_kill_urb(acm->ctrlurb);
                        usb_kill_urb(acm->writeurb);
                        usb_kill_urb(acm->readurb);
-               } else {
-                       tty_unregister_device(acm_tty_driver, acm->minor);
-                       acm_table[acm->minor] = NULL;
-                       usb_free_urb(acm->ctrlurb);
-                       usb_free_urb(acm->readurb);
-                       usb_free_urb(acm->writeurb);
-                       kfree(acm);
-               }
+               } else
+                       acm_tty_unregister(acm);
        }
        up(&open_sem);
 }
@@ -905,7 +910,8 @@ skip_normal_probe:
 
        usb_driver_claim_interface(&acm_driver, data_interface, acm);
 
-       tty_register_device(acm_tty_driver, minor, &intf->dev);
+       usb_get_intf(control_interface);
+       tty_register_device(acm_tty_driver, minor, &control_interface->dev);
 
        acm_table[minor] = acm;
        usb_set_intfdata (intf, acm);
@@ -954,12 +960,7 @@ static void acm_disconnect(struct usb_in
        usb_driver_release_interface(&acm_driver, acm->data);
 
        if (!acm->used) {
-               tty_unregister_device(acm_tty_driver, acm->minor);
-               acm_table[acm->minor] = NULL;
-               usb_free_urb(acm->ctrlurb);
-               usb_free_urb(acm->readurb);
-               usb_free_urb(acm->writeurb);
-               kfree(acm);
+               acm_tty_unregister(acm);
                up(&open_sem);
                return;
        }



-------------------------------------------------------
This SF.Net email is sponsored by the 'Do More With Dual!' webinar happening
July 14 at 8am PDT/11am EDT. We invite you to explore the latest in dual
core and dual graphics technology at this free one hour event hosted by HP,
AMD, and NVIDIA.  To register visit http://www.hp.com/go/dualwebinar
_______________________________________________
linux-usb-devel@lists.sourceforge.net
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

Reply via email to