From patchwork Fri Aug 12 14:38:51 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: vikram pandita X-Patchwork-Id: 1061282 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.4) with ESMTP id p7CEd1TS030799 for ; Fri, 12 Aug 2011 14:39:01 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753457Ab1HLOi5 (ORCPT ); Fri, 12 Aug 2011 10:38:57 -0400 Received: from devils.ext.ti.com ([198.47.26.153]:40693 "EHLO devils.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752702Ab1HLOi4 (ORCPT ); Fri, 12 Aug 2011 10:38:56 -0400 Received: from dlep33.itg.ti.com ([157.170.170.112]) by devils.ext.ti.com (8.13.7/8.13.7) with ESMTP id p7CEcttP017677 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 12 Aug 2011 09:38:56 -0500 Received: from DFLE71.ent.ti.com (smtp-le.itg.ti.com [157.170.170.27]) by dlep33.itg.ti.com (8.13.7/8.13.8) with ESMTP id p7CEctom023528; Fri, 12 Aug 2011 09:38:55 -0500 (CDT) Received: from dlelxv23.itg.ti.com (172.17.1.198) by dfle71.ent.ti.com (128.247.5.62) with Microsoft SMTP Server id 14.1.323.3; Fri, 12 Aug 2011 09:38:55 -0500 Received: from legion.dal.design.ti.com (legion.dal.design.ti.com [128.247.22.53]) by dlelxv23.itg.ti.com (8.13.8/8.13.8) with ESMTP id p7CEcter009462; Fri, 12 Aug 2011 09:38:55 -0500 Received: from localhost (h56-133.vpn.ti.com [172.24.56.133]) by legion.dal.design.ti.com (8.11.7p1+Sun/8.11.7) with ESMTP id p7CEcsf24859; Fri, 12 Aug 2011 09:38:54 -0500 (CDT) From: Vikram Pandita To: , CC: , , , Vikram Pandita , Moiz Sonasath Subject: [PATCH] usb: musb: fix pm_runtime calls while atomic Date: Fri, 12 Aug 2011 07:38:51 -0700 Message-ID: <1313159931-22121-1-git-send-email-vikram.pandita@ti.com> X-Mailer: git-send-email 1.7.4.1 MIME-Version: 1.0 Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Fri, 12 Aug 2011 14:39:01 +0000 (UTC) From: Vikram Pandita musb pm_runtime_get_sync call happens in intrrupt context on cable attach case That can result in re-enabling the interrupts and cause side affects. So move the code to a work queue. Following is the error path hit on cable attach: BUG: sleeping function called from invalid context at drivers/base/power/runtime.c:802 in_atomic(): 0, irqs_disabled(): 0, pid: 18, name: irq/378-twl6030 Backtrace: [] (dump_backtrace+0x0/0x110) from [] (dump_stack+0x18/0x1c) [] (dump_stack+0x0/0x1c) from [] (__might_sleep+0x130/0x134) [] (__might_sleep+0x0/0x134) from [] (__pm_runtime_resume+0x94/0x98) [] (__pm_runtime_resume+0x0/0x98) from [] (musb_otg_notifications+0x9c/0x164) [] (musb_otg_notifications+0x0/0x164) from [] (notifier_call_chain+0x4c/0x8c) [] (notifier_call_chain+0x0/0x8c) from [] (__atomic_notifier_call_chain+0x40/0x54) [] (__atomic_notifier_call_chain+0x0/0x54) from [] (atomic_notifier_call_chain+0x20/0x28) [] (atomic_notifier_call_chain+0x0/0x28) from [] (twl6030_usb_irq+0xc8/0xdc) [] (twl6030_usb_irq+0x0/0xdc) from [] (irq_thread_fn+0x24/0x40) [] (irq_thread_fn+0x0/0x40) from [] (irq_thread+0x150/0x1d8) [] (irq_thread+0x0/0x1d8) from [] (kthread+0x94/0x98) [] (kthread+0x0/0x98) from [] (do_exit+0x0/0x720) Tested with: MUSB Device mode: Cold boot / Hot plug MUSB Host mode: Cold boot / Hot plug Signed-off-by: Vikram Pandita Signed-off-by: Moiz Sonasath Signed-off-by: Vikram Pandita --- drivers/usb/musb/musb_core.h | 2 ++ drivers/usb/musb/omap2430.c | 14 +++++++++++++- 2 files changed, 15 insertions(+), 1 deletions(-) diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h index 0e053b5..ff47316 100644 --- a/drivers/usb/musb/musb_core.h +++ b/drivers/usb/musb/musb_core.h @@ -386,6 +386,7 @@ struct musb { irqreturn_t (*isr)(int, void *); struct work_struct irq_work; + struct work_struct otg_notifier_work; u16 hwvers; /* this hub status bit is reserved by USB 2.0 and not seen by usbcore */ @@ -432,6 +433,7 @@ struct musb { u16 int_tx; struct otg_transceiver *xceiv; + u8 xceiv_event; int nIrq; unsigned irq_wake:1; diff --git a/drivers/usb/musb/omap2430.c b/drivers/usb/musb/omap2430.c index c5d4c44..3026673 100644 --- a/drivers/usb/musb/omap2430.c +++ b/drivers/usb/musb/omap2430.c @@ -234,11 +234,21 @@ static int musb_otg_notifications(struct notifier_block *nb, unsigned long event, void *unused) { struct musb *musb = container_of(nb, struct musb, nb); + + musb->xceiv_event = event; + schedule_work(&musb->otg_notifier_work); + + return 0; +} + +static void musb_otg_notifier_work(struct work_struct *data_notifier_work) +{ + struct musb *musb = container_of(data_notifier_work, struct musb, otg_notifier_work); struct device *dev = musb->controller; struct musb_hdrc_platform_data *pdata = dev->platform_data; struct omap_musb_board_data *data = pdata->board_data; - switch (event) { + switch (musb->xceiv_event) { case USB_EVENT_ID: dev_dbg(musb->controller, "ID GND\n"); @@ -310,6 +320,8 @@ static int omap2430_musb_init(struct musb *musb) return -ENODEV; } + INIT_WORK(&musb->otg_notifier_work, musb_otg_notifier_work); + status = pm_runtime_get_sync(dev); if (status < 0) { dev_err(dev, "pm_runtime_get_sync FAILED");