From patchwork Fri Nov 20 17:06: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: 7670281 Return-Path: X-Original-To: patchwork-linux-rockchip@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 6D2E5BF90C for ; Fri, 20 Nov 2015 17:07:40 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9754220340 for ; Fri, 20 Nov 2015 17:07:39 +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 CADC2200DC for ; Fri, 20 Nov 2015 17:07:38 +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 1Zzp9u-00024P-1m; Fri, 20 Nov 2015 17:07:38 +0000 Received: from mail-pa0-x22e.google.com ([2607:f8b0:400e:c03::22e]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Zzp9F-0001P0-3d for linux-rockchip@lists.infradead.org; Fri, 20 Nov 2015 17:06:58 +0000 Received: by pacdm15 with SMTP id dm15so121742885pac.3 for ; Fri, 20 Nov 2015 09:06:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id; bh=45o5/nYAZZ48szGXZSlFnvEGIlZAkvv271UHCQiWVbM=; b=NQF368DhbyQfS7tiSp9MBvgX8YrHxy2klcdg0EjA+FCue9B3u9GdlS4OAFUv1DnDIR w+mfUDfb0M8bc24xHv91lIOUZURHqkdIRv5YAfijXLF8KeBBy/OwD2QHK54qH8yS4H+/ gLNJYud1AgFOjauqze62vCwhncmBEO5Ou96aI= 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=45o5/nYAZZ48szGXZSlFnvEGIlZAkvv271UHCQiWVbM=; b=An5SSnPntZxHb5vwPlCAJnVf8DlBiOXCxfHAILdYJx6VhocgHbcGIgtlVgzZ6sffEB V7pYNBhpybQPtstxM7fD/rWcsYVeLQ1ycdlSo94MxGsQfAuBJpM0SwaAW0uM7kAKJO4C WX+2wR3cJE/GKeoWLZbZiCTe72NBQSe15jd0pXDj659krmgH6tYcA0QHH22Xj6WV8LrA kct8HmmXIugTbXg4IAsME++R2wsOZHm1c/KCvk8SWctkSQ+qOmOKbPrZ7+z8Cyc/DGYp VaIJxVGVb4m2pFApeysGfDeNk1ysoo+IbLET+0laL3sdgma3Nnn1BZggtRCvXWNh/eNk GHZg== X-Gm-Message-State: ALoCoQkGhQ6HkEn57HwcqCCafEBvuvhqwkJS7H6PgfL10VMdiweaUkE023Hxif0GTuK+qiBTM86v X-Received: by 10.67.1.103 with SMTP id bf7mr20794327pad.147.1448039195810; Fri, 20 Nov 2015 09:06:35 -0800 (PST) Received: from tictac.mtv.corp.google.com ([172.22.65.76]) by smtp.gmail.com with ESMTPSA id l9sm426241pbq.43.2015.11.20.09.06.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 20 Nov 2015 09:06:35 -0800 (PST) From: Douglas Anderson To: John Youn , balbi@ti.com Subject: [PATCH v5 1/2] usb: dwc2: host: Add missing spinlock in dwc2_hcd_reset_func() Date: Fri, 20 Nov 2015 09:06:27 -0800 Message-Id: <1448039188-14296-1-git-send-email-dianders@chromium.org> X-Mailer: git-send-email 2.6.0.rc2.230.g3dd15c0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20151120_090657_368197_A6993714 X-CRM114-Status: UNSURE ( 9.90 ) X-CRM114-Notice: Please train this message. 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 MIME-Version: 1.0 Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID,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 The dwc2_hcd_reset_func() function is only ever called directly by a delayed work function. As such no locks are already held when the function is called. Doing a read-modify-write of CPU registers and setting fields in the main hsotg data structure is a bad idea without locks. Let's add locks. The bug was found by code inspection only. It turns out that the dwc2_hcd_reset_func() is only ever called today if the "host_support_fs_ls_low_power" parameter is enabled and no code in mainline enables that parameter. Thus no known issues in mainline are fixed by this patch, but it's still probably wise to fix the function. Signed-off-by: Douglas Anderson Acked-by: John Youn --- Changes in v5: - New for v5 of the series drivers/usb/dwc2/hcd.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c index 42b6c5127618..e8924cecc83a 100644 --- a/drivers/usb/dwc2/hcd.c +++ b/drivers/usb/dwc2/hcd.c @@ -2357,13 +2357,19 @@ static void dwc2_hcd_reset_func(struct work_struct *work) { struct dwc2_hsotg *hsotg = container_of(work, struct dwc2_hsotg, reset_work.work); + unsigned long flags; u32 hprt0; dev_dbg(hsotg->dev, "USB RESET function called\n"); + + spin_lock_irqsave(&hsotg->lock, flags); + hprt0 = dwc2_read_hprt0(hsotg); hprt0 &= ~HPRT0_RST; dwc2_writel(hprt0, hsotg->regs + HPRT0); hsotg->flags.b.port_reset_change = 1; + + spin_unlock_irqrestore(&hsotg->lock, flags); } /*