All of lore.kernel.org
 help / color / mirror / Atom feed
From: Douglas Anderson <dianders@chromium.org>
To: John Youn <John.Youn@synopsys.com>, balbi@ti.com
Cc: "Yunzhi Li" <lyz@rock-chips.com>,
	"Heiko Stübner" <heiko@sntech.de>,
	linux-rockchip@lists.infradead.org,
	"Julius Werner" <jwerner@chromium.org>,
	gregory.herrero@intel.com, yousaf.kaukab@intel.com,
	dinguyen@opensource.altera.com,
	"Douglas Anderson" <dianders@chromium.org>,
	johnyoun@synopsys.com, gregkh@linuxfoundation.org,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
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	[thread overview]
Message-ID: <1448039188-14296-1-git-send-email-dianders@chromium.org> (raw)

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 <dianders@chromium.org>
---
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);
 }
 
 /*
-- 
2.6.0.rc2.230.g3dd15c0


             reply	other threads:[~2015-11-20 17:06 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-20 17:06 Douglas Anderson [this message]
2015-11-20 17:06 ` [PATCH v5 2/2] usb: dwc2: host: Clear interrupts before handling them Douglas Anderson
2015-11-20 22:48   ` John Youn
2015-11-20 22:48     ` John Youn
2015-11-20 22:44 ` [PATCH v5 1/2] usb: dwc2: host: Add missing spinlock in dwc2_hcd_reset_func() John Youn

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1448039188-14296-1-git-send-email-dianders@chromium.org \
    --to=dianders@chromium.org \
    --cc=John.Youn@synopsys.com \
    --cc=balbi@ti.com \
    --cc=dinguyen@opensource.altera.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=gregory.herrero@intel.com \
    --cc=heiko@sntech.de \
    --cc=johnyoun@synopsys.com \
    --cc=jwerner@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rockchip@lists.infradead.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=lyz@rock-chips.com \
    --cc=yousaf.kaukab@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.