From patchwork Mon Nov 28 06:32:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Duoming Zhou X-Patchwork-Id: 13057058 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 855EDC4321E for ; Mon, 28 Nov 2022 06:32:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229842AbiK1GcX (ORCPT ); Mon, 28 Nov 2022 01:32:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38850 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229621AbiK1GcW (ORCPT ); Mon, 28 Nov 2022 01:32:22 -0500 Received: from zju.edu.cn (spam.zju.edu.cn [61.164.42.155]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id DBA8512D35; Sun, 27 Nov 2022 22:32:20 -0800 (PST) Received: from ubuntu.localdomain (unknown [10.162.98.155]) by mail-app4 (Coremail) with SMTP id cS_KCgDHPk7oVYRjHpqaCA--.63765S2; Mon, 28 Nov 2022 14:32:15 +0800 (CST) From: Duoming Zhou To: linux-kernel@vger.kernel.org Cc: chunfeng.yun@mediatek.com, gregkh@linuxfoundation.org, matthias.bgg@gmail.com, linux-usb@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, Duoming Zhou Subject: [PATCH] usb: mtu3: fix sleep-in-atomic-context bug caused by usleep_range() Date: Mon, 28 Nov 2022 14:32:07 +0800 Message-Id: <20221128063207.100596-1-duoming@zju.edu.cn> X-Mailer: git-send-email 2.17.1 X-CM-TRANSID: cS_KCgDHPk7oVYRjHpqaCA--.63765S2 X-Coremail-Antispam: 1UD129KBjvJXoW7Aw1ftF4rWF48KrW3JF43Wr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ernel.org 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 --- 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); }