aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/pvrusb2/pvrusb2-hdw.c
diff options
context:
space:
mode:
authorMike Isely <isely@pobox.com>2008-04-22 13:45:45 -0400
committerMauro Carvalho Chehab <mchehab@infradead.org>2008-04-24 13:07:48 -0400
commit794b16072e00d0a40a8c773dd4319fb1e460a632 (patch)
tree4ce7b55af0ae1208d72bee673c16311acf085f66 /drivers/media/video/pvrusb2/pvrusb2-hdw.c
parent8f59100a42576c49e2170e9dc04f8b7ac922a74d (diff)
V4L/DVB (7321): pvrusb2: Rework context handling and initialization
This change significantly rearranges pvr2_context level initialization and operation: 1. A new kernel thread is set up for management of the context. 2. Destruction of the pvr2_context instance is moved into the kernel thread. No other context is able to remove the instance; doing this simplifies lock handling. 3. The callback into pvrusb2-main, which is used to trigger initialization of each interface, is now issued from this kernel thread. Previously it had been indirectly issued out of the work queue thread in pvr2_hdw, which led to deadlock issues if the interface needed to change a control setting (which in turn requires dispatch of another work queue entry). 4. Callbacks into the interfaces (via the pvr2_channel structure) are now issued strictly from this thread. The net result of this is that such callback functions can now also safely operate driver controls without deadlocking the work queue. (At the moment this is not actually a problem, but I'm anticipating issues with this in the future). 5. There is no longer any need for anyone to enter / exit the pvr2_context structure. Implementation of the kernel thread here allows this all to be internal now, simplifying other logic. 6. A very very longstanding issue involving a mutex deadlock between the pvrusb2 driver and v4l should now be solved. The deadlock involved the pvr2_context mutex and a globals-protecting mutex in v4l. During initialization the driver would take the pvr2_context mutex first then the v4l2 interface would register with v4l and implicitly take the v4l mutex. Later when v4l would call back into the driver, the two mutexes could possibly be taken in the opposite order, a situation that can lead to deadlock. In practice this really wasn't an issue unless a v4l app tried to start VERY early after the driver appeared. However it still needed to be solved, and with the use of the kernel thread relieving need for pvr2_context mutex, the problem should be finally solved. Signed-off-by: Mike Isely <isely@pobox.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Diffstat (limited to 'drivers/media/video/pvrusb2/pvrusb2-hdw.c')
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-hdw.c20
1 files changed, 5 insertions, 15 deletions
diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw.c b/drivers/media/video/pvrusb2/pvrusb2-hdw.c
index 1dff2d04a5d9..7e7c570cf830 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-hdw.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-hdw.c
@@ -221,7 +221,6 @@ static int pvr2_hdw_state_eval(struct pvr2_hdw *);
221static void pvr2_hdw_set_cur_freq(struct pvr2_hdw *,unsigned long); 221static void pvr2_hdw_set_cur_freq(struct pvr2_hdw *,unsigned long);
222static void pvr2_hdw_worker_i2c(struct work_struct *work); 222static void pvr2_hdw_worker_i2c(struct work_struct *work);
223static void pvr2_hdw_worker_poll(struct work_struct *work); 223static void pvr2_hdw_worker_poll(struct work_struct *work);
224static void pvr2_hdw_worker_init(struct work_struct *work);
225static int pvr2_hdw_wait(struct pvr2_hdw *,int state); 224static int pvr2_hdw_wait(struct pvr2_hdw *,int state);
226static int pvr2_hdw_untrip_unlocked(struct pvr2_hdw *); 225static int pvr2_hdw_untrip_unlocked(struct pvr2_hdw *);
227static void pvr2_hdw_state_log_state(struct pvr2_hdw *); 226static void pvr2_hdw_state_log_state(struct pvr2_hdw *);
@@ -1816,15 +1815,16 @@ static void pvr2_hdw_setup(struct pvr2_hdw *hdw)
1816/* Perform second stage initialization. Set callback pointer first so that 1815/* Perform second stage initialization. Set callback pointer first so that
1817 we can avoid a possible initialization race (if the kernel thread runs 1816 we can avoid a possible initialization race (if the kernel thread runs
1818 before the callback has been set). */ 1817 before the callback has been set). */
1819void pvr2_hdw_initialize(struct pvr2_hdw *hdw, 1818int pvr2_hdw_initialize(struct pvr2_hdw *hdw,
1820 void (*callback_func)(void *), 1819 void (*callback_func)(void *),
1821 void *callback_data) 1820 void *callback_data)
1822{ 1821{
1823 LOCK_TAKE(hdw->big_lock); do { 1822 LOCK_TAKE(hdw->big_lock); do {
1824 hdw->state_data = callback_data; 1823 hdw->state_data = callback_data;
1825 hdw->state_func = callback_func; 1824 hdw->state_func = callback_func;
1826 } while (0); LOCK_GIVE(hdw->big_lock); 1825 } while (0); LOCK_GIVE(hdw->big_lock);
1827 queue_work(hdw->workqueue,&hdw->workinit); 1826 pvr2_hdw_setup(hdw);
1827 return hdw->flag_init_ok;
1828} 1828}
1829 1829
1830 1830
@@ -2032,7 +2032,6 @@ struct pvr2_hdw *pvr2_hdw_create(struct usb_interface *intf,
2032 hdw->workqueue = create_singlethread_workqueue(hdw->name); 2032 hdw->workqueue = create_singlethread_workqueue(hdw->name);
2033 INIT_WORK(&hdw->workpoll,pvr2_hdw_worker_poll); 2033 INIT_WORK(&hdw->workpoll,pvr2_hdw_worker_poll);
2034 INIT_WORK(&hdw->worki2csync,pvr2_hdw_worker_i2c); 2034 INIT_WORK(&hdw->worki2csync,pvr2_hdw_worker_i2c);
2035 INIT_WORK(&hdw->workinit,pvr2_hdw_worker_init);
2036 2035
2037 pvr2_trace(PVR2_TRACE_INIT,"Driver unit number is %d, name is %s", 2036 pvr2_trace(PVR2_TRACE_INIT,"Driver unit number is %d, name is %s",
2038 hdw->unit_number,hdw->name); 2037 hdw->unit_number,hdw->name);
@@ -2517,15 +2516,6 @@ static void pvr2_hdw_worker_poll(struct work_struct *work)
2517} 2516}
2518 2517
2519 2518
2520static void pvr2_hdw_worker_init(struct work_struct *work)
2521{
2522 struct pvr2_hdw *hdw = container_of(work,struct pvr2_hdw,workinit);
2523 LOCK_TAKE(hdw->big_lock); do {
2524 pvr2_hdw_setup(hdw);
2525 } while (0); LOCK_GIVE(hdw->big_lock);
2526}
2527
2528
2529static int pvr2_hdw_wait(struct pvr2_hdw *hdw,int state) 2519static int pvr2_hdw_wait(struct pvr2_hdw *hdw,int state)
2530{ 2520{
2531 return wait_event_interruptible( 2521 return wait_event_interruptible(