From 7a0af6ed97f2f08baecb452e719d9c961d117109 Mon Sep 17 00:00:00 2001 From: Changbing Xiong Date: Wed, 20 Aug 2014 23:04:25 -0300 Subject: [PATCH] [media] media: fix kernel deadlock due to tuner pull-out while playing Normally, ADAP_STREAMING bit is set in dvb_usb_start_feed and cleared in dvb_usb_stop_feed. But in exceptional cases, for example, when the tv is playing programs and the tuner is pulled out, then dvb_usbv2_disconnect is called. In such case, it will first call dvb_usbv2_adapter_frontend_exit to stop dvb_frontend_thread, and then call dvb_usbv2_adapter_dvb_exit to clear ADAP_STREAMING bit. At this point, if dvb_frontend_thread is sleeping and waiting for ADAP_STREAMING to be cleared to get out of sleep. then dvb_frontend_thread can never be stoped, because clearing ADAP_STREAMING bit is performed after dvb_frontend_thread is stopped (i.e. performed in dvb_usbv2_adapter_dvb_exit). So, deadlock: [ 240.822037] INFO: task khubd:497 blocked for more than 120 seconds. [ 240.822655] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message. [ 240.830493] khubd D c0013b3c 0 497 2 0x00000000 [ 240.836996] [] (__schedule+0x200/0x54c) from [] (schedule_timeout+0x14c/0x19c) [ 240.845940] [] (schedule_timeout+0x14c/0x19c) from [] (wait_for_common+0xac/0x150) [ 240.855234] [] (wait_for_common+0xac/0x150) from [] (kthread_stop+0x58/0x90) [ 240.864004] [] (kthread_stop+0x58/0x90) from [] (dvb_frontend_stop+0x3c/0x9c) [ 240.872849] [] (dvb_frontend_stop+0x3c/0x9c) from [] (dvb_unregister_frontend+0x20/0xd8) [ 240.882666] [] (dvb_unregister_frontend+0x20/0xd8) from [] (dvb_usbv2_exit+0x68/0xfc) [ 240.892204] [] (dvb_usbv2_exit+0x68/0xfc) from [] (dvb_usbv2_disconnect+0x4c/0x70) [ 240.901499] [] (dvb_usbv2_disconnect+0x4c/0x70) from [] (usb_unbind_interface+0x58/0x188) [ 240.911395] [] (usb_unbind_interface+0x58/0x188) from [] (__device_release_driver+0x74/0xd0) [ 240.921544] [] (__device_release_driver+0x74/0xd0) from [] (device_release_driver+0x1c/0x28) [ 240.931697] [] (device_release_driver+0x1c/0x28) from [] (bus_remove_device+0xc4/0xe4) [ 240.941332] [] (bus_remove_device+0xc4/0xe4) from [] (device_del+0xf4/0x178) [ 240.950106] [] (device_del+0xf4/0x178) from [] (usb_disable_device+0xa0/0x1c8) [ 240.959040] [] (usb_disable_device+0xa0/0x1c8) from [] (usb_disconnect+0x88/0x188) [ 240.968326] [] (usb_disconnect+0x88/0x188) from [] (hub_thread+0x4d0/0x1200) [ 240.977100] [] (hub_thread+0x4d0/0x1200) from [] (kthread+0xa4/0xb0) [ 240.985174] [] (kthread+0xa4/0xb0) from [] (ret_from_fork+0x14/0x3c) [ 240.993259] INFO: task kdvb-ad-0-fe-0:3256 blocked for more than 120 seconds. [ 241.000349] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message. [ 241.008162] kdvb-ad-0-fe-0 D c0013b3c 0 3256 2 0x00000000 [ 241.014507] [] (__schedule+0x200/0x54c) from [] (wait_schedule+0x8/0x10) [ 241.022924] [] (wait_schedule+0x8/0x10) from [] (__wait_on_bit+0x74/0xb8) [ 241.031434] [] (__wait_on_bit+0x74/0xb8) from [] (out_of_line_wait_on_bit+0x68/0x70) [ 241.040902] [] (out_of_line_wait_on_bit+0x68/0x70) from [] (dvb_usb_fe_sleep+0xf4/0xfc) [ 241.050618] [] (dvb_usb_fe_sleep+0xf4/0xfc) from [] (dvb_frontend_thread+0x124/0x4e8) [ 241.060164] [] (dvb_frontend_thread+0x124/0x4e8) from [] (kthread+0xa4/0xb0) [ 241.068929] [] (kthread+0xa4/0xb0) from [] (ret_from_fork+0x14/0x3c) Fix it by calling dvb_usbv2_adapter_frontend_exit() latter. Test enviroment: odroidx2 + Hauppauge(WinTV-Aero-M) Signed-off-by: Changbing Xiong Signed-off-by: Mauro Carvalho Chehab --- drivers/media/usb/dvb-usb-v2/dvb_usb_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/media/usb/dvb-usb-v2/dvb_usb_core.c b/drivers/media/usb/dvb-usb-v2/dvb_usb_core.c index 2e90310be2af..6c33d8525454 100644 --- a/drivers/media/usb/dvb-usb-v2/dvb_usb_core.c +++ b/drivers/media/usb/dvb-usb-v2/dvb_usb_core.c @@ -762,9 +762,9 @@ static int dvb_usbv2_adapter_exit(struct dvb_usb_device *d) for (i = MAX_NO_OF_ADAPTER_PER_DEVICE - 1; i >= 0; i--) { if (d->adapter[i].props) { - dvb_usbv2_adapter_frontend_exit(&d->adapter[i]); dvb_usbv2_adapter_dvb_exit(&d->adapter[i]); dvb_usbv2_adapter_stream_exit(&d->adapter[i]); + dvb_usbv2_adapter_frontend_exit(&d->adapter[i]); } } -- 2.39.5