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

[media] stk-webcam: enable core-locking

This makes it possible to switch to unlocked_ioctl.
Signed-off-by: default avatarHans Verkuil <hans.verkuil@cisco.com>
Tested-by: default avatarArvydas Sidorenko <asido4@gmail.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 8407653f
...@@ -610,6 +610,8 @@ static int v4l_stk_open(struct file *fp) ...@@ -610,6 +610,8 @@ static int v4l_stk_open(struct file *fp)
if (dev == NULL || !is_present(dev)) if (dev == NULL || !is_present(dev))
return -ENXIO; return -ENXIO;
if (mutex_lock_interruptible(&dev->lock))
return -ERESTARTSYS;
if (!dev->first_init) if (!dev->first_init)
stk_camera_write_reg(dev, 0x0, 0x24); stk_camera_write_reg(dev, 0x0, 0x24);
else else
...@@ -618,6 +620,7 @@ static int v4l_stk_open(struct file *fp) ...@@ -618,6 +620,7 @@ static int v4l_stk_open(struct file *fp)
err = v4l2_fh_open(fp); err = v4l2_fh_open(fp);
if (!err) if (!err)
usb_autopm_get_interface(dev->interface); usb_autopm_get_interface(dev->interface);
mutex_unlock(&dev->lock);
return err; return err;
} }
...@@ -625,6 +628,7 @@ static int v4l_stk_release(struct file *fp) ...@@ -625,6 +628,7 @@ static int v4l_stk_release(struct file *fp)
{ {
struct stk_camera *dev = video_drvdata(fp); struct stk_camera *dev = video_drvdata(fp);
mutex_lock(&dev->lock);
if (dev->owner == fp) { if (dev->owner == fp) {
stk_stop_stream(dev); stk_stop_stream(dev);
stk_free_buffers(dev); stk_free_buffers(dev);
...@@ -635,10 +639,11 @@ static int v4l_stk_release(struct file *fp) ...@@ -635,10 +639,11 @@ static int v4l_stk_release(struct file *fp)
if (is_present(dev)) if (is_present(dev))
usb_autopm_put_interface(dev->interface); usb_autopm_put_interface(dev->interface);
mutex_unlock(&dev->lock);
return v4l2_fh_release(fp); 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) size_t count, loff_t *f_pos)
{ {
int i; int i;
...@@ -699,6 +704,19 @@ static ssize_t v4l_stk_read(struct file *fp, char __user *buf, ...@@ -699,6 +704,19 @@ static ssize_t v4l_stk_read(struct file *fp, char __user *buf,
return count; 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) static unsigned int v4l_stk_poll(struct file *fp, poll_table *wait)
{ {
struct stk_camera *dev = video_drvdata(fp); struct stk_camera *dev = video_drvdata(fp);
...@@ -1183,7 +1201,7 @@ static struct v4l2_file_operations v4l_stk_fops = { ...@@ -1183,7 +1201,7 @@ static struct v4l2_file_operations v4l_stk_fops = {
.read = v4l_stk_read, .read = v4l_stk_read,
.poll = v4l_stk_poll, .poll = v4l_stk_poll,
.mmap = v4l_stk_mmap, .mmap = v4l_stk_mmap,
.ioctl = video_ioctl2, .unlocked_ioctl = video_ioctl2,
}; };
static const struct v4l2_ioctl_ops v4l_stk_ioctl_ops = { static const struct v4l2_ioctl_ops v4l_stk_ioctl_ops = {
...@@ -1231,6 +1249,7 @@ static int stk_register_video_device(struct stk_camera *dev) ...@@ -1231,6 +1249,7 @@ static int stk_register_video_device(struct stk_camera *dev)
int err; int err;
dev->vdev = stk_v4l_data; dev->vdev = stk_v4l_data;
dev->vdev.lock = &dev->lock;
dev->vdev.debug = debug; dev->vdev.debug = debug;
dev->vdev.v4l2_dev = &dev->v4l2_dev; dev->vdev.v4l2_dev = &dev->v4l2_dev;
set_bit(V4L2_FL_USE_FH_PRIO, &dev->vdev.flags); set_bit(V4L2_FL_USE_FH_PRIO, &dev->vdev.flags);
...@@ -1286,6 +1305,7 @@ static int stk_camera_probe(struct usb_interface *interface, ...@@ -1286,6 +1305,7 @@ static int stk_camera_probe(struct usb_interface *interface,
dev->v4l2_dev.ctrl_handler = hdl; dev->v4l2_dev.ctrl_handler = hdl;
spin_lock_init(&dev->spinlock); spin_lock_init(&dev->spinlock);
mutex_init(&dev->lock);
init_waitqueue_head(&dev->wait_frame); init_waitqueue_head(&dev->wait_frame);
dev->first_init = 1; /* webcam LED management */ dev->first_init = 1; /* webcam LED management */
......
...@@ -99,6 +99,7 @@ struct stk_camera { ...@@ -99,6 +99,7 @@ struct stk_camera {
struct usb_interface *interface; struct usb_interface *interface;
int webcam_model; int webcam_model;
struct file *owner; struct file *owner;
struct mutex lock;
int first_init; int first_init;
u8 isoc_ep; u8 isoc_ep;
......
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