if (dev == NULL || !is_present(dev))
return -ENXIO;
+ if (mutex_lock_interruptible(&dev->lock))
+ return -ERESTARTSYS;
if (!dev->first_init)
stk_camera_write_reg(dev, 0x0, 0x24);
else
err = v4l2_fh_open(fp);
if (!err)
usb_autopm_get_interface(dev->interface);
+ mutex_unlock(&dev->lock);
return err;
}
{
struct stk_camera *dev = video_drvdata(fp);
+ mutex_lock(&dev->lock);
if (dev->owner == fp) {
stk_stop_stream(dev);
stk_free_buffers(dev);
if (is_present(dev))
usb_autopm_put_interface(dev->interface);
+ mutex_unlock(&dev->lock);
return v4l2_fh_release(fp);
}
-static ssize_t v4l_stk_read(struct file *fp, char __user *buf,
+static ssize_t stk_read(struct file *fp, char __user *buf,
size_t count, loff_t *f_pos)
{
int i;
return count;
}
+static ssize_t v4l_stk_read(struct file *fp, char __user *buf,
+ size_t count, loff_t *f_pos)
+{
+ struct stk_camera *dev = video_drvdata(fp);
+ int ret;
+
+ if (mutex_lock_interruptible(&dev->lock))
+ return -ERESTARTSYS;
+ ret = stk_read(fp, buf, count, f_pos);
+ mutex_unlock(&dev->lock);
+ return ret;
+}
+
static unsigned int v4l_stk_poll(struct file *fp, poll_table *wait)
{
struct stk_camera *dev = video_drvdata(fp);
.read = v4l_stk_read,
.poll = v4l_stk_poll,
.mmap = v4l_stk_mmap,
- .ioctl = video_ioctl2,
+ .unlocked_ioctl = video_ioctl2,
};
static const struct v4l2_ioctl_ops v4l_stk_ioctl_ops = {
int err;
dev->vdev = stk_v4l_data;
+ dev->vdev.lock = &dev->lock;
dev->vdev.debug = debug;
dev->vdev.v4l2_dev = &dev->v4l2_dev;
set_bit(V4L2_FL_USE_FH_PRIO, &dev->vdev.flags);
dev->v4l2_dev.ctrl_handler = hdl;
spin_lock_init(&dev->spinlock);
+ mutex_init(&dev->lock);
init_waitqueue_head(&dev->wait_frame);
dev->first_init = 1; /* webcam LED management */