mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: Duoming Zhou <duoming@zju.edu.cn>
Cc: linux-kernel@vger.kernel.org, chunfeng.yun@mediatek.com,
	matthias.bgg@gmail.com, linux-usb@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-mediatek@lists.infradead.org
Subject: Re: [PATCH] usb: mtu3: fix sleep-in-atomic-context bug caused by usleep_range()
Date: Thu, 8 Dec 2022 16:37:14 +0100	[thread overview]
Message-ID: <Y5IEqo8EeDiBnzwM@kroah.com> (raw)
In-Reply-To: <20221128063207.100596-1-duoming@zju.edu.cn>

On Mon, Nov 28, 2022 at 02:32:07PM +0800, Duoming Zhou wrote:
> The function zero_autoresume() is a timer handler that runs in
> atomic context. It is used to wake up the host connected to the
> gadget. when used by usb mtu3, the zero_autoresume() calls
> usleep_range() that can sleep. As a result, the sleep-in-atomic-
> context bug will happen. The process is shown below.
> 
>     (atomic context)
> zero_autoresume()
>   usb_gadget_wakeup()
>     mtu3_gadget_wakeup()
>       usleep_range() //sleep
> 
> This patch changes usleep_range(10000, 11000) to mdelay(10)
> in order to mitigate the bug.
> 
> Fixes: df2069acb005 ("usb: Add MediaTek USB3 DRD driver")
> Signed-off-by: Duoming Zhou <duoming@zju.edu.cn>
> ---
>  drivers/usb/mtu3/mtu3_gadget.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/mtu3/mtu3_gadget.c b/drivers/usb/mtu3/mtu3_gadget.c
> index 80236e7b089..e366c4a97d7 100644
> --- a/drivers/usb/mtu3/mtu3_gadget.c
> +++ b/drivers/usb/mtu3/mtu3_gadget.c
> @@ -468,7 +468,7 @@ static int mtu3_gadget_wakeup(struct usb_gadget *gadget)
>  	} else {
>  		mtu3_setbits(mtu->mac_base, U3D_POWER_MANAGEMENT, RESUME);
>  		spin_unlock_irqrestore(&mtu->lock, flags);
> -		usleep_range(10000, 11000);
> +		mdelay(10);
>  		spin_lock_irqsave(&mtu->lock, flags);
>  		mtu3_clrbits(mtu->mac_base, U3D_POWER_MANAGEMENT, RESUME);
>  	}
> -- 
> 2.17.1
> 

Have you tested this on real hardware?  How come the original code does
not trigger any run-time warnings?  Does your change solve the runtime
issue?

thanks,

greg k-h

      reply	other threads:[~2022-12-08 15:38 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-28  6:32 Duoming Zhou
2022-12-08 15:37 ` Greg KH [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=Y5IEqo8EeDiBnzwM@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=chunfeng.yun@mediatek.com \
    --cc=duoming@zju.edu.cn \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=matthias.bgg@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

all inboxes | Powered by JetHome®