diff options
author | Hans Verkuil <hans.verkuil@cisco.com> | 2012-06-23 07:33:25 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2012-08-09 18:48:07 -0400 |
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 ebe5a27c06f5..2e7b711c8501 100644 --- a/drivers/staging/media/dt3155v4l/dt3155v4l.c +++ b/drivers/staging/media/dt3155v4l/dt3155v4l.c | |||
@@ -381,6 +381,8 @@ dt3155_open(struct file *filp) | |||
381 | int ret = 0; | 381 | int ret = 0; |
382 | struct dt3155_priv *pd = video_drvdata(filp); | 382 | struct dt3155_priv *pd = video_drvdata(filp); |
383 | 383 | ||
384 | if (mutex_lock_interruptible(&pd->mux)) | ||
385 | return -ERESTARTSYS; | ||
384 | if (!pd->users) { | 386 | if (!pd->users) { |
385 | pd->q = kzalloc(sizeof(*pd->q), GFP_KERNEL); | 387 | pd->q = kzalloc(sizeof(*pd->q), GFP_KERNEL); |
386 | if (!pd->q) { | 388 | if (!pd->q) { |
@@ -411,6 +413,7 @@ err_request_irq: | |||
411 | kfree(pd->q); | 413 | kfree(pd->q); |
412 | pd->q = NULL; | 414 | pd->q = NULL; |
413 | err_alloc_queue: | 415 | err_alloc_queue: |
416 | mutex_unlock(&pd->mux); | ||
414 | return ret; | 417 | return ret; |
415 | } | 418 | } |
416 | 419 | ||
@@ -419,6 +422,7 @@ dt3155_release(struct file *filp) | |||
419 | { | 422 | { |
420 | struct dt3155_priv *pd = video_drvdata(filp); | 423 | struct dt3155_priv *pd = video_drvdata(filp); |
421 | 424 | ||
425 | mutex_lock(&pd->mux); | ||
422 | pd->users--; | 426 | pd->users--; |
423 | BUG_ON(pd->users < 0); | 427 | BUG_ON(pd->users < 0); |
424 | if (!pd->users) { | 428 | if (!pd->users) { |
@@ -429,6 +433,7 @@ dt3155_release(struct file *filp) | |||
429 | kfree(pd->q); | 433 | kfree(pd->q); |
430 | pd->q = NULL; | 434 | pd->q = NULL; |
431 | } | 435 | } |
436 | mutex_unlock(&pd->mux); | ||
432 | return 0; | 437 | return 0; |
433 | } | 438 | } |
434 | 439 | ||
@@ -436,24 +441,38 @@ static ssize_t | |||
436 | dt3155_read(struct file *filp, char __user *user, size_t size, loff_t *loff) | 441 | dt3155_read(struct file *filp, char __user *user, size_t size, loff_t *loff) |
437 | { | 442 | { |
438 | struct dt3155_priv *pd = video_drvdata(filp); | 443 | struct dt3155_priv *pd = video_drvdata(filp); |
444 | ssize_t res; | ||
439 | 445 | ||
440 | return vb2_read(pd->q, user, size, loff, filp->f_flags & O_NONBLOCK); | 446 | if (mutex_lock_interruptible(&pd->mux)) |
447 | return -ERESTARTSYS; | ||
448 | res = vb2_read(pd->q, user, size, loff, filp->f_flags & O_NONBLOCK); | ||
449 | mutex_unlock(&pd->mux); | ||
450 | return res; | ||
441 | } | 451 | } |
442 | 452 | ||
443 | static unsigned int | 453 | static unsigned int |
444 | dt3155_poll(struct file *filp, struct poll_table_struct *polltbl) | 454 | dt3155_poll(struct file *filp, struct poll_table_struct *polltbl) |
445 | { | 455 | { |
446 | struct dt3155_priv *pd = video_drvdata(filp); | 456 | struct dt3155_priv *pd = video_drvdata(filp); |
457 | unsigned int res; | ||
447 | 458 | ||
448 | return vb2_poll(pd->q, filp, polltbl); | 459 | mutex_lock(&pd->mux); |
460 | res = vb2_poll(pd->q, filp, polltbl); | ||
461 | mutex_unlock(&pd->mux); | ||
462 | return res; | ||
449 | } | 463 | } |
450 | 464 | ||
451 | static int | 465 | static int |
452 | dt3155_mmap(struct file *filp, struct vm_area_struct *vma) | 466 | dt3155_mmap(struct file *filp, struct vm_area_struct *vma) |
453 | { | 467 | { |
454 | struct dt3155_priv *pd = video_drvdata(filp); | 468 | struct dt3155_priv *pd = video_drvdata(filp); |
469 | int res; | ||
455 | 470 | ||
456 | return vb2_mmap(pd->q, vma); | 471 | if (mutex_lock_interruptible(&pd->mux)) |
472 | return -ERESTARTSYS; | ||
473 | res = vb2_mmap(pd->q, vma); | ||
474 | mutex_unlock(&pd->mux); | ||
475 | return res; | ||
457 | } | 476 | } |
458 | 477 | ||
459 | static const struct v4l2_file_operations dt3155_fops = { | 478 | static const struct v4l2_file_operations dt3155_fops = { |
@@ -898,10 +917,6 @@ dt3155_probe(struct pci_dev *pdev, const struct pci_device_id *id) | |||
898 | INIT_LIST_HEAD(&pd->dmaq); | 917 | INIT_LIST_HEAD(&pd->dmaq); |
899 | mutex_init(&pd->mux); | 918 | mutex_init(&pd->mux); |
900 | pd->vdev->lock = &pd->mux; /* for locking v4l2_file_operations */ | 919 | pd->vdev->lock = &pd->mux; /* for locking v4l2_file_operations */ |
901 | /* Locking in file operations other than ioctl should be done | ||
902 | by the driver, not the V4L2 core. | ||
903 | This driver needs auditing so that this flag can be removed. */ | ||
904 | set_bit(V4L2_FL_LOCK_ALL_FOPS, &pd->vdev->flags); | ||
905 | spin_lock_init(&pd->lock); | 920 | spin_lock_init(&pd->lock); |
906 | pd->csr2 = csr2_init; | 921 | pd->csr2 = csr2_init; |
907 | pd->config = config_init; | 922 | pd->config = config_init; |