USB: cdc-acm: fix runtime PM imbalance at shutdown
authorJohan Hovold <jhovold@gmail.com>
Mon, 26 May 2014 17:23:45 +0000 (19:23 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 26 Jun 2014 19:10:29 +0000 (15:10 -0400)
commit 5292afa657d0e790b7479ad8eef9450c1e040b3d upstream.

Make sure only to decrement the PM counters if they were actually
incremented.

Note that the USB PM counter, but not necessarily the driver core PM
counter, is reset when the interface is unbound.

Fixes: 11ea859d64b6 ("USB: additional power savings for cdc-acm devices
that support remote wakeup")

Signed-off-by: Johan Hovold <jhovold@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/class/cdc-acm.c

index 7ffd5f5..2f2540f 100644 (file)
@@ -623,12 +623,13 @@ static void acm_port_shutdown(struct tty_port *port)
        struct urb *urb;
        struct acm_wb *wb;
        int i;
+       int pm_err;
 
        dev_dbg(&acm->control->dev, "%s\n", __func__);
 
        mutex_lock(&acm->mutex);
        if (!acm->disconnected) {
-               usb_autopm_get_interface(acm->control);
+               pm_err = usb_autopm_get_interface(acm->control);
                acm_set_control(acm, acm->ctrlout = 0);
 
                for (;;) {
@@ -646,7 +647,8 @@ static void acm_port_shutdown(struct tty_port *port)
                for (i = 0; i < acm->rx_buflimit; i++)
                        usb_kill_urb(acm->read_urbs[i]);
                acm->control->needs_remote_wakeup = 0;
-               usb_autopm_put_interface(acm->control);
+               if (!pm_err)
+                       usb_autopm_put_interface(acm->control);
        }
        mutex_unlock(&acm->mutex);
 }