diff options
author | Mike Isely <isely@pobox.com> | 2008-02-09 22:59:08 -0600 |
---|---|---|
committer | Mike Isely <isely@pobox.com> | 2008-02-09 22:59:08 -0600 |
commit | def54dfafa784d5829a95ebe5150f9bc8c0bba6e (patch) | |
tree | 2461a4c6938068d5517020dbbc3a6242c57c0c8d /linux/drivers/media/video/pvrusb2/pvrusb2-hdw.c | |
parent | 5d7dcf24bf2c8edcf69c20cc70ba2e5278a5e553 (diff) | |
download | mediapointer-dvb-s2-def54dfafa784d5829a95ebe5150f9bc8c0bba6e.tar.gz mediapointer-dvb-s2-def54dfafa784d5829a95ebe5150f9bc8c0bba6e.tar.bz2 |
pvrusb2: Close potential race condition during initialization
From: Mike Isely <isely@pobox.com>
There is a callback that is issued to into pvr2_context from pvr2_hdw
after initialization is done. There was a probability that this
callback could get missed. Fixed.
Signed-off-by: Mike Isely <isely@pobox.com>
Diffstat (limited to 'linux/drivers/media/video/pvrusb2/pvrusb2-hdw.c')
-rw-r--r-- | linux/drivers/media/video/pvrusb2/pvrusb2-hdw.c | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/linux/drivers/media/video/pvrusb2/pvrusb2-hdw.c b/linux/drivers/media/video/pvrusb2/pvrusb2-hdw.c index 32fc2266b..b3120a1fc 100644 --- a/linux/drivers/media/video/pvrusb2/pvrusb2-hdw.c +++ b/linux/drivers/media/video/pvrusb2/pvrusb2-hdw.c @@ -1824,8 +1824,23 @@ static void pvr2_hdw_setup(struct pvr2_hdw *hdw) } -/* Create and return a structure for interacting with the underlying - hardware */ +/* Perform second stage initialization. Set callback pointer first so that + we can avoid a possible initialization race (if the kernel thread runs + before the callback has been set). */ +void pvr2_hdw_initialize(struct pvr2_hdw *hdw, + void (*callback_func)(void *), + void *callback_data) +{ + LOCK_TAKE(hdw->big_lock); do { + hdw->state_data = callback_data; + hdw->state_func = callback_func; + } while (0); LOCK_GIVE(hdw->big_lock); + queue_work(hdw->workqueue,&hdw->workinit); +} + + +/* Create, set up, and return a structure for interacting with the + underlying hardware. */ struct pvr2_hdw *pvr2_hdw_create(struct usb_interface *intf, const struct usb_device_id *devid) { @@ -2059,7 +2074,6 @@ struct pvr2_hdw *pvr2_hdw_create(struct usb_interface *intf, mutex_init(&hdw->ctl_lock_mutex); mutex_init(&hdw->big_lock_mutex); - queue_work(hdw->workqueue,&hdw->workinit); return hdw; fail: if (hdw) { @@ -2541,17 +2555,6 @@ static int pvr2_hdw_wait(struct pvr2_hdw *hdw,int state) } -void pvr2_hdw_set_state_callback(struct pvr2_hdw *hdw, - void (*callback_func)(void *), - void *callback_data) -{ - LOCK_TAKE(hdw->big_lock); do { - hdw->state_data = callback_data; - hdw->state_func = callback_func; - } while (0); LOCK_GIVE(hdw->big_lock); -} - - /* Return name for this driver instance */ const char *pvr2_hdw_get_driver_name(struct pvr2_hdw *hdw) { |