[PATCH 59/63] USB: cdc-acm: minimise no-suspend window during shutdown

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Now that acm_set_control() handles runtime PM properly, the only
remaining reason for the PM operations in shutdown is to clear the
needs_remote_wakeup flag before the final put.

Note that this also means that we now need to grab the write_lock to
prevent racing with resume.

Signed-off-by: Johan Hovold <jhovold@xxxxxxxxx>
---
 drivers/usb/class/cdc-acm.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
index 91fdc293196f..f038f390db97 100644
--- a/drivers/usb/class/cdc-acm.c
+++ b/drivers/usb/class/cdc-acm.c
@@ -590,13 +590,22 @@ 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__);
 
-	pm_err = usb_autopm_get_interface(acm->control);
 	acm_set_control(acm, acm->ctrlout = 0);
 
+	/*
+	 * Need to grab write_lock to prevent race with resume, but no need to
+	 * hold it due to the tty-port initialised flag.
+	 */
+	spin_lock_irq(&acm->write_lock);
+	spin_unlock_irq(&acm->write_lock);
+
+	usb_autopm_get_interface_no_resume(acm->control);
+	acm->control->needs_remote_wakeup = 0;
+	usb_autopm_put_interface(acm->control);
+
 	for (;;) {
 		urb = usb_get_from_anchor(&acm->delayed);
 		if (!urb)
@@ -611,10 +620,6 @@ static void acm_port_shutdown(struct tty_port *port)
 		usb_kill_urb(acm->wb[i].urb);
 	for (i = 0; i < acm->rx_buflimit; i++)
 		usb_kill_urb(acm->read_urbs[i]);
-
-	acm->control->needs_remote_wakeup = 0;
-	if (!pm_err)
-		usb_autopm_put_interface(acm->control);
 }
 
 static void acm_tty_cleanup(struct tty_struct *tty)
-- 
1.8.5.5

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux