]> git.openfabrics.org - ~emulex/infiniband.git/commitdiff
[media] cpia2: remove V4L2_FL_LOCK_ALL_FOPS
authorHans Verkuil <hans.verkuil@cisco.com>
Sat, 23 Jun 2012 10:56:21 +0000 (07:56 -0300)
committerMauro Carvalho Chehab <mchehab@redhat.com>
Thu, 9 Aug 2012 22:44:33 +0000 (19:44 -0300)
Add proper locking to the file operations, allowing for the removal
of the V4L2_FL_LOCK_ALL_FOPS flag.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
drivers/media/video/cpia2/cpia2_v4l.c

index a62a7b739991806567231870dc143ceb3cac675a..5ca6f44b4c6327fd2c0edc9b1ee0ed63408b4c6a 100644 (file)
@@ -84,21 +84,26 @@ MODULE_VERSION(CPIA_VERSION);
 static int cpia2_open(struct file *file)
 {
        struct camera_data *cam = video_drvdata(file);
-       int retval = v4l2_fh_open(file);
+       int retval;
 
+       if (mutex_lock_interruptible(&cam->v4l2_lock))
+               return -ERESTARTSYS;
+       retval = v4l2_fh_open(file);
        if (retval)
-               return retval;
+               goto open_unlock;
 
        if (v4l2_fh_is_singular_file(file)) {
                if (cpia2_allocate_buffers(cam)) {
                        v4l2_fh_release(file);
-                       return -ENOMEM;
+                       retval = -ENOMEM;
+                       goto open_unlock;
                }
 
                /* reset the camera */
                if (cpia2_reset_camera(cam) < 0) {
                        v4l2_fh_release(file);
-                       return -EIO;
+                       retval = -EIO;
+                       goto open_unlock;
                }
 
                cam->APP_len = 0;
@@ -106,7 +111,9 @@ static int cpia2_open(struct file *file)
        }
 
        cpia2_dbg_dump_registers(cam);
-       return 0;
+open_unlock:
+       mutex_unlock(&cam->v4l2_lock);
+       return retval;
 }
 
 /******************************************************************************
@@ -119,6 +126,7 @@ static int cpia2_close(struct file *file)
        struct video_device *dev = video_devdata(file);
        struct camera_data *cam = video_get_drvdata(dev);
 
+       mutex_lock(&cam->v4l2_lock);
        if (video_is_registered(&cam->vdev) && v4l2_fh_is_singular_file(file)) {
                cpia2_usb_stream_stop(cam);
 
@@ -133,6 +141,7 @@ static int cpia2_close(struct file *file)
                cam->stream_fh = NULL;
                cam->mmapped = 0;
        }
+       mutex_unlock(&cam->v4l2_lock);
        return v4l2_fh_release(file);
 }
 
@@ -146,11 +155,16 @@ static ssize_t cpia2_v4l_read(struct file *file, char __user *buf, size_t count,
 {
        struct camera_data *cam = video_drvdata(file);
        int noblock = file->f_flags&O_NONBLOCK;
+       ssize_t ret;
 
        if(!cam)
                return -EINVAL;
 
-       return cpia2_read(cam, buf, count, noblock);
+       if (mutex_lock_interruptible(&cam->v4l2_lock))
+               return -ERESTARTSYS;
+       ret = cpia2_read(cam, buf, count, noblock);
+       mutex_unlock(&cam->v4l2_lock);
+       return ret;
 }
 
 
@@ -162,8 +176,12 @@ static ssize_t cpia2_v4l_read(struct file *file, char __user *buf, size_t count,
 static unsigned int cpia2_v4l_poll(struct file *filp, struct poll_table_struct *wait)
 {
        struct camera_data *cam = video_drvdata(filp);
+       unsigned int res;
 
-       return cpia2_poll(cam, filp, wait);
+       mutex_lock(&cam->v4l2_lock);
+       res = cpia2_poll(cam, filp, wait);
+       mutex_unlock(&cam->v4l2_lock);
+       return res;
 }
 
 
@@ -987,10 +1005,13 @@ static int cpia2_mmap(struct file *file, struct vm_area_struct *area)
        struct camera_data *cam = video_drvdata(file);
        int retval;
 
+       if (mutex_lock_interruptible(&cam->v4l2_lock))
+               return -ERESTARTSYS;
        retval = cpia2_remap_buffer(cam, area);
 
        if(!retval)
                cam->stream_fh = file->private_data;
+       mutex_unlock(&cam->v4l2_lock);
        return retval;
 }
 
@@ -1147,10 +1168,6 @@ int cpia2_register_camera(struct camera_data *cam)
        cam->vdev.ctrl_handler = hdl;
        cam->vdev.v4l2_dev = &cam->v4l2_dev;
        set_bit(V4L2_FL_USE_FH_PRIO, &cam->vdev.flags);
-       /* Locking in file operations other than ioctl should be done
-          by the driver, not the V4L2 core.
-          This driver needs auditing so that this flag can be removed. */
-       set_bit(V4L2_FL_LOCK_ALL_FOPS, &cam->vdev.flags);
 
        reset_camera_struct_v4l(cam);