From patchwork Wed Oct 14 22:58:27 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 7398951 Return-Path: X-Original-To: patchwork-linux-rockchip@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 0DA9F9F36A for ; Wed, 14 Oct 2015 22:59:15 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 35ECC2099F for ; Wed, 14 Oct 2015 22:59:14 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6299620992 for ; Wed, 14 Oct 2015 22:59:13 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZmV0q-0001Hp-NB; Wed, 14 Oct 2015 22:59:12 +0000 Received: from mail-pa0-x22a.google.com ([2607:f8b0:400e:c03::22a]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZmV0o-0001GG-FO for linux-rockchip@lists.infradead.org; Wed, 14 Oct 2015 22:59:11 +0000 Received: by pabws5 with SMTP id ws5so2896704pab.3 for ; Wed, 14 Oct 2015 15:58:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version:content-type :content-transfer-encoding; bh=LEcbQAYEtfL7GECZsnXA58NwNFRft1CCZX5HUCQgC/4=; b=ANFYFjwNkBR2yuEsXQLa/5UC/7UpMdIpEWhPFzF67Oghbu7mEhpszzuGDiBCPqz0Xl cJm8KAP5Hmc3KG7vMRuAcm1DRS1Qoocr3JqSaM4VzwjSVwV8BqdtiYb8e0f4AHG00IwD isBLqm5WaymoJ0k2AUcPrZnzNylInlwE9I2Cw= 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:mime-version :content-type:content-transfer-encoding; bh=LEcbQAYEtfL7GECZsnXA58NwNFRft1CCZX5HUCQgC/4=; b=dMzfBYmuEirIAasE1jH5gmMnR9BXxbkyYlwpizxe2czV2V7XSM0UwtDlHr/lUJY+BC xV0MExdSCxN0N9vg6jqkrW54my+UulB/c9NUaC7r0xmeDv9oAEENKc+w9crEw8eiJpi1 zn1VhtqA5HpVhK/mi8du2WauFIV6nQ0KAs0EFdBi0toJJPoXu56yP6UFPBUX/5+Wk51T 4fIf5q93EtmBs9YlN7IJ8moOJy9VhPQyM9Dp+8FkWImlvRlpdfWdtqRJGC26bc57NGWI Vbb7sny+NPvof0xH4Y5O11XABR6LjiGWmwpc8F9YtC+x7rjULB8T9W/AspncfSLzpxTO 1R4g== X-Gm-Message-State: ALoCoQlwtWvaiNP/GYfknIEfQ/VTuF5FSZNMjbs8mTBSWtM5Kpbcf7+AXOPj+vjF3NmHBdGlvPhI X-Received: by 10.68.243.37 with SMTP id wv5mr6183439pbc.68.1444863529264; Wed, 14 Oct 2015 15:58:49 -0700 (PDT) Received: from tictac.mtv.corp.google.com ([172.22.65.76]) by smtp.gmail.com with ESMTPSA id or6sm11633550pac.32.2015.10.14.15.58.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 14 Oct 2015 15:58:48 -0700 (PDT) From: Douglas Anderson To: John Youn , balbi@ti.com Subject: [PATCH] usb: dwc2: host: Protect PCGCTL with lock in dwc2_port_resume() Date: Wed, 14 Oct 2015 15:58:27 -0700 Message-Id: <1444863507-27463-1-git-send-email-dianders@chromium.org> X-Mailer: git-send-email 2.6.0.rc2.230.g3dd15c0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20151014_155910_558457_413FBC7D X-CRM114-Status: GOOD ( 10.40 ) X-Spam-Score: -2.7 (--) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: gregory.herrero@intel.com, =?UTF-8?q?Heiko=20St=C3=BCbner?= , johnyoun@synopsys.com, gregkh@linuxfoundation.org, linux-usb@vger.kernel.org, Douglas Anderson , linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, yousaf.kaukab@intel.com, Yunzhi Li , Julius Werner , dinguyen@opensource.altera.com Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From code inspection, it appears to be unsafe to do a read-modify-write of PCGCTL in dwc2_port_resume(). Let's make sure the spinlock is held around this operation. Signed-off-by: Douglas Anderson Acked-by: John Youn --- drivers/usb/dwc2/hcd.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c index af4e4a2..e79baf7 100644 --- a/drivers/usb/dwc2/hcd.c +++ b/drivers/usb/dwc2/hcd.c @@ -1500,6 +1500,8 @@ static void dwc2_port_resume(struct dwc2_hsotg *hsotg) u32 hprt0; u32 pcgctl; + spin_lock_irqsave(&hsotg->lock, flags); + /* * If hibernation is supported, Phy clock is already resumed * after registers restore. @@ -1508,10 +1510,11 @@ static void dwc2_port_resume(struct dwc2_hsotg *hsotg) pcgctl = dwc2_readl(hsotg->regs + PCGCTL); pcgctl &= ~PCGCTL_STOPPCLK; dwc2_writel(pcgctl, hsotg->regs + PCGCTL); + spin_unlock_irqrestore(&hsotg->lock, flags); usleep_range(20000, 40000); + spin_lock_irqsave(&hsotg->lock, flags); } - spin_lock_irqsave(&hsotg->lock, flags); hprt0 = dwc2_read_hprt0(hsotg); hprt0 |= HPRT0_RES; hprt0 &= ~HPRT0_SUSP;