From patchwork Wed Aug 10 08:44:33 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "\(Exiting\) Baolin Wang" X-Patchwork-Id: 73689 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp558012qga; Wed, 10 Aug 2016 12:22:03 -0700 (PDT) X-Received: by 10.98.204.74 with SMTP id a71mr9938373pfg.149.1470856922589; Wed, 10 Aug 2016 12:22:02 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l190si49824299pfc.25.2016.08.10.12.22.02; Wed, 10 Aug 2016 12:22:02 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-usb-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-usb-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-usb-owner@vger.kernel.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S941005AbcHJTVx (ORCPT + 4 others); Wed, 10 Aug 2016 15:21:53 -0400 Received: from mail-pa0-f51.google.com ([209.85.220.51]:36552 "EHLO mail-pa0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S938775AbcHJTVv (ORCPT ); Wed, 10 Aug 2016 15:21:51 -0400 Received: by mail-pa0-f51.google.com with SMTP id pp5so18367946pac.3 for ; Wed, 10 Aug 2016 12:21:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=0rfCg5YDDStajZcjNY4gIIaKCmaV8dxqHWe8TewDVo0=; b=MwzSUVN1cOKD6Lej6M4aFUz9m1NbTbNCT/TxJ7QCWzOPVTWYodXeBXFX5nYnnPCBiV hk9O+6fYSJE0MhaZWmDwM0i62ThkVlzYHeqKGfbLUJdLp5U2dNjz9dWev2s4t8Nhr34n fHxNGTA15pziErcKvPxRROeojcZ1Pw6MJOWR8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=0rfCg5YDDStajZcjNY4gIIaKCmaV8dxqHWe8TewDVo0=; b=Rk833K0G2L5BqMdbyKz5un/FbsEqhd+AAzEaL7pw7XD7VNkgEzz0HLvg0eWuFZVDGw PwbMzcv4gYbrfYMlM6p1wt99ktuSxdcyywCSbJhyn9WK8FhDXPSJZuaCGvTVeQYhqwSA D6i9/tGms4FzkthSnPJIkUnVslrPMkh19FtRIou1kxJ8kMdR6KUmLOl7KBF4fuEqitAv 5KZXeluCsWOu1xrgyPMEvigGMI+Gi9nQEsNhvMDREh64uGv071kDsGbaxL+nZFTB817T hJgT1f2/W/IaqZ76vuqO4DHWRr/NJtcnXn21q85u4I7XkA4t2cFTlYJ7xHk+vTw0kBqT DfdA== X-Gm-Message-State: AEkoousbE9cv62flj6lUzR0kCIQkOC1GQKsgR6NthEKJf9XDMG46ifTUVbvq0tJp9/V5R3UY X-Received: by 10.66.161.195 with SMTP id xu3mr5092578pab.68.1470818726895; Wed, 10 Aug 2016 01:45:26 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([175.111.195.49]) by smtp.gmail.com with ESMTPSA id i62sm61776918pfg.62.2016.08.10.01.45.24 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 10 Aug 2016 01:45:26 -0700 (PDT) From: Baolin Wang To: gregkh@linuxfoundation.org, stefan.koch10@gmail.com, stern@rowland.harvard.edu Cc: oneukum@suse.com, falakreyaz@gmail.com, broonie@kernel.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, baolin.wang@linaro.org Subject: [PATCH v2] usb: core: Add runtime resume checking in choose_wakeup() Date: Wed, 10 Aug 2016 16:44:33 +0800 Message-Id: <68eefd026795581f9da19f9f184038a992d81988.1470818529.git.baolin.wang@linaro.org> X-Mailer: git-send-email 1.7.9.5 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Considering strict power management for mobile device, we should also power off the usb controller if there are no slaves attached even though it is usb host function, but it will meet usb device resume failure in below situation. Suppose that no slave attached ----> usb interface runtime suspend ----> usb device runtime suspend -----> xhci suspend -----> power off usb controller. After that if the system wants to enter suspend state, then it also will issue usb_dev_suspend(), then the pm_runtime_resume() issued in choose_wakeup() function will return '-ESHUTDOWN' due to xhci has been suspend and hardware is not accessible. After system entering resume state, if there is slave attached ----> power on usb controller ----> xhci resume ----> usb device runtime resume ----> usb interface runtime resume. But usb device will resume failed if runtime errors is set ('-ESHUTDOWN'), thus we should clear the runtime errors in choose_wakeup() function to avoid this situation. Signed-off-by: Baolin Wang --- changes since v1: - Modify the changelog to explain clearly. - Remove 'ret' variable in choose_wakeup(). --- drivers/usb/core/driver.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) -- 1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c index dadd1e8d..bce283c 100644 --- a/drivers/usb/core/driver.c +++ b/drivers/usb/core/driver.c @@ -1431,8 +1431,11 @@ 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) { + if (pm_runtime_resume(&udev->dev) == -ESHUTDOWN) + pm_runtime_set_suspended(&udev->dev); + } + udev->do_remote_wakeup = w; }