Skip to content

Commit

Permalink
[media] dt3155v4l: remove V4L2_FL_LOCK_ALL_FOPS
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Hans Verkuil authored and Mauro Carvalho Chehab committed Aug 9, 2012
1 parent 14a09da commit 0d0c159
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions drivers/staging/media/dt3155v4l/dt3155v4l.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -411,6 +413,7 @@ dt3155_open(struct file *filp)
kfree(pd->q);
pd->q = NULL;
err_alloc_queue:
mutex_unlock(&pd->mux);
return ret;
}

Expand All @@ -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) {
Expand All @@ -429,31 +433,46 @@ dt3155_release(struct file *filp)
kfree(pd->q);
pd->q = NULL;
}
mutex_unlock(&pd->mux);
return 0;
}

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 = {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 0d0c159

Please sign in to comment.