From patchwork Thu Mar 12 08:57:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Chen X-Patchwork-Id: 11433593 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9132013B1 for ; Thu, 12 Mar 2020 08:58:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 73387206FA for ; Thu, 12 Mar 2020 08:58:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1584003483; bh=N1uJJrbgyXSqWS05kgvyJwAxqg99mthFz14GgjyFCAk=; h=From:To:Cc:Subject:Date:List-ID:From; b=jSs1mZZ+oi79NkyMqV/nCeIxG8/Fgk6tYAj/gXjwjT/YYukG9IOMyVZJWs6W7r9l1 6uDnMnxkzXO32kBByffAbA4wvYRV2hfOytb/oia274ryZQY1Xx1x3e5zzeZ0wobb+K /Am+YjePG6usuqMf1T1nQIFwm4tO3Si4RaxMM19U= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726099AbgCLI6C (ORCPT ); Thu, 12 Mar 2020 04:58:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:38626 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725978AbgCLI6C (ORCPT ); Thu, 12 Mar 2020 04:58:02 -0400 Received: from localhost.localdomain (unknown [180.171.74.255]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4778420578; Thu, 12 Mar 2020 08:57:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1584003481; bh=N1uJJrbgyXSqWS05kgvyJwAxqg99mthFz14GgjyFCAk=; h=From:To:Cc:Subject:Date:From; b=STntgs2ovx2H5XafYOteqPLR3EujEBKjnUKWkfur/tL6ra+lEYa1o0NJ20Kj2Uuzd KHCXre56FOsjG7nrM6ZgR3gN0WLjFGB+w7mKPDjuItGUXnRdhyQN91vIUPsVoJ0u2H hBxmBSrjxqDYBNTVn85Bt0l8TZ8qiSsVTsemP3Wc= From: Peter Chen To: linux-usb@vger.kernel.org Cc: linux-imx@nxp.com, jun.li@nxp.com, Peter Chen , stable@vger.kernel.org Subject: [PATCH v2 1/1] usb: chipidea: udc: fix sleeping function called from invalid context Date: Thu, 12 Mar 2020 16:57:43 +0800 Message-Id: <20200312085743.10260-1-peter.chen@kernel.org> X-Mailer: git-send-email 2.17.1 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: Peter Chen The code calls pm_runtime_get_sync with irq disabled, it causes below warning: BUG: sleeping function called from invalid context at wer/runtime.c:1075 in_atomic(): 1, irqs_disabled(): 128, non_block: 0, pid: er/u8:1 CPU: 1 PID: 37 Comm: kworker/u8:1 Not tainted 20200304-00181-gbebfd2a5be98 #1588 Hardware name: NVIDIA Tegra SoC (Flattened Device Tree) Workqueue: ci_otg ci_otg_work [] (unwind_backtrace) from [] 1/0x14) [] (show_stack) from [] 5/0x94) [] (dump_stack) from [] +0xeb/0x118) [] (___might_sleep) from [] esume+0x75/0x78) [] (__pm_runtime_resume) from [] 0x23/0x74) [] (ci_udc_pullup) from [] nect+0x2b/0xcc) [] (usb_gadget_connect) from [] _connect+0x59/0x104) [] (ci_hdrc_gadget_connect) from [] ssion+0x43/0x48) [] (ci_udc_vbus_session) from [] s_connect+0x17/0x9c) [] (usb_gadget_vbus_connect) from [] bd/0x128) [] (ci_otg_work) from [] rk+0x149/0x404) [] (process_one_work) from [] 0xf7/0x3bc) [] (worker_thread) from [] x118) [] (kthread) from [] (ret_from_fork+0x11/0x34) Tested-by: Dmitry Osipenko Cc: #v5.5 Fixes: 72dc8df7920f ("usb: chipidea: udc: protect usb interrupt enable") Reported-by: Dmitry Osipenko Signed-off-by: Peter Chen --- Changes for v2: - Change spin_lock_irqsave to spin_lock_irq since the code is running at process context drivers/usb/chipidea/udc.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c index ffaf46f5d062..4c4ac30db498 100644 --- a/drivers/usb/chipidea/udc.c +++ b/drivers/usb/chipidea/udc.c @@ -1530,18 +1530,19 @@ static const struct usb_ep_ops usb_ep_ops = { static void ci_hdrc_gadget_connect(struct usb_gadget *_gadget, int is_active) { struct ci_hdrc *ci = container_of(_gadget, struct ci_hdrc, gadget); - unsigned long flags; if (is_active) { pm_runtime_get_sync(&_gadget->dev); hw_device_reset(ci); - spin_lock_irqsave(&ci->lock, flags); + spin_lock_irq(&ci->lock); if (ci->driver) { hw_device_state(ci, ci->ep0out->qh.dma); usb_gadget_set_state(_gadget, USB_STATE_POWERED); + spin_unlock_irq(&ci->lock); usb_udc_vbus_handler(_gadget, true); + } else { + spin_unlock_irq(&ci->lock); } - spin_unlock_irqrestore(&ci->lock, flags); } else { usb_udc_vbus_handler(_gadget, false); if (ci->driver)