USB: don't recover device if suspend fails in system sleep
Subsystems (11)
v2 cover USB: don't recover device if suspend fails in system sleep
Hi,
Sorry for my broken email client just now.
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 the USB serial, HID and several usbnet drivers which may recover device in suspend failure path of system sleep.
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 | 3 ++- include/linux/usb.h | 7 ++++++- 8 files changed, 41 insertions(+), 16 deletions(-)
Thanks,
--
Ming Lei
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v2 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 v2 2/7 USB: serial: handle suspend failure path correctly
In reply to Ming LeiThis patch kills traffic even though type->suspend returns failure inside usb_serial_suspend from system sleep context because USB core ignores the failiure and lets system sleep go ahread, so the serial URB traffic need to be killed in this case.
--- drivers/usb/serial/usb-serial.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/usb/serial/usb-serial.c +2 -1
@@ -1142,10 +1142,11 @@ int usb_serial_suspend(struct usb_interface *intf, pm_message_t message)if (serial->type->suspend) { r = serial->type->suspend (serial, message); -if (r <0 ) { +if (r <0 &&PMSG_IS_AUTO (message)) { serial->suspending =0 ; goto err_out; } +/* TODO: resume() might need to handle suspend failure */ }for (i =0 ; i < serial->num_ports; ++i) {
Signature · 1 line
1.7.9.5
PATCH v2 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
@@ -1493,7 +1493,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)) {
@@ -1520,19 +1520,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);
@@ -1544,7 +1540,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 v2 4/7 usbnet: cdc_mbim: 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/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 · 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 v2 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
@@ -288,6 +288,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 v2 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 v2 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 v2 4/7] usbnet: cdc_mbim: comments on suspend failure
In reply to Ming LeiQuoted 18 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 both
usbnet_suspend()andsubdriver->suspend()MUST return 0 in system sleep context.Cc Bjørn Mork <[email protected]>Signed-off-by Ming Lei <[email protected]>--- drivers/net/usb/cdc_mbim.c | 5 +++++ 1 file changed, 5 insertions(+)drivers/net/usb/cdc_mbim.c +0
-0@@ -332,6 +332,11 @@ static int cdc_mbim_suspend(struct usb_interface *intf, pm_message_t message) goto error;
drivers/net/usb/cdc_mbim.c static int cdc_mbim_suspend(struct usb_interface *intf, pm_message_t message) · line 342
Quoted 10 lines
drivers/net/usb/cdc_mbim.c +5
-0} +/* +* 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;
Looks fine. Thanks
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v2 5/7] usbnet: qmi_wwan: comments on suspend failure
In reply to Ming LeiQuoted 18 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 both
usbnet_suspend()andsubdriver->suspend()MUST return 0 in system sleep context.Cc Bjørn Mork <[email protected]>Signed-off-by Ming Lei <[email protected]>--- drivers/net/usb/qmi_wwan.c | 5 +++++ 1 file changed, 5 insertions(+)drivers/net/usb/qmi_wwan.c +0
-0@@ -288,6 +288,11 @@ static int qmi_wwan_suspend(struct usb_interface *intf, pm_message_t message)struct qmi_wwan_state *info = (void *)&dev->data;
drivers/net/usb/qmi_wwan.c static int qmi_wwan_suspend(struct usb_interface *intf, pm_message_t message) · line 298
Quoted 10 lines
drivers/net/usb/qmi_wwan.c +5
-0int 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;
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v2 1/7] USB: adds comment on suspend callback
In reply to Ming LeiQuoted 45 lines · Ming Lei
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 and let resume/reset_resume callback handle the suspend failure if needed.
Also kerneldoc for
usb_suspend_both()is updated with the fact.Signed-off-by Ming Lei <[email protected]>--- 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 +0
-0@@ -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.
include/linux/usb.h struct usbdrv_wrap { · line 989
Quoted 10 lines
include/linux/usb.h +6
-1-* @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.
From: Ming Lei <[email protected]>
Date: Fri, 8 Mar 2013 00:15:17 +0800
Quoted 9 lines
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 the USB serial, HID and several usbnet drivers which may recover device in suspend failure path of system sleep.
Quoted 10 lines
v2:
- improve comments on suspend callback as suggested by Alan
- update kerneldoc forusb_suspend_bothas suggested by Alan
- remove previous check ofPMSG_IS_AUTO(message)in cdc_mbim/qmi_wwanand 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 inresume()
Feel free to merge this via the USB tree and to add my ACK to the networking driver bits:
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v2 3/7] USBHID: don't recover device if suspend fails in system sleep
In reply to Ming LeiQuoted 7 lines · Ming Lei
If 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.Cc Jiri Kosina <[email protected]>Signed-off-by Ming Lei <[email protected]>
I guess this will go through USB tree as a series ...
Thanks,
Signature · 2 lines
Jiri Kosina SUSE Labs
Greg KH
maintainerQuoted 23 lines · David Miller
From: Ming Lei <[email protected]>
Date: Fri, 8 Mar 2013 00:15:17 +0800Quoted 9 lines
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 the USB serial, HID and several usbnet drivers which may recover device in suspend failure path of system sleep.
Quoted 10 lines
v2:
- improve comments on suspend callback as suggested by Alan
- update kerneldoc forusb_suspend_bothas suggested by Alan
- remove previous check ofPMSG_IS_AUTO(message)in cdc_mbim/qmi_wwanand 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 inresume()
Quoted 4 lines
Feel free to merge this via the USB tree and to add my ACK to the networking driver bits:
Acked-by David S. Miller <[email protected]>
Thanks, I will do that.
greg k-h
Greg Kroah-Hartman
maintainerRe: [PATCH v2 3/7] USBHID: don't recover device if suspend fails in system sleep
In reply to Jiri KosinaQuoted 7 lines · Jiri Kosina
Quoted 5 lines · Ming Lei
If 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.
Quoted 6 lines
Quoted 2 lines
Cc Jiri Kosina <[email protected]>Signed-off-by Ming Lei <[email protected]>Acked-by Jiri Kosina <[email protected]>I guess this will go through USB tree as a series ...
Yes, I can take this, thanks for the ack.
greg k-h
Re: [PATCH v2 2/7] USB: serial: handle suspend failure path correctly
In reply to Ming LeiQuoted 19 lines · Ming Lei
This patch kills traffic even though
type->suspendreturns failure insideusb_serial_suspendfrom system sleep context because USB core ignores the failiure and lets system sleep go ahread, so the serial URB traffic need to be killed in this case.Cc Johan Hovold <[email protected]>Signed-off-by Ming Lei <[email protected]>--- drivers/usb/serial/usb-serial.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/usb/serial/usb-serial.c +0
-0@@ -1142,10 +1142,11 @@ int usb_serial_suspend(struct usb_interface *intf, pm_message_t message)if (serial->type->suspend) {
drivers/usb/serial/usb-serial.c int usb_serial_suspend(struct usb_interface *intf, pm_message_t message) · line 1152
Quoted 10 lines
drivers/usb/serial/usb-serial.c +2
-1r = serial->type->suspend (serial, message); -if (r <0 ) { +if (r <0 &&PMSG_IS_AUTO (message)) { serial->suspending =0 ; goto err_out; } +/* TODO: resume() might need to handle suspend failure */ }for (i =0 ; i < serial->num_ports; ++i) {
Sorry for the late reply.
The usb-serial subdriver suspend callbacks do not and must not return non-zero if !PMSG_IS_AUTO(message) so adding code to handle that case merely obfuscates this fact.
I'd rather see this documented with a comment just as Bjørn suggested for cdc_mbim and qmi_wwan.
Thanks,
Johan
Re: [PATCH v2 2/7] USB: serial: handle suspend failure path correctly
Quoted 33 lines · Johan Hovold
Quoted 19 lines · Ming Lei
This patch kills traffic even though
type->suspendreturns failure insideusb_serial_suspendfrom system sleep context because USB core ignores the failiure and lets system sleep go ahread, so the serial URB traffic need to be killed in this case.Cc Johan Hovold <[email protected]>Signed-off-by Ming Lei <[email protected]>--- drivers/usb/serial/usb-serial.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/usb/serial/usb-serial.c +0
-0@@ -1142,10 +1142,11 @@ int usb_serial_suspend(struct usb_interface *intf, pm_message_t message)if (serial->type->suspend) {drivers/usb/serial/usb-serial.c int usb_serial_suspend(struct usb_interface *intf, pm_message_t message) · line 1152
Quoted 10 lines
drivers/usb/serial/usb-serial.c +2
-1r = serial->type->suspend (serial, message); -if (r <0 ) { +if (r <0 &&PMSG_IS_AUTO (message)) { serial->suspending =0 ; goto err_out; } +/* TODO: resume() might need to handle suspend failure */ }for (i =0 ; i < serial->num_ports; ++i) {Sorry for the late reply.
Quoted 6 lines
The usb-serial subdriver suspend callbacks do not and must not return non-zero if !PMSG_IS_AUTO(message) so adding code to handle that case merely obfuscates this fact.
I'd rather see this documented with a comment just as Bjørn suggested for
cdc_mbimandqmi_wwan.
No problem, will do it in v3.
Thanks,
--
Ming Lei
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html