aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/serial/usb-serial.c
diff options
context:
space:
mode:
authorJohan Hovold <johan@kernel.org>2021-09-10 14:11:28 +0200
committerJohan Hovold <johan@kernel.org>2021-09-20 11:49:34 +0200
commit6400b974910407cd299dc08578a6c1792b4c922a (patch)
treec5fa78901493dda544cda1f037dcd604090c36bf /drivers/usb/serial/usb-serial.c
parentUSB: serial: clean up core error labels (diff)
downloadlinux-dev-6400b974910407cd299dc08578a6c1792b4c922a.tar.xz
linux-dev-6400b974910407cd299dc08578a6c1792b4c922a.zip
USB: serial: allow hung up ports to be suspended
User space can keep a tty open indefinitely and that should not prevent a hung up port and its USB device from being runtime suspended. Fix this by incrementing the PM usage counter when the port it activated and decrementing the counter when the port is shutdown rather than when the tty is installed and the last reference is dropped, respectively. Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Johan Hovold <johan@kernel.org>
Diffstat (limited to 'drivers/usb/serial/usb-serial.c')
-rw-r--r--drivers/usb/serial/usb-serial.c31
1 files changed, 17 insertions, 14 deletions
diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c
index d71f08da2dfd..24101bd7fcad 100644
--- a/drivers/usb/serial/usb-serial.c
+++ b/drivers/usb/serial/usb-serial.c
@@ -208,8 +208,8 @@ void usb_serial_put(struct usb_serial *serial)
*
* This is the first place a new tty gets used. Hence this is where we
* acquire references to the usb_serial structure and the driver module,
- * where we store a pointer to the port, and where we do an autoresume.
- * All these actions are reversed in serial_cleanup().
+ * where we store a pointer to the port. All these actions are reversed
+ * in serial_cleanup().
*/
static int serial_install(struct tty_driver *driver, struct tty_struct *tty)
{
@@ -227,15 +227,11 @@ static int serial_install(struct tty_driver *driver, struct tty_struct *tty)
if (!try_module_get(serial->type->driver.owner))
goto err_put_serial;
- retval = usb_autopm_get_interface(serial->interface);
- if (retval)
- goto err_put_module;
-
init_termios = (driver->termios[idx] == NULL);
retval = tty_standard_install(driver, tty);
if (retval)
- goto err_put_autopm;
+ goto err_put_module;
mutex_unlock(&serial->disc_mutex);
@@ -247,8 +243,6 @@ static int serial_install(struct tty_driver *driver, struct tty_struct *tty)
return retval;
-err_put_autopm:
- usb_autopm_put_interface(serial->interface);
err_put_module:
module_put(serial->type->driver.owner);
err_put_serial:
@@ -265,10 +259,19 @@ static int serial_port_activate(struct tty_port *tport, struct tty_struct *tty)
int retval;
mutex_lock(&serial->disc_mutex);
- if (serial->disconnected)
+ if (serial->disconnected) {
retval = -ENODEV;
- else
- retval = port->serial->type->open(tty, port);
+ goto out_unlock;
+ }
+
+ retval = usb_autopm_get_interface(serial->interface);
+ if (retval)
+ goto out_unlock;
+
+ retval = port->serial->type->open(tty, port);
+ if (retval)
+ usb_autopm_put_interface(serial->interface);
+out_unlock:
mutex_unlock(&serial->disc_mutex);
if (retval < 0)
@@ -304,6 +307,8 @@ static void serial_port_shutdown(struct tty_port *tport)
if (drv->close)
drv->close(port);
+
+ usb_autopm_put_interface(port->serial->interface);
}
static void serial_hangup(struct tty_struct *tty)
@@ -352,8 +357,6 @@ static void serial_cleanup(struct tty_struct *tty)
serial = port->serial;
owner = serial->type->driver.owner;
- usb_autopm_put_interface(serial->interface);
-
usb_serial_put(serial);
module_put(owner);
}