V4L/DVB (11231): hdpvr: locking fixes
authorJanne Grunau <j@jannau.net>
Thu, 26 Mar 2009 23:56:06 +0000 (20:56 -0300)
committerMauro Carvalho Chehab <mchehab@redhat.com>
Mon, 30 Mar 2009 15:43:42 +0000 (12:43 -0300)
unlock io_mutex in hdpvr_stop_streaming hdpvr_disconnect to allow the
streaming worker to stop before we flush the workqueue.
do not return to user space with mutex held in vidioc_encoder_cmd with
an unknown encoder command.

Signed-off-by: Janne Grunau <j@jannau.net>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
drivers/media/video/hdpvr/hdpvr-core.c
drivers/media/video/hdpvr/hdpvr-video.c

index 2c49862b6d3264bd897695da272125a6b2c37dc7..547833eb6cec8ad9b05b4de0d265f4ce4fca0064 100644 (file)
@@ -390,8 +390,10 @@ static void hdpvr_disconnect(struct usb_interface *interface)
        video_unregister_device(dev->video_dev);
        wake_up_interruptible(&dev->wait_data);
        wake_up_interruptible(&dev->wait_buffer);
+       mutex_unlock(&dev->io_mutex);
        msleep(100);
        flush_workqueue(dev->workqueue);
+       mutex_lock(&dev->io_mutex);
        hdpvr_cancel_queue(dev);
        destroy_workqueue(dev->workqueue);
        mutex_unlock(&dev->io_mutex);
index e9078cdedb281eccdd35135b19d316335135d949..2fe57303c0b560b2ed075c95d07195cc367a228f 100644 (file)
@@ -300,12 +300,14 @@ static int hdpvr_stop_streaming(struct hdpvr_device *dev)
 
        dev->status = STATUS_SHUTTING_DOWN;
        hdpvr_config_call(dev, CTRL_STOP_STREAMING_VALUE, 0x00);
+       mutex_unlock(&dev->io_mutex);
 
        wake_up_interruptible(&dev->wait_buffer);
        msleep(50);
 
        flush_workqueue(dev->workqueue);
 
+       mutex_lock(&dev->io_mutex);
        /* kill the still outstanding urbs */
        hdpvr_cancel_queue(dev);
 
@@ -1130,7 +1132,7 @@ static int vidioc_encoder_cmd(struct file *filp, void *priv,
        default:
                v4l2_dbg(MSG_INFO, hdpvr_debug, dev->video_dev,
                         "Unsupported encoder cmd %d\n", a->cmd);
-               return -EINVAL;
+               res = -EINVAL;
        }
        mutex_unlock(&dev->io_mutex);
        return res;