Commit d76ebb67 authored by Hans Verkuil's avatar Hans Verkuil Committed by Mauro Carvalho Chehab

[media] cpia2: remove V4L2_FL_LOCK_ALL_FOPS

Add proper locking to the file operations, allowing for the removal
of the V4L2_FL_LOCK_ALL_FOPS flag.
Signed-off-by: default avatarHans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 6de7d14d
...@@ -84,21 +84,26 @@ MODULE_VERSION(CPIA_VERSION); ...@@ -84,21 +84,26 @@ MODULE_VERSION(CPIA_VERSION);
static int cpia2_open(struct file *file) static int cpia2_open(struct file *file)
{ {
struct camera_data *cam = video_drvdata(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) if (retval)
return retval; goto open_unlock;
if (v4l2_fh_is_singular_file(file)) { if (v4l2_fh_is_singular_file(file)) {
if (cpia2_allocate_buffers(cam)) { if (cpia2_allocate_buffers(cam)) {
v4l2_fh_release(file); v4l2_fh_release(file);
return -ENOMEM; retval = -ENOMEM;
goto open_unlock;
} }
/* reset the camera */ /* reset the camera */
if (cpia2_reset_camera(cam) < 0) { if (cpia2_reset_camera(cam) < 0) {
v4l2_fh_release(file); v4l2_fh_release(file);
return -EIO; retval = -EIO;
goto open_unlock;
} }
cam->APP_len = 0; cam->APP_len = 0;
...@@ -106,7 +111,9 @@ static int cpia2_open(struct file *file) ...@@ -106,7 +111,9 @@ static int cpia2_open(struct file *file)
} }
cpia2_dbg_dump_registers(cam); 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) ...@@ -119,6 +126,7 @@ static int cpia2_close(struct file *file)
struct video_device *dev = video_devdata(file); struct video_device *dev = video_devdata(file);
struct camera_data *cam = video_get_drvdata(dev); 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)) { if (video_is_registered(&cam->vdev) && v4l2_fh_is_singular_file(file)) {
cpia2_usb_stream_stop(cam); cpia2_usb_stream_stop(cam);
...@@ -133,6 +141,7 @@ static int cpia2_close(struct file *file) ...@@ -133,6 +141,7 @@ static int cpia2_close(struct file *file)
cam->stream_fh = NULL; cam->stream_fh = NULL;
cam->mmapped = 0; cam->mmapped = 0;
} }
mutex_unlock(&cam->v4l2_lock);
return v4l2_fh_release(file); return v4l2_fh_release(file);
} }
...@@ -146,11 +155,16 @@ static ssize_t cpia2_v4l_read(struct file *file, char __user *buf, size_t count, ...@@ -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); struct camera_data *cam = video_drvdata(file);
int noblock = file->f_flags&O_NONBLOCK; int noblock = file->f_flags&O_NONBLOCK;
ssize_t ret;
if(!cam) if(!cam)
return -EINVAL; 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, ...@@ -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) static unsigned int cpia2_v4l_poll(struct file *filp, struct poll_table_struct *wait)
{ {
struct camera_data *cam = video_drvdata(filp); 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) ...@@ -987,10 +1005,13 @@ static int cpia2_mmap(struct file *file, struct vm_area_struct *area)
struct camera_data *cam = video_drvdata(file); struct camera_data *cam = video_drvdata(file);
int retval; int retval;
if (mutex_lock_interruptible(&cam->v4l2_lock))
return -ERESTARTSYS;
retval = cpia2_remap_buffer(cam, area); retval = cpia2_remap_buffer(cam, area);
if(!retval) if(!retval)
cam->stream_fh = file->private_data; cam->stream_fh = file->private_data;
mutex_unlock(&cam->v4l2_lock);
return retval; return retval;
} }
...@@ -1147,10 +1168,6 @@ int cpia2_register_camera(struct camera_data *cam) ...@@ -1147,10 +1168,6 @@ int cpia2_register_camera(struct camera_data *cam)
cam->vdev.ctrl_handler = hdl; cam->vdev.ctrl_handler = hdl;
cam->vdev.v4l2_dev = &cam->v4l2_dev; cam->vdev.v4l2_dev = &cam->v4l2_dev;
set_bit(V4L2_FL_USE_FH_PRIO, &cam->vdev.flags); 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); reset_camera_struct_v4l(cam);
......
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