diff options
author | Hans Verkuil <hans.verkuil@cisco.com> | 2012-06-23 08:33:25 -0300 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2012-08-09 19:48:07 -0300 |
commit | 0d0c1596b9d62eb44972b9210f80e38722a05465 (patch) | |
tree | 88a5317e6f38a9f4f68e533da60c66c0233f231b | |
parent | 14a09dac5324dea0ac825c3701ffc08709559bcb (diff) |
[media] dt3155v4l: 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: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
-rw-r--r-- | drivers/staging/media/dt3155v4l/dt3155v4l.c | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/drivers/staging/media/dt3155v4l/dt3155v4l.c b/drivers/staging/media/dt3155v4l/dt3155v4l.c index ebe5a27c06f..2e7b711c850 100644 --- a/drivers/staging/media/dt3155v4l/dt3155v4l.c +++ b/drivers/staging/media/dt3155v4l/dt3155v4l.c @@ -381,6 +381,8 @@ dt3155_open(struct file *filp) int ret = 0; struct dt3155_priv *pd = video_drvdata(filp); + if (mutex_lock_interruptible(&pd->mux)) + return -ERESTARTSYS; if (!pd->users) { pd->q = kzalloc(sizeof(*pd->q), GFP_KERNEL); if (!pd->q) { @@ -411,6 +413,7 @@ err_request_irq: kfree(pd->q); pd->q = NULL; err_alloc_queue: + mutex_unlock(&pd->mux); return ret; } @@ -419,6 +422,7 @@ dt3155_release(struct file *filp) { struct dt3155_priv *pd = video_drvdata(filp); + mutex_lock(&pd->mux); pd->users--; BUG_ON(pd->users < 0); if (!pd->users) { @@ -429,6 +433,7 @@ dt3155_release(struct file *filp) kfree(pd->q); pd->q = NULL; } + mutex_unlock(&pd->mux); return 0; } @@ -436,24 +441,38 @@ static ssize_t dt3155_read(struct file *filp, char __user *user, size_t size, loff_t *loff) { struct dt3155_priv *pd = video_drvdata(filp); + ssize_t res; - return vb2_read(pd->q, user, size, loff, filp->f_flags & O_NONBLOCK); + if (mutex_lock_interruptible(&pd->mux)) + return -ERESTARTSYS; + res = vb2_read(pd->q, user, size, loff, filp->f_flags & O_NONBLOCK); + mutex_unlock(&pd->mux); + return res; } static unsigned int dt3155_poll(struct file *filp, struct poll_table_struct *polltbl) { struct dt3155_priv *pd = video_drvdata(filp); + unsigned int res; - return vb2_poll(pd->q, filp, polltbl); + mutex_lock(&pd->mux); + res = vb2_poll(pd->q, filp, polltbl); + mutex_unlock(&pd->mux); + return res; } static int dt3155_mmap(struct file *filp, struct vm_area_struct *vma) { struct dt3155_priv *pd = video_drvdata(filp); + int res; - return vb2_mmap(pd->q, vma); + if (mutex_lock_interruptible(&pd->mux)) + return -ERESTARTSYS; + res = vb2_mmap(pd->q, vma); + mutex_unlock(&pd->mux); + return res; } static const struct v4l2_file_operations dt3155_fops = { @@ -898,10 +917,6 @@ dt3155_probe(struct pci_dev *pdev, const struct pci_device_id *id) INIT_LIST_HEAD(&pd->dmaq); mutex_init(&pd->mux); pd->vdev->lock = &pd->mux; /* for locking v4l2_file_operations */ - /* 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, &pd->vdev->flags); spin_lock_init(&pd->lock); pd->csr2 = csr2_init; pd->config = config_init; |