提交 c14829fa 编写于 作者: J Johan Hovold 提交者: Greg Kroah-Hartman

USB: serial: fix potential runtime pm imbalance at device remove

Only call usb_autopm_put_interface() if the corresponding
usb_autopm_get_interface() was successful.

This prevents a potential runtime PM counter imbalance should
usb_autopm_get_interface() fail. Note that the USB PM usage counter is
reset when the interface is unbound, but that the runtime PM counter may
be left unbalanced.

Also add comment on why we don't need to worry about racing
resume/suspend on autopm_get failures.

Fixes: d5fd650c ("usb: serial: prevent suspend/resume from racing
against probe/remove")
Signed-off-by: NJohan Hovold <jhovold@gmail.com>
Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
上级 b0a9aa6d
...@@ -97,13 +97,19 @@ static int usb_serial_device_remove(struct device *dev) ...@@ -97,13 +97,19 @@ static int usb_serial_device_remove(struct device *dev)
struct usb_serial_port *port; struct usb_serial_port *port;
int retval = 0; int retval = 0;
int minor; int minor;
int autopm_err;
port = to_usb_serial_port(dev); port = to_usb_serial_port(dev);
if (!port) if (!port)
return -ENODEV; return -ENODEV;
/* make sure suspend/resume doesn't race against port_remove */ /*
usb_autopm_get_interface(port->serial->interface); * Make sure suspend/resume doesn't race against port_remove.
*
* Note that no further runtime PM callbacks will be made if
* autopm_get fails.
*/
autopm_err = usb_autopm_get_interface(port->serial->interface);
minor = port->minor; minor = port->minor;
tty_unregister_device(usb_serial_tty_driver, minor); tty_unregister_device(usb_serial_tty_driver, minor);
...@@ -117,7 +123,9 @@ static int usb_serial_device_remove(struct device *dev) ...@@ -117,7 +123,9 @@ static int usb_serial_device_remove(struct device *dev)
dev_info(dev, "%s converter now disconnected from ttyUSB%d\n", dev_info(dev, "%s converter now disconnected from ttyUSB%d\n",
driver->description, minor); driver->description, minor);
usb_autopm_put_interface(port->serial->interface); if (!autopm_err)
usb_autopm_put_interface(port->serial->interface);
return retval; return retval;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册