public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] usb: core: Add runtime resume checking
@ 2016-08-09  9:33 Baolin Wang
  2016-08-09 10:26 ` Greg KH
  0 siblings, 1 reply; 16+ messages in thread
From: Baolin Wang @ 2016-08-09  9:33 UTC (permalink / raw)
  To: gregkh, stefan.koch10, stern
  Cc: oneukum, falakreyaz, broonie, linux-usb, linux-kernel,
	baolin.wang

When the usb device has entered suspend state by runtime suspend method, and
the sustem also try to enter suspend state by issuing usb_dev_suspend(), it
will issue pm_runtime_resume() function to deal with wrong wakeup setting in
choose_wakeup() function.

But if usb device resumes failed due to xhci has been into suspend state and
hardware is not accessible, which will set runtime errors. Thus when there is
slave attached, usb device will resume failed by runtime resume method due to
previous runtime errors.

Then we should check if it resumes successfully in choose_wakeup() function,
if it failed we should clear the runtime errors by pm_runtime_set_suspended()
function to avoid runtime resume failure.

Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
---
 drivers/usb/core/driver.c |    9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c
index dadd1e8d..a1a0f5f 100644
--- a/drivers/usb/core/driver.c
+++ b/drivers/usb/core/driver.c
@@ -1412,6 +1412,7 @@ static int usb_resume_both(struct usb_device *udev, pm_message_t msg)
 static void choose_wakeup(struct usb_device *udev, pm_message_t msg)
 {
 	int	w;
+	int	ret;
 
 	/* Remote wakeup is needed only when we actually go to sleep.
 	 * For things like FREEZE and QUIESCE, if the device is already
@@ -1431,8 +1432,12 @@ static void choose_wakeup(struct usb_device *udev, pm_message_t msg)
 	/* If the device is autosuspended with the wrong wakeup setting,
 	 * autoresume now so the setting can be changed.
 	 */
-	if (udev->state == USB_STATE_SUSPENDED && w != udev->do_remote_wakeup)
-		pm_runtime_resume(&udev->dev);
+	if (udev->state == USB_STATE_SUSPENDED && w != udev->do_remote_wakeup) {
+		ret = pm_runtime_resume(&udev->dev);
+		if (ret == -ESHUTDOWN)
+			pm_runtime_set_suspended(&udev->dev);
+	}
+
 	udev->do_remote_wakeup = w;
 }
 
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2016-08-11  9:08 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-08-09  9:33 [PATCH] usb: core: Add runtime resume checking Baolin Wang
2016-08-09 10:26 ` Greg KH
2016-08-10  2:33   ` Baolin Wang
2016-08-10  6:18     ` Peter Chen
2016-08-10  6:43       ` Baolin Wang
2016-08-10  9:07         ` Peter Chen
2016-08-10  9:35           ` Baolin Wang
2016-08-10 14:25             ` Alan Stern
2016-08-11  3:08               ` Baolin Wang
2016-08-11  6:54                 ` Peter Chen
2016-08-11  8:07                   ` Baolin Wang
2016-08-11  8:19                     ` Peter Chen
2016-08-11  8:41                       ` Baolin Wang
2016-08-11  8:44                         ` Peter Chen
2016-08-11  9:08                           ` Baolin Wang
     [not found]     ` <20160810081707.GB7753@kroah.com>
2016-08-10  8:23       ` Baolin Wang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox