Commit e4acba3c authored by Deti Fliegl's avatar Deti Fliegl Committed by Mauro Carvalho Chehab

DVB (2401): USB hot unplug Oops fix.

- USB hot unplug Oops fix.
Signed-off-by: default avatarDeti Fliegl <deti@fliegl.de>
Signed-off-by: default avatarJohannes Stezenbach <js@linuxtv.org>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@brturbo.com.br>
parent 6a5bdd32
...@@ -131,6 +131,8 @@ struct cinergyt2 { ...@@ -131,6 +131,8 @@ struct cinergyt2 {
wait_queue_head_t poll_wq; wait_queue_head_t poll_wq;
int pending_fe_events; int pending_fe_events;
int disconnect_pending;
atomic_t inuse;
void *streambuf; void *streambuf;
dma_addr_t streambuf_dmahandle; dma_addr_t streambuf_dmahandle;
...@@ -343,7 +345,7 @@ static int cinergyt2_start_feed(struct dvb_demux_feed *dvbdmxfeed) ...@@ -343,7 +345,7 @@ static int cinergyt2_start_feed(struct dvb_demux_feed *dvbdmxfeed)
struct dvb_demux *demux = dvbdmxfeed->demux; struct dvb_demux *demux = dvbdmxfeed->demux;
struct cinergyt2 *cinergyt2 = demux->priv; struct cinergyt2 *cinergyt2 = demux->priv;
if (down_interruptible(&cinergyt2->sem)) if (cinergyt2->disconnect_pending || down_interruptible(&cinergyt2->sem))
return -ERESTARTSYS; return -ERESTARTSYS;
if (cinergyt2->streaming == 0) if (cinergyt2->streaming == 0)
...@@ -359,7 +361,7 @@ static int cinergyt2_stop_feed(struct dvb_demux_feed *dvbdmxfeed) ...@@ -359,7 +361,7 @@ static int cinergyt2_stop_feed(struct dvb_demux_feed *dvbdmxfeed)
struct dvb_demux *demux = dvbdmxfeed->demux; struct dvb_demux *demux = dvbdmxfeed->demux;
struct cinergyt2 *cinergyt2 = demux->priv; struct cinergyt2 *cinergyt2 = demux->priv;
if (down_interruptible(&cinergyt2->sem)) if (cinergyt2->disconnect_pending || down_interruptible(&cinergyt2->sem))
return -ERESTARTSYS; return -ERESTARTSYS;
if (--cinergyt2->streaming == 0) if (--cinergyt2->streaming == 0)
...@@ -479,23 +481,37 @@ static int cinergyt2_open (struct inode *inode, struct file *file) ...@@ -479,23 +481,37 @@ static int cinergyt2_open (struct inode *inode, struct file *file)
{ {
struct dvb_device *dvbdev = file->private_data; struct dvb_device *dvbdev = file->private_data;
struct cinergyt2 *cinergyt2 = dvbdev->priv; struct cinergyt2 *cinergyt2 = dvbdev->priv;
int err; int err = -ERESTARTSYS;
if ((err = dvb_generic_open(inode, file))) if (cinergyt2->disconnect_pending || down_interruptible(&cinergyt2->sem))
return -ERESTARTSYS;
if ((err = dvb_generic_open(inode, file))) {
up(&cinergyt2->sem);
return err; return err;
}
if (down_interruptible(&cinergyt2->sem))
return -ERESTARTSYS;
if ((file->f_flags & O_ACCMODE) != O_RDONLY) { if ((file->f_flags & O_ACCMODE) != O_RDONLY) {
cinergyt2_sleep(cinergyt2, 0); cinergyt2_sleep(cinergyt2, 0);
schedule_delayed_work(&cinergyt2->query_work, HZ/2); schedule_delayed_work(&cinergyt2->query_work, HZ/2);
} }
atomic_inc(&cinergyt2->inuse);
up(&cinergyt2->sem); up(&cinergyt2->sem);
return 0; return 0;
} }
static void cinergyt2_unregister(struct cinergyt2 *cinergyt2)
{
dvb_unregister_device(cinergyt2->fedev);
dvb_unregister_adapter(&cinergyt2->adapter);
cinergyt2_free_stream_urbs(cinergyt2);
kfree(cinergyt2);
}
static int cinergyt2_release (struct inode *inode, struct file *file) static int cinergyt2_release (struct inode *inode, struct file *file)
{ {
struct dvb_device *dvbdev = file->private_data; struct dvb_device *dvbdev = file->private_data;
...@@ -504,7 +520,7 @@ static int cinergyt2_release (struct inode *inode, struct file *file) ...@@ -504,7 +520,7 @@ static int cinergyt2_release (struct inode *inode, struct file *file)
if (down_interruptible(&cinergyt2->sem)) if (down_interruptible(&cinergyt2->sem))
return -ERESTARTSYS; return -ERESTARTSYS;
if ((file->f_flags & O_ACCMODE) != O_RDONLY) { if (!cinergyt2->disconnect_pending && (file->f_flags & O_ACCMODE) != O_RDONLY) {
cancel_delayed_work(&cinergyt2->query_work); cancel_delayed_work(&cinergyt2->query_work);
flush_scheduled_work(); flush_scheduled_work();
cinergyt2_sleep(cinergyt2, 1); cinergyt2_sleep(cinergyt2, 1);
...@@ -512,6 +528,11 @@ static int cinergyt2_release (struct inode *inode, struct file *file) ...@@ -512,6 +528,11 @@ static int cinergyt2_release (struct inode *inode, struct file *file)
up(&cinergyt2->sem); up(&cinergyt2->sem);
if (atomic_dec_and_test(&cinergyt2->inuse) && cinergyt2->disconnect_pending) {
warn("delayed unregister in release");
cinergyt2_unregister(cinergyt2);
}
return dvb_generic_release(inode, file); return dvb_generic_release(inode, file);
} }
...@@ -519,7 +540,14 @@ static unsigned int cinergyt2_poll (struct file *file, struct poll_table_struct ...@@ -519,7 +540,14 @@ static unsigned int cinergyt2_poll (struct file *file, struct poll_table_struct
{ {
struct dvb_device *dvbdev = file->private_data; struct dvb_device *dvbdev = file->private_data;
struct cinergyt2 *cinergyt2 = dvbdev->priv; struct cinergyt2 *cinergyt2 = dvbdev->priv;
if (cinergyt2->disconnect_pending || down_interruptible(&cinergyt2->sem))
return -ERESTARTSYS;
poll_wait(file, &cinergyt2->poll_wq, wait); poll_wait(file, &cinergyt2->poll_wq, wait);
up(&cinergyt2->sem);
return (POLLIN | POLLRDNORM | POLLPRI); return (POLLIN | POLLRDNORM | POLLPRI);
} }
...@@ -585,7 +613,7 @@ static int cinergyt2_ioctl (struct inode *inode, struct file *file, ...@@ -585,7 +613,7 @@ static int cinergyt2_ioctl (struct inode *inode, struct file *file,
if (copy_from_user(&p, (void __user*) arg, sizeof(p))) if (copy_from_user(&p, (void __user*) arg, sizeof(p)))
return -EFAULT; return -EFAULT;
if (down_interruptible(&cinergyt2->sem)) if (cinergyt2->disconnect_pending || down_interruptible(&cinergyt2->sem))
return -ERESTARTSYS; return -ERESTARTSYS;
param->cmd = CINERGYT2_EP1_SET_TUNER_PARAMETERS; param->cmd = CINERGYT2_EP1_SET_TUNER_PARAMETERS;
...@@ -696,7 +724,7 @@ static void cinergyt2_query_rc (void *data) ...@@ -696,7 +724,7 @@ static void cinergyt2_query_rc (void *data)
struct cinergyt2_rc_event rc_events[12]; struct cinergyt2_rc_event rc_events[12];
int n, len, i; int n, len, i;
if (down_interruptible(&cinergyt2->sem)) if (cinergyt2->disconnect_pending || down_interruptible(&cinergyt2->sem))
return; return;
len = cinergyt2_command(cinergyt2, buf, sizeof(buf), len = cinergyt2_command(cinergyt2, buf, sizeof(buf),
...@@ -791,7 +819,6 @@ static int cinergyt2_register_rc(struct cinergyt2 *cinergyt2) ...@@ -791,7 +819,6 @@ static int cinergyt2_register_rc(struct cinergyt2 *cinergyt2)
static void cinergyt2_unregister_rc(struct cinergyt2 *cinergyt2) static void cinergyt2_unregister_rc(struct cinergyt2 *cinergyt2)
{ {
cancel_delayed_work(&cinergyt2->rc_query_work); cancel_delayed_work(&cinergyt2->rc_query_work);
flush_scheduled_work();
input_unregister_device(cinergyt2->rc_input_dev); input_unregister_device(cinergyt2->rc_input_dev);
} }
...@@ -822,7 +849,7 @@ static void cinergyt2_query (void *data) ...@@ -822,7 +849,7 @@ static void cinergyt2_query (void *data)
uint8_t lock_bits; uint8_t lock_bits;
uint32_t unc; uint32_t unc;
if (down_interruptible(&cinergyt2->sem)) if (cinergyt2->disconnect_pending || down_interruptible(&cinergyt2->sem))
return; return;
unc = s->uncorrected_block_count; unc = s->uncorrected_block_count;
...@@ -922,28 +949,25 @@ static void cinergyt2_disconnect (struct usb_interface *intf) ...@@ -922,28 +949,25 @@ static void cinergyt2_disconnect (struct usb_interface *intf)
{ {
struct cinergyt2 *cinergyt2 = usb_get_intfdata (intf); struct cinergyt2 *cinergyt2 = usb_get_intfdata (intf);
if (down_interruptible(&cinergyt2->sem)) flush_scheduled_work();
return;
cinergyt2_unregister_rc(cinergyt2); cinergyt2_unregister_rc(cinergyt2);
cancel_delayed_work(&cinergyt2->query_work);
wake_up_interruptible(&cinergyt2->poll_wq);
cinergyt2->demux.dmx.close(&cinergyt2->demux.dmx); cinergyt2->demux.dmx.close(&cinergyt2->demux.dmx);
dvb_net_release(&cinergyt2->dvbnet); cinergyt2->disconnect_pending = 1;
dvb_dmxdev_release(&cinergyt2->dmxdev);
dvb_dmx_release(&cinergyt2->demux);
dvb_unregister_device(cinergyt2->fedev);
dvb_unregister_adapter(&cinergyt2->adapter);
cinergyt2_free_stream_urbs(cinergyt2); if (!atomic_read(&cinergyt2->inuse))
up(&cinergyt2->sem); cinergyt2_unregister(cinergyt2);
kfree(cinergyt2);
} }
static int cinergyt2_suspend (struct usb_interface *intf, pm_message_t state) static int cinergyt2_suspend (struct usb_interface *intf, pm_message_t state)
{ {
struct cinergyt2 *cinergyt2 = usb_get_intfdata (intf); struct cinergyt2 *cinergyt2 = usb_get_intfdata (intf);
if (down_interruptible(&cinergyt2->sem)) if (cinergyt2->disconnect_pending || down_interruptible(&cinergyt2->sem))
return -ERESTARTSYS; return -ERESTARTSYS;
if (state.event > PM_EVENT_ON) { if (state.event > PM_EVENT_ON) {
...@@ -966,7 +990,7 @@ static int cinergyt2_resume (struct usb_interface *intf) ...@@ -966,7 +990,7 @@ static int cinergyt2_resume (struct usb_interface *intf)
struct cinergyt2 *cinergyt2 = usb_get_intfdata (intf); struct cinergyt2 *cinergyt2 = usb_get_intfdata (intf);
struct dvbt_set_parameters_msg *param = &cinergyt2->param; struct dvbt_set_parameters_msg *param = &cinergyt2->param;
if (down_interruptible(&cinergyt2->sem)) if (cinergyt2->disconnect_pending || down_interruptible(&cinergyt2->sem))
return -ERESTARTSYS; return -ERESTARTSYS;
if (!cinergyt2->sleeping) { if (!cinergyt2->sleeping) {
...@@ -1019,4 +1043,3 @@ module_exit (cinergyt2_exit); ...@@ -1019,4 +1043,3 @@ module_exit (cinergyt2_exit);
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
MODULE_AUTHOR("Holger Waechtler, Daniel Mack"); MODULE_AUTHOR("Holger Waechtler, Daniel Mack");
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment