Skip to content

Commit

Permalink
[media] cpia2: remove V4L2_FL_LOCK_ALL_FOPS
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Hans Verkuil authored and Mauro Carvalho Chehab committed Aug 9, 2012
1 parent 6de7d14 commit d76ebb6
Showing 1 changed file with 28 additions and 11 deletions.
39 changes: 28 additions & 11 deletions drivers/media/video/cpia2/cpia2_v4l.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,29 +84,36 @@ 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;
cam->COM_len = 0;
}

cpia2_dbg_dump_registers(cam);
return 0;
open_unlock:
mutex_unlock(&cam->v4l2_lock);
return retval;
}

/******************************************************************************
Expand All @@ -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);

Expand All @@ -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);
}

Expand All @@ -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;
}


Expand All @@ -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;
}


Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit d76ebb6

Please sign in to comment.