From 712d8efafbbcbe617f9ad706f6ca1ffea4bbf2e8 Mon Sep 17 00:00:00 2001 From: Vikram Pandita Date: Fri, 12 Aug 2011 07:38:51 -0700 Subject: [PATCH] usb: musb: fix pm_runtime calls while atomic 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 Signed-off-by: Felipe Balbi --- drivers/usb/musb/musb_core.h | 2 ++ drivers/usb/musb/omap2430.c | 14 +++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h index bd2e6b8b814..3d28fb8a2dc 100644 --- a/drivers/usb/musb/musb_core.h +++ b/drivers/usb/musb/musb_core.h @@ -327,6 +327,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 */ @@ -372,6 +373,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 2f6cd431fb1..fd5dd46039a 100644 --- a/drivers/usb/musb/omap2430.c +++ b/drivers/usb/musb/omap2430.c @@ -227,11 +227,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"); @@ -296,6 +306,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"); -- 2.39.5