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;
}
cpia2_dbg_dump_registers(cam);
- return 0;
+open_unlock:
+ mutex_unlock(&cam->v4l2_lock);
+ return retval;
}
/******************************************************************************
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);
cam->stream_fh = NULL;
cam->mmapped = 0;
}
+ mutex_unlock(&cam->v4l2_lock);
return v4l2_fh_release(file);
}
{
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;
}
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;
}
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;
}
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);