From patchwork Thu Mar 5 01:55:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Chen X-Patchwork-Id: 11421063 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 04DDC92A for ; Thu, 5 Mar 2020 01:55:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CE7FF20866 for ; Thu, 5 Mar 2020 01:55:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583373318; bh=7G3sJ/cyj1mXIFuR/9IYeXvkuabmRFg/mlqG0lPn/Fw=; h=From:To:Cc:Subject:Date:List-ID:From; b=o0wVSdmGJ00fji2vtlOq7snYU6c4W0KYT20VbENPDpRSJZpydcr7tsjBkf7veTQGM pj/wKQCSDToOkFWHBhQGdan0rnIYaFK5SRXuGG6+1InA8o9s4j+ZbepBiwduAqVHN9 FftRloOQidcsnlLwGdoXwMpOd3v3UBvMzf1YhVT0= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725880AbgCEBzR (ORCPT ); Wed, 4 Mar 2020 20:55:17 -0500 Received: from mail.kernel.org ([198.145.29.99]:39266 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725773AbgCEBzR (ORCPT ); Wed, 4 Mar 2020 20:55:17 -0500 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 A5E6C20848; Thu, 5 Mar 2020 01:55:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583373317; bh=7G3sJ/cyj1mXIFuR/9IYeXvkuabmRFg/mlqG0lPn/Fw=; h=From:To:Cc:Subject:Date:From; b=arZxgAGlP5rBopeW46AFf2SW1rBZuGViQYETf1s2isVNfMI1TD39JzOnrmVOhIGq0 bA9w6K7AFzWuQq5dxTusTMWZYRajawUzgfPv3IFHxTlN2zWKxqosAiBSm2H3Sd3f+l fDOrGu3Pj7IXHjru9N9RjAMf03uGRYhB0KGLp+gc= 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 1/1] usb: chipidea: udc: fix sleeping function called from invalid context Date: Thu, 5 Mar 2020 09:55:02 +0800 Message-Id: <20200305015502.28927-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) Cc: #v5.5 Fixes: 72dc8df7920f ("usb: chipidea: udc: protect usb interrupt enable") Reported-by: Dmitry Osipenko Signed-off-by: Peter Chen Tested-by: Dmitry Osipenko --- drivers/usb/chipidea/udc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c index 94feaecc6059..9d74fe856ce8 100644 --- a/drivers/usb/chipidea/udc.c +++ b/drivers/usb/chipidea/udc.c @@ -1601,9 +1601,11 @@ static void ci_hdrc_gadget_connect(struct usb_gadget *_gadget, int is_active) if (ci->driver) { hw_device_state(ci, ci->ep0out->qh.dma); usb_gadget_set_state(_gadget, USB_STATE_POWERED); + spin_unlock_irqrestore(&ci->lock, flags); usb_udc_vbus_handler(_gadget, true); + } else { + spin_unlock_irqrestore(&ci->lock, flags); } - spin_unlock_irqrestore(&ci->lock, flags); } else { usb_udc_vbus_handler(_gadget, false); if (ci->driver)