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

[media] vpif_display: 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 bc738301
...@@ -695,10 +695,15 @@ static int vpif_mmap(struct file *filep, struct vm_area_struct *vma) ...@@ -695,10 +695,15 @@ static int vpif_mmap(struct file *filep, struct vm_area_struct *vma)
struct vpif_fh *fh = filep->private_data; struct vpif_fh *fh = filep->private_data;
struct channel_obj *ch = fh->channel; struct channel_obj *ch = fh->channel;
struct common_obj *common = &(ch->common[VPIF_VIDEO_INDEX]); struct common_obj *common = &(ch->common[VPIF_VIDEO_INDEX]);
int ret;
vpif_dbg(2, debug, "vpif_mmap\n"); vpif_dbg(2, debug, "vpif_mmap\n");
return vb2_mmap(&common->buffer_queue, vma); if (mutex_lock_interruptible(&common->lock))
return -ERESTARTSYS;
ret = vb2_mmap(&common->buffer_queue, vma);
mutex_unlock(&common->lock);
return ret;
} }
/* /*
...@@ -709,11 +714,15 @@ static unsigned int vpif_poll(struct file *filep, poll_table *wait) ...@@ -709,11 +714,15 @@ static unsigned int vpif_poll(struct file *filep, poll_table *wait)
struct vpif_fh *fh = filep->private_data; struct vpif_fh *fh = filep->private_data;
struct channel_obj *ch = fh->channel; struct channel_obj *ch = fh->channel;
struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
unsigned int res = 0;
if (common->started) if (common->started) {
return vb2_poll(&common->buffer_queue, filep, wait); mutex_lock(&common->lock);
res = vb2_poll(&common->buffer_queue, filep, wait);
mutex_unlock(&common->lock);
}
return 0; return res;
} }
/* /*
...@@ -723,10 +732,10 @@ static unsigned int vpif_poll(struct file *filep, poll_table *wait) ...@@ -723,10 +732,10 @@ static unsigned int vpif_poll(struct file *filep, poll_table *wait)
static int vpif_open(struct file *filep) static int vpif_open(struct file *filep)
{ {
struct video_device *vdev = video_devdata(filep); struct video_device *vdev = video_devdata(filep);
struct channel_obj *ch = NULL; struct channel_obj *ch = video_get_drvdata(vdev);
struct vpif_fh *fh = NULL; struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
struct vpif_fh *fh;
ch = video_get_drvdata(vdev);
/* Allocate memory for the file handle object */ /* Allocate memory for the file handle object */
fh = kzalloc(sizeof(struct vpif_fh), GFP_KERNEL); fh = kzalloc(sizeof(struct vpif_fh), GFP_KERNEL);
if (fh == NULL) { if (fh == NULL) {
...@@ -734,6 +743,10 @@ static int vpif_open(struct file *filep) ...@@ -734,6 +743,10 @@ static int vpif_open(struct file *filep)
return -ENOMEM; return -ENOMEM;
} }
if (mutex_lock_interruptible(&common->lock)) {
kfree(fh);
return -ERESTARTSYS;
}
/* store pointer to fh in private_data member of filep */ /* store pointer to fh in private_data member of filep */
filep->private_data = fh; filep->private_data = fh;
fh->channel = ch; fh->channel = ch;
...@@ -751,6 +764,7 @@ static int vpif_open(struct file *filep) ...@@ -751,6 +764,7 @@ static int vpif_open(struct file *filep)
/* Initialize priority of this instance to default priority */ /* Initialize priority of this instance to default priority */
fh->prio = V4L2_PRIORITY_UNSET; fh->prio = V4L2_PRIORITY_UNSET;
v4l2_prio_open(&ch->prio, &fh->prio); v4l2_prio_open(&ch->prio, &fh->prio);
mutex_unlock(&common->lock);
return 0; return 0;
} }
...@@ -765,6 +779,7 @@ static int vpif_release(struct file *filep) ...@@ -765,6 +779,7 @@ static int vpif_release(struct file *filep)
struct channel_obj *ch = fh->channel; struct channel_obj *ch = fh->channel;
struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
mutex_lock(&common->lock);
/* if this instance is doing IO */ /* if this instance is doing IO */
if (fh->io_allowed[VPIF_VIDEO_INDEX]) { if (fh->io_allowed[VPIF_VIDEO_INDEX]) {
/* Reset io_usrs member of channel object */ /* Reset io_usrs member of channel object */
...@@ -799,6 +814,7 @@ static int vpif_release(struct file *filep) ...@@ -799,6 +814,7 @@ static int vpif_release(struct file *filep)
v4l2_prio_close(&ch->prio, fh->prio); v4l2_prio_close(&ch->prio, fh->prio);
filep->private_data = NULL; filep->private_data = NULL;
fh->initialized = 0; fh->initialized = 0;
mutex_unlock(&common->lock);
kfree(fh); kfree(fh);
return 0; return 0;
...@@ -1789,10 +1805,6 @@ static __init int vpif_probe(struct platform_device *pdev) ...@@ -1789,10 +1805,6 @@ static __init int vpif_probe(struct platform_device *pdev)
v4l2_prio_init(&ch->prio); v4l2_prio_init(&ch->prio);
ch->common[VPIF_VIDEO_INDEX].fmt.type = ch->common[VPIF_VIDEO_INDEX].fmt.type =
V4L2_BUF_TYPE_VIDEO_OUTPUT; V4L2_BUF_TYPE_VIDEO_OUTPUT;
/* 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, &ch->video_dev->flags);
ch->video_dev->lock = &common->lock; ch->video_dev->lock = &common->lock;
/* register video device */ /* register video device */
......
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