USB: don't recover device if suspend fails in system sleep
Subsystems (11)
v3 cover USB: don't recover device if suspend fails in system sleep
Hi,
This patch adds comments on interface driver suspend callback to emphasize that the failure return value is ignored by USB core in system sleep context, so do not try to recover device for this case, otherwise the recovery things may confuse resume().
Also fixes USB HID and several usbnet drivers which may recover device in suspend failure path of system sleep.
v3:
- only 2/7 changed, don't change code but add comments to restrict subdriver->suspend(), suggested by Johan Hovold.
v2:
- improve comments on suspend callback as suggested by Alan
- update kerneldoc for usb_suspend_both as suggested by Alan
- remove previous check of PMSG_IS_AUTO(message) in cdc_mbim/ qmi_wwan and add comments on suspend failure case, since Bjørn doesn't like the check.
- add comments on smsc95xx/smsc75xx
v1:
- fix compile failure
- add comments about handling suspend failure in resume()
drivers/hid/usbhid/hid-core.c | 14 +++++--------- drivers/net/usb/cdc_mbim.c | 5 +++++ drivers/net/usb/qmi_wwan.c | 5 +++++ drivers/net/usb/smsc75xx.c | 6 +++++- drivers/net/usb/smsc95xx.c | 6 +++++- drivers/usb/core/driver.c | 11 ++++++++--- drivers/usb/serial/usb-serial.c | 5 +++++ include/linux/usb.h | 7 ++++++- 8 files changed, 44 insertions(+), 15 deletions(-)
Thanks
--
Ming Lei
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v3 1/7 USB: adds comment on suspend callback
In reply to a message not in the archiveThis patch adds comments on interface driver suspend callback to emphasize that the failure return value is ignored by USB core in system sleep context, so do not try to recover device for this case and let resume/reset_resume callback handle the suspend failure if needed.
Also kerneldoc for usb_suspend_both() is updated with the fact.
--- drivers/usb/core/driver.c | 11 ++++++++--- include/linux/usb.h | 7 ++++++- 2 files changed, 14 insertions(+), 4 deletions(-)
drivers/usb/core/driver.c +8 -3
@@ -1196,9 +1196,14 @@ done:* * This is the central routine for suspending USB devices. It calls the * suspend methods for all the interface drivers in @udev and then calls -* the suspend method for @udev itself. If an error occurs at any stage, -* all the interfaces which were suspended are resumed so that they remain -* in the same state as the device. +* the suspend method for @udev itself. When the routine is called in +* autosuspend, if an error occurs at any stage, all the interfaces +* which were suspended are resumed so that they remain in the same +* state as the device, but when called from system sleep, all error +* from suspend methods of interfaces and the non-root-hub device itself +* are simply ignored, so all suspended interfaces are only resumed +* to the device's state when @udev is root-hub and its suspend method +* returns failure. * * Autosuspend requests originating from a child device or an interface * driver may be made without the protection of @udev's device lock, but
include/linux/usb.h +6 -1
@@ -978,7 +978,12 @@ struct usbdrv_wrap {* the "usbfs" filesystem. This lets devices provide ways to * expose information to user space regardless of where they * do (or don't) show up otherwise in the filesystem. -* @suspend: Called when the device is going to be suspended by the system. +* @suspend: Called when the device is going to be suspended by the +* system either from system sleep or runtime suspend context. The +* return value will be ignored in system sleep context, so do NOT +* try to continue using the device if suspend fails in this case. +* Instead, let the resume or reset-resume routine recover from +* the failure. * @resume: Called when the device is being resumed by the system. * @reset_resume: Called when the suspended device has been reset instead * of being resumed.
Signature · 6 lines
1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v3 2/7 USB: serial: comments on suspend failure
In reply to a message not in the archiveIf suspend callback fails in system sleep context, usb core will ignore the failure and let system sleep go ahead further, so this patch comments on the case and requires that serial->type->suspend() MUST return 0 in system sleep context.
--- drivers/usb/serial/usb-serial.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/usb/serial/usb-serial.c +5 -0
@@ -1140,6 +1140,11 @@ int usb_serial_suspend(struct usb_interface *intf, pm_message_t message) serial->suspending =1 ; +/* +* serial->type->suspend() MUST return 0 in system sleep context, +* otherwise, the resume callback has to recover device from +* previous suspend failure. +*/ if (serial->type->suspend) { r = serial->type->suspend (serial, message);if (r <0 ) {
Signature · 6 lines
1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v3 3/7 USBHID: don't recover device if suspend fails in system sleep
In reply to Ming LeiIf suspend callback fails in system sleep context, usb core will ignore the failure and let the system sleep go ahead further, so this patch doesn't recover device under this situation, otherwise may cause resume() confused.
--- drivers/hid/usbhid/hid-core.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-)
drivers/hid/usbhid/hid-core.c +5 -9
@@ -1520,7 +1520,7 @@ static int hid_suspend(struct usb_interface *intf, pm_message_t message) {struct hid_device *hid =usb_get_intfdata (intf);struct usbhid_device *usbhid = hid->driver_data; -int status; +int status =0 ;bool driver_suspended = false;if (PMSG_IS_AUTO (message)) {
@@ -1547,19 +1547,15 @@ static int hid_suspend(struct usb_interface *intf, pm_message_t message) } }else { -if (hid->driver && hid->driver->suspend) { +/* TODO: resume() might need to handle suspend failure */ +if (hid->driver && hid->driver->suspend) status = hid->driver->suspend (hid, message); -if (status <0 ) -return status; - } driver_suspended = true;spin_lock_irq (&usbhid->lock);set_bit (HID_SUSPENDED , &usbhid->iofl);spin_unlock_irq (&usbhid->lock); -if (usbhid_wait_io (hid) <0 ) { +if (usbhid_wait_io (hid) <0 ) status = -EIO ; - goto failed; - } }hid_cancel_delayed_stuff (usbhid);
@@ -1571,7 +1567,7 @@ static int hid_suspend(struct usb_interface *intf, pm_message_t message) goto failed; }dev_dbg (&intf->dev,"suspend\n" ); -return 0 ; +return status; failed:hid_resume_common (hid, driver_suspended);
Signature · 1 line
1.7.9.5
PATCH v3 4/7 usbnet: cdc_mbim: comments on suspend failure
In reply to Ming LeiIf suspend callback fails in system sleep context, usb core will ignore the failure and let system sleep go ahead further, so this patch comments on the case and requires that both usbnet_suspend() and subdriver->suspend() MUST return 0 in system sleep context.
--- drivers/net/usb/cdc_mbim.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/net/usb/cdc_mbim.c +5 -0
@@ -332,6 +332,11 @@ static int cdc_mbim_suspend(struct usb_interface *intf, pm_message_t message) goto error; } +/* +* Both usbnet_suspend() and subdriver->suspend() MUST return 0 +* in system sleep context, otherwise, the resume callback has +* to recover device from previous suspend failure. +*/ ret =usbnet_suspend (intf, message);if (ret <0 ) goto error;
Signature · 1 line
1.7.9.5
PATCH v3 5/7 usbnet: qmi_wwan: comments on suspend failure
In reply to a message not in the archiveIf suspend callback fails in system sleep context, usb core will ignore the failure and let system sleep go ahead further, so this patch comments on the case and requires that both usbnet_suspend() and subdriver->suspend() MUST return 0 in system sleep context.
--- drivers/net/usb/qmi_wwan.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/net/usb/qmi_wwan.c +5 -0
@@ -271,6 +271,11 @@ static int qmi_wwan_suspend(struct usb_interface *intf, pm_message_t message)struct qmi_wwan_state *info = (void *)&dev->data;int ret; +/* +* Both usbnet_suspend() and subdriver->suspend() MUST return 0 +* in system sleep context, otherwise, the resume callback has +* to recover device from previous suspend failure. +*/ ret =usbnet_suspend (intf, message);if (ret <0 ) goto err;
Signature · 6 lines
1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v3 6/7 usbnet: smsc95xx: don't recover device if suspend fails in system sleep
In reply to Ming LeiIf suspend callback fails in system sleep context, usb core will ignore the failure and let system sleep go ahead further, so this patch doesn't recover device under this situation.
Also add comments on the case.
--- drivers/net/usb/smsc95xx.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/net/usb/smsc95xx.c +5 -1
@@ -1660,7 +1660,11 @@ static int smsc95xx_suspend(struct usb_interface *intf, pm_message_t message) ret =smsc95xx_enter_suspend0 (dev); done: -if (ret) +/* +* TODO: resume() might need to handle the suspend failure +* in system sleep +*/ +if (ret &&PMSG_IS_AUTO (message))usbnet_resume (intf);return ret; }
Signature · 1 line
1.7.9.5
PATCH v3 7/7 usbnet: smsc75xx: don't recover device if suspend fails in system sleep
In reply to Ming LeiIf suspend callback fails in system sleep context, usb core will ignore the failure and let system sleep go ahead further, so this patch doesn't recover device under this situation.
Also add comments on this case.
--- drivers/net/usb/smsc75xx.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/net/usb/smsc75xx.c +5 -1
@@ -2011,7 +2011,11 @@ static int smsc75xx_suspend(struct usb_interface *intf, pm_message_t message) ret =smsc75xx_enter_suspend0 (dev); done: -if (ret) +/* +* TODO: resume() might need to handle the suspend failure +* in system sleep +*/ +if (ret &&PMSG_IS_AUTO (message))usbnet_resume (intf);return ret; }
Signature · 1 line
1.7.9.5
Re: [PATCH v3 2/7] USB: serial: comments on suspend failure
In reply to Ming LeiQuoted 17 lines · Ming Lei
If suspend callback fails in system sleep context, usb core will ignore the failure and let system sleep go ahead further, so this patch comments on the case and requires that
serial->type->suspend()MUST return 0 in system sleep context.Cc Johan Hovold <[email protected]>Signed-off-by Ming Lei <[email protected]>--- drivers/usb/serial/usb-serial.c | 5 +++++ 1 file changed, 5 insertions(+)drivers/usb/serial/usb-serial.c +0
-0@@ -1140,6 +1140,11 @@ int usb_serial_suspend(struct usb_interface *intf, pm_message_t message)
drivers/usb/serial/usb-serial.c int usb_serial_suspend(struct usb_interface *intf, pm_message_t message) · line 1150
Quoted 10 lines
drivers/usb/serial/usb-serial.c +5
-0serial->suspending =1 ; +/* +* serial->type->suspend() MUST return 0 in system sleep context, +* otherwise, the resume callback has to recover device from +* previous suspend failure. +*/ if (serial->type->suspend) { r = serial->type->suspend (serial, message);if (r <0 ) {
Thanks,
Johan