Skip to contentSkip to conversation

USB: don't recover device if suspend fails in system sleep

PATCH Superseded Ming Lei 8 participants 17 messages Mar 7, 2013 – Mar 15, 2013 1 message not in the archive

Subsystems (11)
Networking Network drivers USB HID +7 more subsystems

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Ming Lei

author
#0 lore raw

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

A message that is not in the archive (sent off-list or not yet received): 1362672924-22975-1-git-send-email-ming.lei-Z7WLFzj8eWMS+FvcfC7Uqw@public.gmane.org

#2 lore raw

PATCH v2 1/7 USB: adds comment on suspend callback

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.

---
 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
index d938b2b..eb1d00a 100644
@@ -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
index 4d22d0f..f82ce57 100644
@@ -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
Acked-by on v2 1/7
#3 lore raw

Re: [PATCH v2 1/7] USB: adds comment on suspend callback

Quoted 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.

---
 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
index d938b2b..eb1d00a 100644
@@ -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
index 4d22d0f..f82ce57 100644
@@ -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.
#4 lore raw

PATCH v2 4/7 usbnet: cdc_mbim: comments on suspend failure

In reply to a message not in the archive

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() 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
index 248d2dc..406a34d 100644
@@ -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
maintainer Acked-by on v2 4/7
#5 lore raw

Re: [PATCH v2 4/7] usbnet: cdc_mbim: comments on suspend failure

Quoted 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() 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 +0 -0
index 248d2dc..406a34d 100644
@@ -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

#6 lore raw

PATCH v2 5/7 usbnet: qmi_wwan: comments on suspend failure

In reply to a message not in the archive

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() 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
index efb5c7c..8a60bdd 100644
@@ -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
maintainer Acked-by on v2 5/7
#7 lore raw

Re: [PATCH v2 5/7] usbnet: qmi_wwan: comments on suspend failure

Quoted 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() 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 +0 -0
index efb5c7c..8a60bdd 100644
@@ -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 -0
 	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;

--
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

author
#8 lore raw

PATCH v2 2/7 USB: serial: handle suspend failure path correctly

In reply to Ming Lei

This 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.

Cc Johan Hovold <[email protected]>
---
 drivers/usb/serial/usb-serial.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/usb/serial/usb-serial.c +2 -1
index a19ed74..9d0b9c8 100644
@@ -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
#9 lore raw

Re: [PATCH v2 2/7] USB: serial: handle suspend failure path correctly

Quoted 19 lines · Ming Lei

This 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.

Cc Johan Hovold <[email protected]>
---
 drivers/usb/serial/usb-serial.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/usb/serial/usb-serial.c +0 -0
index a19ed74..9d0b9c8 100644
@@ -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 -1
 		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) {

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

author
#10 lore raw

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->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.

Cc Johan Hovold <[email protected]>
---
 drivers/usb/serial/usb-serial.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/usb/serial/usb-serial.c +0 -0
index a19ed74..9d0b9c8 100644
@@ -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 -1
              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) {

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_mbim and qmi_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

author
#11 lore raw

PATCH v2 3/7 USBHID: don't recover device if suspend fails in system sleep

In reply to 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.

---
 drivers/hid/usbhid/hid-core.c |   14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)
drivers/hid/usbhid/hid-core.c +5 -9
index 8e0c4bf94..1f9e56b 100644
@@ -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
Acked-by on v2 3/7
#12 lore raw

Re: [PATCH v2 3/7] USBHID: don't recover device if suspend fails in system sleep

Quoted 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.

I guess this will go through USB tree as a series ...

Thanks,

Signature · 2 lines
Jiri Kosina
SUSE Labs
#13 lore raw

Re: [PATCH v2 3/7] USBHID: don't recover device if suspend fails in system sleep

Quoted 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

I guess this will go through USB tree as a series ...

Yes, I can take this, thanks for the ack.

greg k-h

author
#14 lore raw

PATCH v2 6/7 usbnet: smsc95xx: don't recover device if suspend fails in system sleep

In reply to 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 doesn't recover device under this situation.

Also add comments on the case.

Cc Steve Glendinning <[email protected]>
---
 drivers/net/usb/smsc95xx.c |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/net/usb/smsc95xx.c +5 -1
index e6d2dea..3f38ba8 100644
@@ -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
author
#15 lore raw

PATCH v2 7/7 usbnet: smsc75xx: don't recover device if suspend fails in system sleep

In reply to 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 doesn't recover device under this situation.

Also add comments on this case.

Cc Steve Glendinning <[email protected]>
---
 drivers/net/usb/smsc75xx.c |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/net/usb/smsc75xx.c +5 -1
index 9abe517..21b607a 100644
@@ -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
maintainer Acked-by on the v2 series
#16 lore raw
In reply to Ming Lei

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 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()

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

maintainer
#17 lore raw
Quoted 23 lines · David Miller

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 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()

Quoted 4 lines

Feel free to merge this via the USB tree and to add my ACK to the networking driver bits:

Thanks, I will do that.

greg k-h