mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Felipe Balbi <balbi@kernel.org>
To: Nicolas Saenz Julienne <nicolassaenzj@gmail.com>
Cc: gregkh@linuxfoundation.org, linux-usb@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] usb: dwc3: gadget: don't rely on jiffies while holding spinlock
Date: Tue, 16 Aug 2016 10:12:23 +0300	[thread overview]
Message-ID: <871t1p9oh4.fsf@linux.intel.com> (raw)
In-Reply-To: <1471290014-6815-1-git-send-email-nicolassaenzj@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1631 bytes --]


Hi,

Nicolas Saenz Julienne <nicolassaenzj@gmail.com> writes:
> __dwc3_gadget_wakeup() is called while holding a spinlock, then depends on
> jiffies in order to timeout while polling the USB core for a link state
> update. In the case the wakeup failed, the timeout will never happen and
> will also cause the cpu to stall until rcu_preempt kicks in.
>
> This switches to a "decrement variable and wait" timeout scheme.
>
> Signed-off-by: Nicolas Saenz Julienne <nicolassaenzj@gmail.com>
> ---
>  drivers/usb/dwc3/gadget.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
> index 8f8c215..d0c711f 100644
> --- a/drivers/usb/dwc3/gadget.c
> +++ b/drivers/usb/dwc3/gadget.c
> @@ -1433,7 +1433,7 @@ static int dwc3_gadget_get_frame(struct usb_gadget *g)
>  
>  static int __dwc3_gadget_wakeup(struct dwc3 *dwc)
>  {
> -	unsigned long		timeout;
> +	int			retries;
>  
>  	int			ret;
>  	u32			reg;
> @@ -1484,14 +1484,16 @@ static int __dwc3_gadget_wakeup(struct dwc3 *dwc)
>  	}
>  
>  	/* poll until Link State changes to ON */
> -	timeout = jiffies + msecs_to_jiffies(100);
> +	retries = 20000;
>  
> -	while (!time_after(jiffies, timeout)) {
> +	while (retries--) {
>  		reg = dwc3_readl(dwc->regs, DWC3_DSTS);
>  
>  		/* in HS, means ON */
>  		if (DWC3_DSTS_USBLNKST(reg) == DWC3_LINK_STATE_U0)
>  			break;
> +
> +		udelay(5);

let's just drop this udelay() here. It's very likely this will switch
the link state much quicker than 100ms anyway. Other than that, nice
catch :-)

-- 
balbi

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 818 bytes --]

      reply	other threads:[~2016-08-16  7:12 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-15 19:40 Nicolas Saenz Julienne
2016-08-16  7:12 ` Felipe Balbi [this message]

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=871t1p9oh4.fsf@linux.intel.com \
    --to=balbi@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=nicolassaenzj@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome