aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/media
diff options
context:
space:
mode:
authorArjan van de Ven <arjan@infradead.org>2006-01-11 09:55:29 -0500
committerGreg Kroah-Hartman <gregkh@suse.de>2006-03-20 17:49:55 -0500
commit4186ecf8ad16dd05759a09594de6a87e48759ba6 (patch)
tree3ee5292d9f4a36e3eb359b586289ec972bcbaf39 /drivers/usb/media
parent35cce732d9d4d9af6b4ad4d26d8f8c0eddb573a2 (diff)
[PATCH] USB: convert a bunch of USB semaphores to mutexes
the patch below converts a bunch of semaphores-used-as-mutex in the USB code to mutexes Signed-off-by: Arjan van de Ven <arjan@infradead.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb/media')
-rw-r--r--drivers/usb/media/dabusb.c31
-rw-r--r--drivers/usb/media/dabusb.h2
-rw-r--r--drivers/usb/media/ov511.c91
-rw-r--r--drivers/usb/media/ov511.h11
-rw-r--r--drivers/usb/media/se401.c12
-rw-r--r--drivers/usb/media/se401.h3
-rw-r--r--drivers/usb/media/sn9c102.h5
-rw-r--r--drivers/usb/media/sn9c102_core.c156
-rw-r--r--drivers/usb/media/stv680.c13
-rw-r--r--drivers/usb/media/stv680.h2
-rw-r--r--drivers/usb/media/usbvideo.c28
-rw-r--r--drivers/usb/media/usbvideo.h5
-rw-r--r--drivers/usb/media/vicam.c21
-rw-r--r--drivers/usb/media/w9968cf.c75
-rw-r--r--drivers/usb/media/w9968cf.h14
15 files changed, 236 insertions, 233 deletions
diff --git a/drivers/usb/media/dabusb.c b/drivers/usb/media/dabusb.c
index 6f560fe9a519..1774ab7a40d2 100644
--- a/drivers/usb/media/dabusb.c
+++ b/drivers/usb/media/dabusb.c
@@ -38,6 +38,7 @@
38#include <linux/delay.h> 38#include <linux/delay.h>
39#include <linux/usb.h> 39#include <linux/usb.h>
40#include <linux/smp_lock.h> 40#include <linux/smp_lock.h>
41#include <linux/mutex.h>
41 42
42#include "dabusb.h" 43#include "dabusb.h"
43#include "dabfirmware.h" 44#include "dabfirmware.h"
@@ -570,7 +571,7 @@ static ssize_t dabusb_read (struct file *file, char __user *buf, size_t count, l
570 s->readptr = 0; 571 s->readptr = 0;
571 } 572 }
572 } 573 }
573 err: //up(&s->mutex); 574 err: //mutex_unlock(&s->mutex);
574 return ret; 575 return ret;
575} 576}
576 577
@@ -585,10 +586,10 @@ static int dabusb_open (struct inode *inode, struct file *file)
585 s = &dabusb[devnum - DABUSB_MINOR]; 586 s = &dabusb[devnum - DABUSB_MINOR];
586 587
587 dbg("dabusb_open"); 588 dbg("dabusb_open");
588 down (&s->mutex); 589 mutex_lock(&s->mutex);
589 590
590 while (!s->usbdev || s->opened) { 591 while (!s->usbdev || s->opened) {
591 up (&s->mutex); 592 mutex_unlock(&s->mutex);
592 593
593 if (file->f_flags & O_NONBLOCK) { 594 if (file->f_flags & O_NONBLOCK) {
594 return -EBUSY; 595 return -EBUSY;
@@ -598,15 +599,15 @@ static int dabusb_open (struct inode *inode, struct file *file)
598 if (signal_pending (current)) { 599 if (signal_pending (current)) {
599 return -EAGAIN; 600 return -EAGAIN;
600 } 601 }
601 down (&s->mutex); 602 mutex_lock(&s->mutex);
602 } 603 }
603 if (usb_set_interface (s->usbdev, _DABUSB_IF, 1) < 0) { 604 if (usb_set_interface (s->usbdev, _DABUSB_IF, 1) < 0) {
604 up(&s->mutex); 605 mutex_unlock(&s->mutex);
605 err("set_interface failed"); 606 err("set_interface failed");
606 return -EINVAL; 607 return -EINVAL;
607 } 608 }
608 s->opened = 1; 609 s->opened = 1;
609 up (&s->mutex); 610 mutex_unlock(&s->mutex);
610 611
611 file->f_pos = 0; 612 file->f_pos = 0;
612 file->private_data = s; 613 file->private_data = s;
@@ -620,10 +621,10 @@ static int dabusb_release (struct inode *inode, struct file *file)
620 621
621 dbg("dabusb_release"); 622 dbg("dabusb_release");
622 623
623 down (&s->mutex); 624 mutex_lock(&s->mutex);
624 dabusb_stop (s); 625 dabusb_stop (s);
625 dabusb_free_buffers (s); 626 dabusb_free_buffers (s);
626 up (&s->mutex); 627 mutex_unlock(&s->mutex);
627 628
628 if (!s->remove_pending) { 629 if (!s->remove_pending) {
629 if (usb_set_interface (s->usbdev, _DABUSB_IF, 0) < 0) 630 if (usb_set_interface (s->usbdev, _DABUSB_IF, 0) < 0)
@@ -648,10 +649,10 @@ static int dabusb_ioctl (struct inode *inode, struct file *file, unsigned int cm
648 if (s->remove_pending) 649 if (s->remove_pending)
649 return -EIO; 650 return -EIO;
650 651
651 down (&s->mutex); 652 mutex_lock(&s->mutex);
652 653
653 if (!s->usbdev) { 654 if (!s->usbdev) {
654 up (&s->mutex); 655 mutex_unlock(&s->mutex);
655 return -EIO; 656 return -EIO;
656 } 657 }
657 658
@@ -691,7 +692,7 @@ static int dabusb_ioctl (struct inode *inode, struct file *file, unsigned int cm
691 ret = -ENOIOCTLCMD; 692 ret = -ENOIOCTLCMD;
692 break; 693 break;
693 } 694 }
694 up (&s->mutex); 695 mutex_unlock(&s->mutex);
695 return ret; 696 return ret;
696} 697}
697 698
@@ -737,7 +738,7 @@ static int dabusb_probe (struct usb_interface *intf,
737 738
738 s = &dabusb[intf->minor]; 739 s = &dabusb[intf->minor];
739 740
740 down (&s->mutex); 741 mutex_lock(&s->mutex);
741 s->remove_pending = 0; 742 s->remove_pending = 0;
742 s->usbdev = usbdev; 743 s->usbdev = usbdev;
743 s->devnum = intf->minor; 744 s->devnum = intf->minor;
@@ -760,7 +761,7 @@ static int dabusb_probe (struct usb_interface *intf,
760 } 761 }
761 dbg("bound to interface: %d", intf->altsetting->desc.bInterfaceNumber); 762 dbg("bound to interface: %d", intf->altsetting->desc.bInterfaceNumber);
762 usb_set_intfdata (intf, s); 763 usb_set_intfdata (intf, s);
763 up (&s->mutex); 764 mutex_unlock(&s->mutex);
764 765
765 retval = usb_register_dev(intf, &dabusb_class); 766 retval = usb_register_dev(intf, &dabusb_class);
766 if (retval) { 767 if (retval) {
@@ -771,7 +772,7 @@ static int dabusb_probe (struct usb_interface *intf,
771 return 0; 772 return 0;
772 773
773 reject: 774 reject:
774 up (&s->mutex); 775 mutex_unlock(&s->mutex);
775 s->usbdev = NULL; 776 s->usbdev = NULL;
776 return -ENODEV; 777 return -ENODEV;
777} 778}
@@ -828,7 +829,7 @@ static int __init dabusb_init (void)
828 for (u = 0; u < NRDABUSB; u++) { 829 for (u = 0; u < NRDABUSB; u++) {
829 pdabusb_t s = &dabusb[u]; 830 pdabusb_t s = &dabusb[u];
830 memset (s, 0, sizeof (dabusb_t)); 831 memset (s, 0, sizeof (dabusb_t));
831 init_MUTEX (&s->mutex); 832 mutex_init (&s->mutex);
832 s->usbdev = NULL; 833 s->usbdev = NULL;
833 s->total_buffer_size = buffers; 834 s->total_buffer_size = buffers;
834 init_waitqueue_head (&s->wait); 835 init_waitqueue_head (&s->wait);
diff --git a/drivers/usb/media/dabusb.h b/drivers/usb/media/dabusb.h
index 10b666e43abc..96b03e4af8b9 100644
--- a/drivers/usb/media/dabusb.h
+++ b/drivers/usb/media/dabusb.h
@@ -18,7 +18,7 @@ typedef enum { _stopped=0, _started } driver_state_t;
18 18
19typedef struct 19typedef struct
20{ 20{
21 struct semaphore mutex; 21 struct mutex mutex;
22 struct usb_device *usbdev; 22 struct usb_device *usbdev;
23 wait_queue_head_t wait; 23 wait_queue_head_t wait;
24 wait_queue_head_t remove_ok; 24 wait_queue_head_t remove_ok;
diff --git a/drivers/usb/media/ov511.c b/drivers/usb/media/ov511.c
index 51e9cc06f7e3..cfec8c61574e 100644
--- a/drivers/usb/media/ov511.c
+++ b/drivers/usb/media/ov511.c
@@ -365,14 +365,14 @@ reg_w(struct usb_ov511 *ov, unsigned char reg, unsigned char value)
365 365
366 PDEBUG(5, "0x%02X:0x%02X", reg, value); 366 PDEBUG(5, "0x%02X:0x%02X", reg, value);
367 367
368 down(&ov->cbuf_lock); 368 mutex_lock(&ov->cbuf_lock);
369 ov->cbuf[0] = value; 369 ov->cbuf[0] = value;
370 rc = usb_control_msg(ov->dev, 370 rc = usb_control_msg(ov->dev,
371 usb_sndctrlpipe(ov->dev, 0), 371 usb_sndctrlpipe(ov->dev, 0),
372 (ov->bclass == BCL_OV518)?1:2 /* REG_IO */, 372 (ov->bclass == BCL_OV518)?1:2 /* REG_IO */,
373 USB_TYPE_VENDOR | USB_RECIP_DEVICE, 373 USB_TYPE_VENDOR | USB_RECIP_DEVICE,
374 0, (__u16)reg, &ov->cbuf[0], 1, 1000); 374 0, (__u16)reg, &ov->cbuf[0], 1, 1000);
375 up(&ov->cbuf_lock); 375 mutex_unlock(&ov->cbuf_lock);
376 376
377 if (rc < 0) 377 if (rc < 0)
378 err("reg write: error %d: %s", rc, symbolic(urb_errlist, rc)); 378 err("reg write: error %d: %s", rc, symbolic(urb_errlist, rc));
@@ -387,7 +387,7 @@ reg_r(struct usb_ov511 *ov, unsigned char reg)
387{ 387{
388 int rc; 388 int rc;
389 389
390 down(&ov->cbuf_lock); 390 mutex_lock(&ov->cbuf_lock);
391 rc = usb_control_msg(ov->dev, 391 rc = usb_control_msg(ov->dev,
392 usb_rcvctrlpipe(ov->dev, 0), 392 usb_rcvctrlpipe(ov->dev, 0),
393 (ov->bclass == BCL_OV518)?1:3 /* REG_IO */, 393 (ov->bclass == BCL_OV518)?1:3 /* REG_IO */,
@@ -401,7 +401,7 @@ reg_r(struct usb_ov511 *ov, unsigned char reg)
401 PDEBUG(5, "0x%02X:0x%02X", reg, ov->cbuf[0]); 401 PDEBUG(5, "0x%02X:0x%02X", reg, ov->cbuf[0]);
402 } 402 }
403 403
404 up(&ov->cbuf_lock); 404 mutex_unlock(&ov->cbuf_lock);
405 405
406 return rc; 406 return rc;
407} 407}
@@ -444,7 +444,7 @@ ov518_reg_w32(struct usb_ov511 *ov, unsigned char reg, u32 val, int n)
444 444
445 PDEBUG(5, "0x%02X:%7d, n=%d", reg, val, n); 445 PDEBUG(5, "0x%02X:%7d, n=%d", reg, val, n);
446 446
447 down(&ov->cbuf_lock); 447 mutex_lock(&ov->cbuf_lock);
448 448
449 *((__le32 *)ov->cbuf) = __cpu_to_le32(val); 449 *((__le32 *)ov->cbuf) = __cpu_to_le32(val);
450 450
@@ -453,7 +453,7 @@ ov518_reg_w32(struct usb_ov511 *ov, unsigned char reg, u32 val, int n)
453 1 /* REG_IO */, 453 1 /* REG_IO */,
454 USB_TYPE_VENDOR | USB_RECIP_DEVICE, 454 USB_TYPE_VENDOR | USB_RECIP_DEVICE,
455 0, (__u16)reg, ov->cbuf, n, 1000); 455 0, (__u16)reg, ov->cbuf, n, 1000);
456 up(&ov->cbuf_lock); 456 mutex_unlock(&ov->cbuf_lock);
457 457
458 if (rc < 0) 458 if (rc < 0)
459 err("reg write multiple: error %d: %s", rc, 459 err("reg write multiple: error %d: %s", rc,
@@ -768,14 +768,14 @@ i2c_r(struct usb_ov511 *ov, unsigned char reg)
768{ 768{
769 int rc; 769 int rc;
770 770
771 down(&ov->i2c_lock); 771 mutex_lock(&ov->i2c_lock);
772 772
773 if (ov->bclass == BCL_OV518) 773 if (ov->bclass == BCL_OV518)
774 rc = ov518_i2c_read_internal(ov, reg); 774 rc = ov518_i2c_read_internal(ov, reg);
775 else 775 else
776 rc = ov511_i2c_read_internal(ov, reg); 776 rc = ov511_i2c_read_internal(ov, reg);
777 777
778 up(&ov->i2c_lock); 778 mutex_unlock(&ov->i2c_lock);
779 779
780 return rc; 780 return rc;
781} 781}
@@ -785,14 +785,14 @@ i2c_w(struct usb_ov511 *ov, unsigned char reg, unsigned char value)
785{ 785{
786 int rc; 786 int rc;
787 787
788 down(&ov->i2c_lock); 788 mutex_lock(&ov->i2c_lock);
789 789
790 if (ov->bclass == BCL_OV518) 790 if (ov->bclass == BCL_OV518)
791 rc = ov518_i2c_write_internal(ov, reg, value); 791 rc = ov518_i2c_write_internal(ov, reg, value);
792 else 792 else
793 rc = ov511_i2c_write_internal(ov, reg, value); 793 rc = ov511_i2c_write_internal(ov, reg, value);
794 794
795 up(&ov->i2c_lock); 795 mutex_unlock(&ov->i2c_lock);
796 796
797 return rc; 797 return rc;
798} 798}
@@ -842,9 +842,9 @@ i2c_w_mask(struct usb_ov511 *ov,
842{ 842{
843 int rc; 843 int rc;
844 844
845 down(&ov->i2c_lock); 845 mutex_lock(&ov->i2c_lock);
846 rc = ov51x_i2c_write_mask_internal(ov, reg, value, mask); 846 rc = ov51x_i2c_write_mask_internal(ov, reg, value, mask);
847 up(&ov->i2c_lock); 847 mutex_unlock(&ov->i2c_lock);
848 848
849 return rc; 849 return rc;
850} 850}
@@ -880,7 +880,7 @@ i2c_w_slave(struct usb_ov511 *ov,
880{ 880{
881 int rc = 0; 881 int rc = 0;
882 882
883 down(&ov->i2c_lock); 883 mutex_lock(&ov->i2c_lock);
884 884
885 /* Set new slave IDs */ 885 /* Set new slave IDs */
886 rc = i2c_set_slave_internal(ov, slave); 886 rc = i2c_set_slave_internal(ov, slave);
@@ -894,7 +894,7 @@ out:
894 if (i2c_set_slave_internal(ov, ov->primary_i2c_slave) < 0) 894 if (i2c_set_slave_internal(ov, ov->primary_i2c_slave) < 0)
895 err("Couldn't restore primary I2C slave"); 895 err("Couldn't restore primary I2C slave");
896 896
897 up(&ov->i2c_lock); 897 mutex_unlock(&ov->i2c_lock);
898 return rc; 898 return rc;
899} 899}
900 900
@@ -906,7 +906,7 @@ i2c_r_slave(struct usb_ov511 *ov,
906{ 906{
907 int rc; 907 int rc;
908 908
909 down(&ov->i2c_lock); 909 mutex_lock(&ov->i2c_lock);
910 910
911 /* Set new slave IDs */ 911 /* Set new slave IDs */
912 rc = i2c_set_slave_internal(ov, slave); 912 rc = i2c_set_slave_internal(ov, slave);
@@ -923,7 +923,7 @@ out:
923 if (i2c_set_slave_internal(ov, ov->primary_i2c_slave) < 0) 923 if (i2c_set_slave_internal(ov, ov->primary_i2c_slave) < 0)
924 err("Couldn't restore primary I2C slave"); 924 err("Couldn't restore primary I2C slave");
925 925
926 up(&ov->i2c_lock); 926 mutex_unlock(&ov->i2c_lock);
927 return rc; 927 return rc;
928} 928}
929 929
@@ -933,7 +933,7 @@ ov51x_set_slave_ids(struct usb_ov511 *ov, unsigned char sid)
933{ 933{
934 int rc; 934 int rc;
935 935
936 down(&ov->i2c_lock); 936 mutex_lock(&ov->i2c_lock);
937 937
938 rc = i2c_set_slave_internal(ov, sid); 938 rc = i2c_set_slave_internal(ov, sid);
939 if (rc < 0) 939 if (rc < 0)
@@ -942,7 +942,7 @@ ov51x_set_slave_ids(struct usb_ov511 *ov, unsigned char sid)
942 // FIXME: Is this actually necessary? 942 // FIXME: Is this actually necessary?
943 rc = ov51x_reset(ov, OV511_RESET_NOREGS); 943 rc = ov51x_reset(ov, OV511_RESET_NOREGS);
944out: 944out:
945 up(&ov->i2c_lock); 945 mutex_unlock(&ov->i2c_lock);
946 return rc; 946 return rc;
947} 947}
948 948
@@ -3832,7 +3832,7 @@ ov51x_alloc(struct usb_ov511 *ov)
3832 const int raw_bufsize = OV511_NUMFRAMES * MAX_RAW_DATA_SIZE(w, h); 3832 const int raw_bufsize = OV511_NUMFRAMES * MAX_RAW_DATA_SIZE(w, h);
3833 3833
3834 PDEBUG(4, "entered"); 3834 PDEBUG(4, "entered");
3835 down(&ov->buf_lock); 3835 mutex_lock(&ov->buf_lock);
3836 3836
3837 if (ov->buf_state == BUF_ALLOCATED) 3837 if (ov->buf_state == BUF_ALLOCATED)
3838 goto out; 3838 goto out;
@@ -3879,12 +3879,12 @@ ov51x_alloc(struct usb_ov511 *ov)
3879 3879
3880 ov->buf_state = BUF_ALLOCATED; 3880 ov->buf_state = BUF_ALLOCATED;
3881out: 3881out:
3882 up(&ov->buf_lock); 3882 mutex_unlock(&ov->buf_lock);
3883 PDEBUG(4, "leaving"); 3883 PDEBUG(4, "leaving");
3884 return 0; 3884 return 0;
3885error: 3885error:
3886 ov51x_do_dealloc(ov); 3886 ov51x_do_dealloc(ov);
3887 up(&ov->buf_lock); 3887 mutex_unlock(&ov->buf_lock);
3888 PDEBUG(4, "errored"); 3888 PDEBUG(4, "errored");
3889 return -ENOMEM; 3889 return -ENOMEM;
3890} 3890}
@@ -3893,9 +3893,9 @@ static void
3893ov51x_dealloc(struct usb_ov511 *ov) 3893ov51x_dealloc(struct usb_ov511 *ov)
3894{ 3894{
3895 PDEBUG(4, "entered"); 3895 PDEBUG(4, "entered");
3896 down(&ov->buf_lock); 3896 mutex_lock(&ov->buf_lock);
3897 ov51x_do_dealloc(ov); 3897 ov51x_do_dealloc(ov);
3898 up(&ov->buf_lock); 3898 mutex_unlock(&ov->buf_lock);
3899 PDEBUG(4, "leaving"); 3899 PDEBUG(4, "leaving");
3900} 3900}
3901 3901
@@ -3914,7 +3914,7 @@ ov51x_v4l1_open(struct inode *inode, struct file *file)
3914 3914
3915 PDEBUG(4, "opening"); 3915 PDEBUG(4, "opening");
3916 3916
3917 down(&ov->lock); 3917 mutex_lock(&ov->lock);
3918 3918
3919 err = -EBUSY; 3919 err = -EBUSY;
3920 if (ov->user) 3920 if (ov->user)
@@ -3958,7 +3958,7 @@ ov51x_v4l1_open(struct inode *inode, struct file *file)
3958 ov51x_led_control(ov, 1); 3958 ov51x_led_control(ov, 1);
3959 3959
3960out: 3960out:
3961 up(&ov->lock); 3961 mutex_unlock(&ov->lock);
3962 return err; 3962 return err;
3963} 3963}
3964 3964
@@ -3970,7 +3970,7 @@ ov51x_v4l1_close(struct inode *inode, struct file *file)
3970 3970
3971 PDEBUG(4, "ov511_close"); 3971 PDEBUG(4, "ov511_close");
3972 3972
3973 down(&ov->lock); 3973 mutex_lock(&ov->lock);
3974 3974
3975 ov->user--; 3975 ov->user--;
3976 ov51x_stop_isoc(ov); 3976 ov51x_stop_isoc(ov);
@@ -3981,15 +3981,15 @@ ov51x_v4l1_close(struct inode *inode, struct file *file)
3981 if (ov->dev) 3981 if (ov->dev)
3982 ov51x_dealloc(ov); 3982 ov51x_dealloc(ov);
3983 3983
3984 up(&ov->lock); 3984 mutex_unlock(&ov->lock);
3985 3985
3986 /* Device unplugged while open. Only a minimum of unregistration is done 3986 /* Device unplugged while open. Only a minimum of unregistration is done
3987 * here; the disconnect callback already did the rest. */ 3987 * here; the disconnect callback already did the rest. */
3988 if (!ov->dev) { 3988 if (!ov->dev) {
3989 down(&ov->cbuf_lock); 3989 mutex_lock(&ov->cbuf_lock);
3990 kfree(ov->cbuf); 3990 kfree(ov->cbuf);
3991 ov->cbuf = NULL; 3991 ov->cbuf = NULL;
3992 up(&ov->cbuf_lock); 3992 mutex_unlock(&ov->cbuf_lock);
3993 3993
3994 ov51x_dealloc(ov); 3994 ov51x_dealloc(ov);
3995 kfree(ov); 3995 kfree(ov);
@@ -4449,12 +4449,12 @@ ov51x_v4l1_ioctl(struct inode *inode, struct file *file,
4449 struct usb_ov511 *ov = video_get_drvdata(vdev); 4449 struct usb_ov511 *ov = video_get_drvdata(vdev);
4450 int rc; 4450 int rc;
4451 4451
4452 if (down_interruptible(&ov->lock)) 4452 if (mutex_lock_interruptible(&ov->lock))
4453 return -EINTR; 4453 return -EINTR;
4454 4454
4455 rc = video_usercopy(inode, file, cmd, arg, ov51x_v4l1_ioctl_internal); 4455 rc = video_usercopy(inode, file, cmd, arg, ov51x_v4l1_ioctl_internal);
4456 4456
4457 up(&ov->lock); 4457 mutex_unlock(&ov->lock);
4458 return rc; 4458 return rc;
4459} 4459}
4460 4460
@@ -4468,7 +4468,7 @@ ov51x_v4l1_read(struct file *file, char __user *buf, size_t cnt, loff_t *ppos)
4468 int i, rc = 0, frmx = -1; 4468 int i, rc = 0, frmx = -1;
4469 struct ov511_frame *frame; 4469 struct ov511_frame *frame;
4470 4470
4471 if (down_interruptible(&ov->lock)) 4471 if (mutex_lock_interruptible(&ov->lock))
4472 return -EINTR; 4472 return -EINTR;
4473 4473
4474 PDEBUG(4, "%ld bytes, noblock=%d", count, noblock); 4474 PDEBUG(4, "%ld bytes, noblock=%d", count, noblock);
@@ -4604,11 +4604,11 @@ restart:
4604 4604
4605 PDEBUG(4, "read finished, returning %ld (sweet)", count); 4605 PDEBUG(4, "read finished, returning %ld (sweet)", count);
4606 4606
4607 up(&ov->lock); 4607 mutex_unlock(&ov->lock);
4608 return count; 4608 return count;
4609 4609
4610error: 4610error:
4611 up(&ov->lock); 4611 mutex_unlock(&ov->lock);
4612 return rc; 4612 return rc;
4613} 4613}
4614 4614
@@ -4631,14 +4631,14 @@ ov51x_v4l1_mmap(struct file *file, struct vm_area_struct *vma)
4631 + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1)))) 4631 + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1))))
4632 return -EINVAL; 4632 return -EINVAL;
4633 4633
4634 if (down_interruptible(&ov->lock)) 4634 if (mutex_lock_interruptible(&ov->lock))
4635 return -EINTR; 4635 return -EINTR;
4636 4636
4637 pos = (unsigned long)ov->fbuf; 4637 pos = (unsigned long)ov->fbuf;
4638 while (size > 0) { 4638 while (size > 0) {
4639 page = vmalloc_to_pfn((void *)pos); 4639 page = vmalloc_to_pfn((void *)pos);
4640 if (remap_pfn_range(vma, start, page, PAGE_SIZE, PAGE_SHARED)) { 4640 if (remap_pfn_range(vma, start, page, PAGE_SIZE, PAGE_SHARED)) {
4641 up(&ov->lock); 4641 mutex_unlock(&ov->lock);
4642 return -EAGAIN; 4642 return -EAGAIN;
4643 } 4643 }
4644 start += PAGE_SIZE; 4644 start += PAGE_SIZE;
@@ -4649,7 +4649,7 @@ ov51x_v4l1_mmap(struct file *file, struct vm_area_struct *vma)
4649 size = 0; 4649 size = 0;
4650 } 4650 }
4651 4651
4652 up(&ov->lock); 4652 mutex_unlock(&ov->lock);
4653 return 0; 4653 return 0;
4654} 4654}
4655 4655
@@ -5738,11 +5738,10 @@ ov51x_probe(struct usb_interface *intf, const struct usb_device_id *id)
5738 5738
5739 init_waitqueue_head(&ov->wq); 5739 init_waitqueue_head(&ov->wq);
5740 5740
5741 init_MUTEX(&ov->lock); /* to 1 == available */ 5741 mutex_init(&ov->lock); /* to 1 == available */
5742 init_MUTEX(&ov->buf_lock); 5742 mutex_init(&ov->buf_lock);
5743 init_MUTEX(&ov->param_lock); 5743 mutex_init(&ov->i2c_lock);
5744 init_MUTEX(&ov->i2c_lock); 5744 mutex_init(&ov->cbuf_lock);
5745 init_MUTEX(&ov->cbuf_lock);
5746 5745
5747 ov->buf_state = BUF_NOT_ALLOCATED; 5746 ov->buf_state = BUF_NOT_ALLOCATED;
5748 5747
@@ -5833,10 +5832,10 @@ error:
5833 } 5832 }
5834 5833
5835 if (ov->cbuf) { 5834 if (ov->cbuf) {
5836 down(&ov->cbuf_lock); 5835 mutex_lock(&ov->cbuf_lock);
5837 kfree(ov->cbuf); 5836 kfree(ov->cbuf);
5838 ov->cbuf = NULL; 5837 ov->cbuf = NULL;
5839 up(&ov->cbuf_lock); 5838 mutex_unlock(&ov->cbuf_lock);
5840 } 5839 }
5841 5840
5842 kfree(ov); 5841 kfree(ov);
@@ -5881,10 +5880,10 @@ ov51x_disconnect(struct usb_interface *intf)
5881 5880
5882 /* Free the memory */ 5881 /* Free the memory */
5883 if (ov && !ov->user) { 5882 if (ov && !ov->user) {
5884 down(&ov->cbuf_lock); 5883 mutex_lock(&ov->cbuf_lock);
5885 kfree(ov->cbuf); 5884 kfree(ov->cbuf);
5886 ov->cbuf = NULL; 5885 ov->cbuf = NULL;
5887 up(&ov->cbuf_lock); 5886 mutex_unlock(&ov->cbuf_lock);
5888 5887
5889 ov51x_dealloc(ov); 5888 ov51x_dealloc(ov);
5890 kfree(ov); 5889 kfree(ov);
diff --git a/drivers/usb/media/ov511.h b/drivers/usb/media/ov511.h
index 086509a137c6..bce9b3633889 100644
--- a/drivers/usb/media/ov511.h
+++ b/drivers/usb/media/ov511.h
@@ -5,6 +5,7 @@
5#include <linux/videodev.h> 5#include <linux/videodev.h>
6#include <linux/smp_lock.h> 6#include <linux/smp_lock.h>
7#include <linux/usb.h> 7#include <linux/usb.h>
8#include <linux/mutex.h>
8 9
9#define OV511_DEBUG /* Turn on debug messages */ 10#define OV511_DEBUG /* Turn on debug messages */
10 11
@@ -435,7 +436,7 @@ struct usb_ov511 {
435 436
436 int led_policy; /* LED: off|on|auto; OV511+ only */ 437 int led_policy; /* LED: off|on|auto; OV511+ only */
437 438
438 struct semaphore lock; /* Serializes user-accessible operations */ 439 struct mutex lock; /* Serializes user-accessible operations */
439 int user; /* user count for exclusive use */ 440 int user; /* user count for exclusive use */
440 441
441 int streaming; /* Are we streaming Isochronous? */ 442 int streaming; /* Are we streaming Isochronous? */
@@ -473,11 +474,9 @@ struct usb_ov511 {
473 int packet_size; /* Frame size per isoc desc */ 474 int packet_size; /* Frame size per isoc desc */
474 int packet_numbering; /* Is ISO frame numbering enabled? */ 475 int packet_numbering; /* Is ISO frame numbering enabled? */
475 476
476 struct semaphore param_lock; /* params lock for this camera */
477
478 /* Framebuffer/sbuf management */ 477 /* Framebuffer/sbuf management */
479 int buf_state; 478 int buf_state;
480 struct semaphore buf_lock; 479 struct mutex buf_lock;
481 480
482 struct ov51x_decomp_ops *decomp_ops; 481 struct ov51x_decomp_ops *decomp_ops;
483 482
@@ -494,12 +493,12 @@ struct usb_ov511 {
494 int pal; /* Device is designed for PAL resolution */ 493 int pal; /* Device is designed for PAL resolution */
495 494
496 /* I2C interface */ 495 /* I2C interface */
497 struct semaphore i2c_lock; /* Protect I2C controller regs */ 496 struct mutex i2c_lock; /* Protect I2C controller regs */
498 unsigned char primary_i2c_slave; /* I2C write id of sensor */ 497 unsigned char primary_i2c_slave; /* I2C write id of sensor */
499 498
500 /* Control transaction stuff */ 499 /* Control transaction stuff */
501 unsigned char *cbuf; /* Buffer for payload */ 500 unsigned char *cbuf; /* Buffer for payload */
502 struct semaphore cbuf_lock; 501 struct mutex cbuf_lock;
503}; 502};
504 503
505/* Used to represent a list of values and their respective symbolic names */ 504/* Used to represent a list of values and their respective symbolic names */
diff --git a/drivers/usb/media/se401.c b/drivers/usb/media/se401.c
index 2ba562285fda..8c3b1ad8a8fd 100644
--- a/drivers/usb/media/se401.c
+++ b/drivers/usb/media/se401.c
@@ -1157,21 +1157,21 @@ static int se401_mmap(struct file *file, struct vm_area_struct *vma)
1157 unsigned long size = vma->vm_end-vma->vm_start; 1157 unsigned long size = vma->vm_end-vma->vm_start;
1158 unsigned long page, pos; 1158 unsigned long page, pos;
1159 1159
1160 down(&se401->lock); 1160 mutex_lock(&se401->lock);
1161 1161
1162 if (se401->dev == NULL) { 1162 if (se401->dev == NULL) {
1163 up(&se401->lock); 1163 mutex_unlock(&se401->lock);
1164 return -EIO; 1164 return -EIO;
1165 } 1165 }
1166 if (size > (((SE401_NUMFRAMES * se401->maxframesize) + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1))) { 1166 if (size > (((SE401_NUMFRAMES * se401->maxframesize) + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1))) {
1167 up(&se401->lock); 1167 mutex_unlock(&se401->lock);
1168 return -EINVAL; 1168 return -EINVAL;
1169 } 1169 }
1170 pos = (unsigned long)se401->fbuf; 1170 pos = (unsigned long)se401->fbuf;
1171 while (size > 0) { 1171 while (size > 0) {
1172 page = vmalloc_to_pfn((void *)pos); 1172 page = vmalloc_to_pfn((void *)pos);
1173 if (remap_pfn_range(vma, start, page, PAGE_SIZE, PAGE_SHARED)) { 1173 if (remap_pfn_range(vma, start, page, PAGE_SIZE, PAGE_SHARED)) {
1174 up(&se401->lock); 1174 mutex_unlock(&se401->lock);
1175 return -EAGAIN; 1175 return -EAGAIN;
1176 } 1176 }
1177 start += PAGE_SIZE; 1177 start += PAGE_SIZE;
@@ -1181,7 +1181,7 @@ static int se401_mmap(struct file *file, struct vm_area_struct *vma)
1181 else 1181 else
1182 size = 0; 1182 size = 0;
1183 } 1183 }
1184 up(&se401->lock); 1184 mutex_unlock(&se401->lock);
1185 1185
1186 return 0; 1186 return 0;
1187} 1187}
@@ -1366,7 +1366,7 @@ static int se401_probe(struct usb_interface *intf,
1366 memcpy(&se401->vdev, &se401_template, sizeof(se401_template)); 1366 memcpy(&se401->vdev, &se401_template, sizeof(se401_template));
1367 memcpy(se401->vdev.name, se401->camera_name, strlen(se401->camera_name)); 1367 memcpy(se401->vdev.name, se401->camera_name, strlen(se401->camera_name));
1368 init_waitqueue_head(&se401->wq); 1368 init_waitqueue_head(&se401->wq);
1369 init_MUTEX(&se401->lock); 1369 mutex_init(&se401->lock);
1370 wmb(); 1370 wmb();
1371 1371
1372 if (video_register_device(&se401->vdev, VFL_TYPE_GRABBER, video_nr) == -1) { 1372 if (video_register_device(&se401->vdev, VFL_TYPE_GRABBER, video_nr) == -1) {
diff --git a/drivers/usb/media/se401.h b/drivers/usb/media/se401.h
index 2e5846f1eb20..e88a40d4c86a 100644
--- a/drivers/usb/media/se401.h
+++ b/drivers/usb/media/se401.h
@@ -5,6 +5,7 @@
5#include <asm/uaccess.h> 5#include <asm/uaccess.h>
6#include <linux/videodev.h> 6#include <linux/videodev.h>
7#include <linux/smp_lock.h> 7#include <linux/smp_lock.h>
8#include <linux/mutex.h>
8 9
9#define se401_DEBUG /* Turn on debug messages */ 10#define se401_DEBUG /* Turn on debug messages */
10 11
@@ -189,7 +190,7 @@ struct usb_se401 {
189 int maxframesize; 190 int maxframesize;
190 int cframesize; /* current framesize */ 191 int cframesize; /* current framesize */
191 192
192 struct semaphore lock; 193 struct mutex lock;
193 int user; /* user count for exclusive use */ 194 int user; /* user count for exclusive use */
194 int removed; /* device disconnected */ 195 int removed; /* device disconnected */
195 196
diff --git a/drivers/usb/media/sn9c102.h b/drivers/usb/media/sn9c102.h
index 17d60c1eea7e..59e44be27cb4 100644
--- a/drivers/usb/media/sn9c102.h
+++ b/drivers/usb/media/sn9c102.h
@@ -33,6 +33,7 @@
33#include <linux/types.h> 33#include <linux/types.h>
34#include <linux/param.h> 34#include <linux/param.h>
35#include <linux/rwsem.h> 35#include <linux/rwsem.h>
36#include <linux/mutex.h>
36#include <asm/semaphore.h> 37#include <asm/semaphore.h>
37 38
38#include "sn9c102_sensor.h" 39#include "sn9c102_sensor.h"
@@ -109,7 +110,7 @@ struct sn9c102_module_param {
109 u8 force_munmap; 110 u8 force_munmap;
110}; 111};
111 112
112static DECLARE_MUTEX(sn9c102_sysfs_lock); 113static DEFINE_MUTEX(sn9c102_sysfs_lock);
113static DECLARE_RWSEM(sn9c102_disconnect); 114static DECLARE_RWSEM(sn9c102_disconnect);
114 115
115struct sn9c102_device { 116struct sn9c102_device {
@@ -141,7 +142,7 @@ struct sn9c102_device {
141 enum sn9c102_dev_state state; 142 enum sn9c102_dev_state state;
142 u8 users; 143 u8 users;
143 144
144 struct semaphore dev_sem, fileop_sem; 145 struct mutex dev_mutex, fileop_mutex;
145 spinlock_t queue_lock; 146 spinlock_t queue_lock;
146 wait_queue_head_t open, wait_frame, wait_stream; 147 wait_queue_head_t open, wait_frame, wait_stream;
147}; 148};
diff --git a/drivers/usb/media/sn9c102_core.c b/drivers/usb/media/sn9c102_core.c
index c81397e4714b..30119080871b 100644
--- a/drivers/usb/media/sn9c102_core.c
+++ b/drivers/usb/media/sn9c102_core.c
@@ -866,18 +866,18 @@ static ssize_t sn9c102_show_reg(struct class_device* cd, char* buf)
866 struct sn9c102_device* cam; 866 struct sn9c102_device* cam;
867 ssize_t count; 867 ssize_t count;
868 868
869 if (down_interruptible(&sn9c102_sysfs_lock)) 869 if (mutex_lock_interruptible(&sn9c102_sysfs_lock))
870 return -ERESTARTSYS; 870 return -ERESTARTSYS;
871 871
872 cam = video_get_drvdata(to_video_device(cd)); 872 cam = video_get_drvdata(to_video_device(cd));
873 if (!cam) { 873 if (!cam) {
874 up(&sn9c102_sysfs_lock); 874 mutex_unlock(&sn9c102_sysfs_lock);
875 return -ENODEV; 875 return -ENODEV;
876 } 876 }
877 877
878 count = sprintf(buf, "%u\n", cam->sysfs.reg); 878 count = sprintf(buf, "%u\n", cam->sysfs.reg);
879 879
880 up(&sn9c102_sysfs_lock); 880 mutex_unlock(&sn9c102_sysfs_lock);
881 881
882 return count; 882 return count;
883} 883}
@@ -890,18 +890,18 @@ sn9c102_store_reg(struct class_device* cd, const char* buf, size_t len)
890 u8 index; 890 u8 index;
891 ssize_t count; 891 ssize_t count;
892 892
893 if (down_interruptible(&sn9c102_sysfs_lock)) 893 if (mutex_lock_interruptible(&sn9c102_sysfs_lock))
894 return -ERESTARTSYS; 894 return -ERESTARTSYS;
895 895
896 cam = video_get_drvdata(to_video_device(cd)); 896 cam = video_get_drvdata(to_video_device(cd));
897 if (!cam) { 897 if (!cam) {
898 up(&sn9c102_sysfs_lock); 898 mutex_unlock(&sn9c102_sysfs_lock);
899 return -ENODEV; 899 return -ENODEV;
900 } 900 }
901 901
902 index = sn9c102_strtou8(buf, len, &count); 902 index = sn9c102_strtou8(buf, len, &count);
903 if (index > 0x1f || !count) { 903 if (index > 0x1f || !count) {
904 up(&sn9c102_sysfs_lock); 904 mutex_unlock(&sn9c102_sysfs_lock);
905 return -EINVAL; 905 return -EINVAL;
906 } 906 }
907 907
@@ -910,7 +910,7 @@ sn9c102_store_reg(struct class_device* cd, const char* buf, size_t len)
910 DBG(2, "Moved SN9C10X register index to 0x%02X", cam->sysfs.reg); 910 DBG(2, "Moved SN9C10X register index to 0x%02X", cam->sysfs.reg);
911 DBG(3, "Written bytes: %zd", count); 911 DBG(3, "Written bytes: %zd", count);
912 912
913 up(&sn9c102_sysfs_lock); 913 mutex_unlock(&sn9c102_sysfs_lock);
914 914
915 return count; 915 return count;
916} 916}
@@ -922,17 +922,17 @@ static ssize_t sn9c102_show_val(struct class_device* cd, char* buf)
922 ssize_t count; 922 ssize_t count;
923 int val; 923 int val;
924 924
925 if (down_interruptible(&sn9c102_sysfs_lock)) 925 if (mutex_lock_interruptible(&sn9c102_sysfs_lock))
926 return -ERESTARTSYS; 926 return -ERESTARTSYS;
927 927
928 cam = video_get_drvdata(to_video_device(cd)); 928 cam = video_get_drvdata(to_video_device(cd));
929 if (!cam) { 929 if (!cam) {
930 up(&sn9c102_sysfs_lock); 930 mutex_unlock(&sn9c102_sysfs_lock);
931 return -ENODEV; 931 return -ENODEV;
932 } 932 }
933 933
934 if ((val = sn9c102_read_reg(cam, cam->sysfs.reg)) < 0) { 934 if ((val = sn9c102_read_reg(cam, cam->sysfs.reg)) < 0) {
935 up(&sn9c102_sysfs_lock); 935 mutex_unlock(&sn9c102_sysfs_lock);
936 return -EIO; 936 return -EIO;
937 } 937 }
938 938
@@ -940,7 +940,7 @@ static ssize_t sn9c102_show_val(struct class_device* cd, char* buf)
940 940
941 DBG(3, "Read bytes: %zd", count); 941 DBG(3, "Read bytes: %zd", count);
942 942
943 up(&sn9c102_sysfs_lock); 943 mutex_unlock(&sn9c102_sysfs_lock);
944 944
945 return count; 945 return count;
946} 946}
@@ -954,24 +954,24 @@ sn9c102_store_val(struct class_device* cd, const char* buf, size_t len)
954 ssize_t count; 954 ssize_t count;
955 int err; 955 int err;
956 956
957 if (down_interruptible(&sn9c102_sysfs_lock)) 957 if (mutex_lock_interruptible(&sn9c102_sysfs_lock))
958 return -ERESTARTSYS; 958 return -ERESTARTSYS;
959 959
960 cam = video_get_drvdata(to_video_device(cd)); 960 cam = video_get_drvdata(to_video_device(cd));
961 if (!cam) { 961 if (!cam) {
962 up(&sn9c102_sysfs_lock); 962 mutex_unlock(&sn9c102_sysfs_lock);
963 return -ENODEV; 963 return -ENODEV;
964 } 964 }
965 965
966 value = sn9c102_strtou8(buf, len, &count); 966 value = sn9c102_strtou8(buf, len, &count);
967 if (!count) { 967 if (!count) {
968 up(&sn9c102_sysfs_lock); 968 mutex_unlock(&sn9c102_sysfs_lock);
969 return -EINVAL; 969 return -EINVAL;
970 } 970 }
971 971
972 err = sn9c102_write_reg(cam, value, cam->sysfs.reg); 972 err = sn9c102_write_reg(cam, value, cam->sysfs.reg);
973 if (err) { 973 if (err) {
974 up(&sn9c102_sysfs_lock); 974 mutex_unlock(&sn9c102_sysfs_lock);
975 return -EIO; 975 return -EIO;
976 } 976 }
977 977
@@ -979,7 +979,7 @@ sn9c102_store_val(struct class_device* cd, const char* buf, size_t len)
979 cam->sysfs.reg, value); 979 cam->sysfs.reg, value);
980 DBG(3, "Written bytes: %zd", count); 980 DBG(3, "Written bytes: %zd", count);
981 981
982 up(&sn9c102_sysfs_lock); 982 mutex_unlock(&sn9c102_sysfs_lock);
983 983
984 return count; 984 return count;
985} 985}
@@ -990,12 +990,12 @@ static ssize_t sn9c102_show_i2c_reg(struct class_device* cd, char* buf)
990 struct sn9c102_device* cam; 990 struct sn9c102_device* cam;
991 ssize_t count; 991 ssize_t count;
992 992
993 if (down_interruptible(&sn9c102_sysfs_lock)) 993 if (mutex_lock_interruptible(&sn9c102_sysfs_lock))
994 return -ERESTARTSYS; 994 return -ERESTARTSYS;
995 995
996 cam = video_get_drvdata(to_video_device(cd)); 996 cam = video_get_drvdata(to_video_device(cd));
997 if (!cam) { 997 if (!cam) {
998 up(&sn9c102_sysfs_lock); 998 mutex_unlock(&sn9c102_sysfs_lock);
999 return -ENODEV; 999 return -ENODEV;
1000 } 1000 }
1001 1001
@@ -1003,7 +1003,7 @@ static ssize_t sn9c102_show_i2c_reg(struct class_device* cd, char* buf)
1003 1003
1004 DBG(3, "Read bytes: %zd", count); 1004 DBG(3, "Read bytes: %zd", count);
1005 1005
1006 up(&sn9c102_sysfs_lock); 1006 mutex_unlock(&sn9c102_sysfs_lock);
1007 1007
1008 return count; 1008 return count;
1009} 1009}
@@ -1016,18 +1016,18 @@ sn9c102_store_i2c_reg(struct class_device* cd, const char* buf, size_t len)
1016 u8 index; 1016 u8 index;
1017 ssize_t count; 1017 ssize_t count;
1018 1018
1019 if (down_interruptible(&sn9c102_sysfs_lock)) 1019 if (mutex_lock_interruptible(&sn9c102_sysfs_lock))
1020 return -ERESTARTSYS; 1020 return -ERESTARTSYS;
1021 1021
1022 cam = video_get_drvdata(to_video_device(cd)); 1022 cam = video_get_drvdata(to_video_device(cd));
1023 if (!cam) { 1023 if (!cam) {
1024 up(&sn9c102_sysfs_lock); 1024 mutex_unlock(&sn9c102_sysfs_lock);
1025 return -ENODEV; 1025 return -ENODEV;
1026 } 1026 }
1027 1027
1028 index = sn9c102_strtou8(buf, len, &count); 1028 index = sn9c102_strtou8(buf, len, &count);
1029 if (!count) { 1029 if (!count) {
1030 up(&sn9c102_sysfs_lock); 1030 mutex_unlock(&sn9c102_sysfs_lock);
1031 return -EINVAL; 1031 return -EINVAL;
1032 } 1032 }
1033 1033
@@ -1036,7 +1036,7 @@ sn9c102_store_i2c_reg(struct class_device* cd, const char* buf, size_t len)
1036 DBG(2, "Moved sensor register index to 0x%02X", cam->sysfs.i2c_reg); 1036 DBG(2, "Moved sensor register index to 0x%02X", cam->sysfs.i2c_reg);
1037 DBG(3, "Written bytes: %zd", count); 1037 DBG(3, "Written bytes: %zd", count);
1038 1038
1039 up(&sn9c102_sysfs_lock); 1039 mutex_unlock(&sn9c102_sysfs_lock);
1040 1040
1041 return count; 1041 return count;
1042} 1042}
@@ -1048,22 +1048,22 @@ static ssize_t sn9c102_show_i2c_val(struct class_device* cd, char* buf)
1048 ssize_t count; 1048 ssize_t count;
1049 int val; 1049 int val;
1050 1050
1051 if (down_interruptible(&sn9c102_sysfs_lock)) 1051 if (mutex_lock_interruptible(&sn9c102_sysfs_lock))
1052 return -ERESTARTSYS; 1052 return -ERESTARTSYS;
1053 1053
1054 cam = video_get_drvdata(to_video_device(cd)); 1054 cam = video_get_drvdata(to_video_device(cd));
1055 if (!cam) { 1055 if (!cam) {
1056 up(&sn9c102_sysfs_lock); 1056 mutex_unlock(&sn9c102_sysfs_lock);
1057 return -ENODEV; 1057 return -ENODEV;
1058 } 1058 }
1059 1059
1060 if (!(cam->sensor->sysfs_ops & SN9C102_I2C_READ)) { 1060 if (!(cam->sensor->sysfs_ops & SN9C102_I2C_READ)) {
1061 up(&sn9c102_sysfs_lock); 1061 mutex_unlock(&sn9c102_sysfs_lock);
1062 return -ENOSYS; 1062 return -ENOSYS;
1063 } 1063 }
1064 1064
1065 if ((val = sn9c102_i2c_read(cam, cam->sysfs.i2c_reg)) < 0) { 1065 if ((val = sn9c102_i2c_read(cam, cam->sysfs.i2c_reg)) < 0) {
1066 up(&sn9c102_sysfs_lock); 1066 mutex_unlock(&sn9c102_sysfs_lock);
1067 return -EIO; 1067 return -EIO;
1068 } 1068 }
1069 1069
@@ -1071,7 +1071,7 @@ static ssize_t sn9c102_show_i2c_val(struct class_device* cd, char* buf)
1071 1071
1072 DBG(3, "Read bytes: %zd", count); 1072 DBG(3, "Read bytes: %zd", count);
1073 1073
1074 up(&sn9c102_sysfs_lock); 1074 mutex_unlock(&sn9c102_sysfs_lock);
1075 1075
1076 return count; 1076 return count;
1077} 1077}
@@ -1085,29 +1085,29 @@ sn9c102_store_i2c_val(struct class_device* cd, const char* buf, size_t len)
1085 ssize_t count; 1085 ssize_t count;
1086 int err; 1086 int err;
1087 1087
1088 if (down_interruptible(&sn9c102_sysfs_lock)) 1088 if (mutex_lock_interruptible(&sn9c102_sysfs_lock))
1089 return -ERESTARTSYS; 1089 return -ERESTARTSYS;
1090 1090
1091 cam = video_get_drvdata(to_video_device(cd)); 1091 cam = video_get_drvdata(to_video_device(cd));
1092 if (!cam) { 1092 if (!cam) {
1093 up(&sn9c102_sysfs_lock); 1093 mutex_unlock(&sn9c102_sysfs_lock);
1094 return -ENODEV; 1094 return -ENODEV;
1095 } 1095 }
1096 1096
1097 if (!(cam->sensor->sysfs_ops & SN9C102_I2C_WRITE)) { 1097 if (!(cam->sensor->sysfs_ops & SN9C102_I2C_WRITE)) {
1098 up(&sn9c102_sysfs_lock); 1098 mutex_unlock(&sn9c102_sysfs_lock);
1099 return -ENOSYS; 1099 return -ENOSYS;
1100 } 1100 }
1101 1101
1102 value = sn9c102_strtou8(buf, len, &count); 1102 value = sn9c102_strtou8(buf, len, &count);
1103 if (!count) { 1103 if (!count) {
1104 up(&sn9c102_sysfs_lock); 1104 mutex_unlock(&sn9c102_sysfs_lock);
1105 return -EINVAL; 1105 return -EINVAL;
1106 } 1106 }
1107 1107
1108 err = sn9c102_i2c_write(cam, cam->sysfs.i2c_reg, value); 1108 err = sn9c102_i2c_write(cam, cam->sysfs.i2c_reg, value);
1109 if (err) { 1109 if (err) {
1110 up(&sn9c102_sysfs_lock); 1110 mutex_unlock(&sn9c102_sysfs_lock);
1111 return -EIO; 1111 return -EIO;
1112 } 1112 }
1113 1113
@@ -1115,7 +1115,7 @@ sn9c102_store_i2c_val(struct class_device* cd, const char* buf, size_t len)
1115 cam->sysfs.i2c_reg, value); 1115 cam->sysfs.i2c_reg, value);
1116 DBG(3, "Written bytes: %zd", count); 1116 DBG(3, "Written bytes: %zd", count);
1117 1117
1118 up(&sn9c102_sysfs_lock); 1118 mutex_unlock(&sn9c102_sysfs_lock);
1119 1119
1120 return count; 1120 return count;
1121} 1121}
@@ -1130,18 +1130,18 @@ sn9c102_store_green(struct class_device* cd, const char* buf, size_t len)
1130 u8 value; 1130 u8 value;
1131 ssize_t count; 1131 ssize_t count;
1132 1132
1133 if (down_interruptible(&sn9c102_sysfs_lock)) 1133 if (mutex_lock_interruptible(&sn9c102_sysfs_lock))
1134 return -ERESTARTSYS; 1134 return -ERESTARTSYS;
1135 1135
1136 cam = video_get_drvdata(to_video_device(cd)); 1136 cam = video_get_drvdata(to_video_device(cd));
1137 if (!cam) { 1137 if (!cam) {
1138 up(&sn9c102_sysfs_lock); 1138 mutex_unlock(&sn9c102_sysfs_lock);
1139 return -ENODEV; 1139 return -ENODEV;
1140 } 1140 }
1141 1141
1142 bridge = cam->bridge; 1142 bridge = cam->bridge;
1143 1143
1144 up(&sn9c102_sysfs_lock); 1144 mutex_unlock(&sn9c102_sysfs_lock);
1145 1145
1146 value = sn9c102_strtou8(buf, len, &count); 1146 value = sn9c102_strtou8(buf, len, &count);
1147 if (!count) 1147 if (!count)
@@ -1404,7 +1404,7 @@ static int sn9c102_init(struct sn9c102_device* cam)
1404 } 1404 }
1405 1405
1406 if (!(cam->state & DEV_INITIALIZED)) { 1406 if (!(cam->state & DEV_INITIALIZED)) {
1407 init_MUTEX(&cam->fileop_sem); 1407 mutex_init(&cam->fileop_mutex);
1408 spin_lock_init(&cam->queue_lock); 1408 spin_lock_init(&cam->queue_lock);
1409 init_waitqueue_head(&cam->wait_frame); 1409 init_waitqueue_head(&cam->wait_frame);
1410 init_waitqueue_head(&cam->wait_stream); 1410 init_waitqueue_head(&cam->wait_stream);
@@ -1422,13 +1422,13 @@ static int sn9c102_init(struct sn9c102_device* cam)
1422 1422
1423static void sn9c102_release_resources(struct sn9c102_device* cam) 1423static void sn9c102_release_resources(struct sn9c102_device* cam)
1424{ 1424{
1425 down(&sn9c102_sysfs_lock); 1425 mutex_lock(&sn9c102_sysfs_lock);
1426 1426
1427 DBG(2, "V4L2 device /dev/video%d deregistered", cam->v4ldev->minor); 1427 DBG(2, "V4L2 device /dev/video%d deregistered", cam->v4ldev->minor);
1428 video_set_drvdata(cam->v4ldev, NULL); 1428 video_set_drvdata(cam->v4ldev, NULL);
1429 video_unregister_device(cam->v4ldev); 1429 video_unregister_device(cam->v4ldev);
1430 1430
1431 up(&sn9c102_sysfs_lock); 1431 mutex_unlock(&sn9c102_sysfs_lock);
1432 1432
1433 kfree(cam->control_buffer); 1433 kfree(cam->control_buffer);
1434} 1434}
@@ -1449,7 +1449,7 @@ static int sn9c102_open(struct inode* inode, struct file* filp)
1449 1449
1450 cam = video_get_drvdata(video_devdata(filp)); 1450 cam = video_get_drvdata(video_devdata(filp));
1451 1451
1452 if (down_interruptible(&cam->dev_sem)) { 1452 if (mutex_lock_interruptible(&cam->dev_mutex)) {
1453 up_read(&sn9c102_disconnect); 1453 up_read(&sn9c102_disconnect);
1454 return -ERESTARTSYS; 1454 return -ERESTARTSYS;
1455 } 1455 }
@@ -1461,7 +1461,7 @@ static int sn9c102_open(struct inode* inode, struct file* filp)
1461 err = -EWOULDBLOCK; 1461 err = -EWOULDBLOCK;
1462 goto out; 1462 goto out;
1463 } 1463 }
1464 up(&cam->dev_sem); 1464 mutex_unlock(&cam->dev_mutex);
1465 err = wait_event_interruptible_exclusive(cam->open, 1465 err = wait_event_interruptible_exclusive(cam->open,
1466 cam->state & DEV_DISCONNECTED 1466 cam->state & DEV_DISCONNECTED
1467 || !cam->users); 1467 || !cam->users);
@@ -1473,7 +1473,7 @@ static int sn9c102_open(struct inode* inode, struct file* filp)
1473 up_read(&sn9c102_disconnect); 1473 up_read(&sn9c102_disconnect);
1474 return -ENODEV; 1474 return -ENODEV;
1475 } 1475 }
1476 down(&cam->dev_sem); 1476 mutex_lock(&cam->dev_mutex);
1477 } 1477 }
1478 1478
1479 1479
@@ -1501,7 +1501,7 @@ static int sn9c102_open(struct inode* inode, struct file* filp)
1501 DBG(3, "Video device /dev/video%d is open", cam->v4ldev->minor); 1501 DBG(3, "Video device /dev/video%d is open", cam->v4ldev->minor);
1502 1502
1503out: 1503out:
1504 up(&cam->dev_sem); 1504 mutex_unlock(&cam->dev_mutex);
1505 up_read(&sn9c102_disconnect); 1505 up_read(&sn9c102_disconnect);
1506 return err; 1506 return err;
1507} 1507}
@@ -1511,7 +1511,7 @@ static int sn9c102_release(struct inode* inode, struct file* filp)
1511{ 1511{
1512 struct sn9c102_device* cam = video_get_drvdata(video_devdata(filp)); 1512 struct sn9c102_device* cam = video_get_drvdata(video_devdata(filp));
1513 1513
1514 down(&cam->dev_sem); /* prevent disconnect() to be called */ 1514 mutex_lock(&cam->dev_mutex); /* prevent disconnect() to be called */
1515 1515
1516 sn9c102_stop_transfer(cam); 1516 sn9c102_stop_transfer(cam);
1517 1517
@@ -1519,7 +1519,7 @@ static int sn9c102_release(struct inode* inode, struct file* filp)
1519 1519
1520 if (cam->state & DEV_DISCONNECTED) { 1520 if (cam->state & DEV_DISCONNECTED) {
1521 sn9c102_release_resources(cam); 1521 sn9c102_release_resources(cam);
1522 up(&cam->dev_sem); 1522 mutex_unlock(&cam->dev_mutex);
1523 kfree(cam); 1523 kfree(cam);
1524 return 0; 1524 return 0;
1525 } 1525 }
@@ -1529,7 +1529,7 @@ static int sn9c102_release(struct inode* inode, struct file* filp)
1529 1529
1530 DBG(3, "Video device /dev/video%d closed", cam->v4ldev->minor); 1530 DBG(3, "Video device /dev/video%d closed", cam->v4ldev->minor);
1531 1531
1532 up(&cam->dev_sem); 1532 mutex_unlock(&cam->dev_mutex);
1533 1533
1534 return 0; 1534 return 0;
1535} 1535}
@@ -1543,33 +1543,33 @@ sn9c102_read(struct file* filp, char __user * buf, size_t count, loff_t* f_pos)
1543 unsigned long lock_flags; 1543 unsigned long lock_flags;
1544 int err = 0; 1544 int err = 0;
1545 1545
1546 if (down_interruptible(&cam->fileop_sem)) 1546 if (mutex_lock_interruptible(&cam->fileop_mutex))
1547 return -ERESTARTSYS; 1547 return -ERESTARTSYS;
1548 1548
1549 if (cam->state & DEV_DISCONNECTED) { 1549 if (cam->state & DEV_DISCONNECTED) {
1550 DBG(1, "Device not present"); 1550 DBG(1, "Device not present");
1551 up(&cam->fileop_sem); 1551 mutex_unlock(&cam->fileop_mutex);
1552 return -ENODEV; 1552 return -ENODEV;
1553 } 1553 }
1554 1554
1555 if (cam->state & DEV_MISCONFIGURED) { 1555 if (cam->state & DEV_MISCONFIGURED) {
1556 DBG(1, "The camera is misconfigured. Close and open it " 1556 DBG(1, "The camera is misconfigured. Close and open it "
1557 "again."); 1557 "again.");
1558 up(&cam->fileop_sem); 1558 mutex_unlock(&cam->fileop_mutex);
1559 return -EIO; 1559 return -EIO;
1560 } 1560 }
1561 1561
1562 if (cam->io == IO_MMAP) { 1562 if (cam->io == IO_MMAP) {
1563 DBG(3, "Close and open the device again to choose " 1563 DBG(3, "Close and open the device again to choose "
1564 "the read method"); 1564 "the read method");
1565 up(&cam->fileop_sem); 1565 mutex_unlock(&cam->fileop_mutex);
1566 return -EINVAL; 1566 return -EINVAL;
1567 } 1567 }
1568 1568
1569 if (cam->io == IO_NONE) { 1569 if (cam->io == IO_NONE) {
1570 if (!sn9c102_request_buffers(cam,cam->nreadbuffers, IO_READ)) { 1570 if (!sn9c102_request_buffers(cam,cam->nreadbuffers, IO_READ)) {
1571 DBG(1, "read() failed, not enough memory"); 1571 DBG(1, "read() failed, not enough memory");
1572 up(&cam->fileop_sem); 1572 mutex_unlock(&cam->fileop_mutex);
1573 return -ENOMEM; 1573 return -ENOMEM;
1574 } 1574 }
1575 cam->io = IO_READ; 1575 cam->io = IO_READ;
@@ -1583,13 +1583,13 @@ sn9c102_read(struct file* filp, char __user * buf, size_t count, loff_t* f_pos)
1583 } 1583 }
1584 1584
1585 if (!count) { 1585 if (!count) {
1586 up(&cam->fileop_sem); 1586 mutex_unlock(&cam->fileop_mutex);
1587 return 0; 1587 return 0;
1588 } 1588 }
1589 1589
1590 if (list_empty(&cam->outqueue)) { 1590 if (list_empty(&cam->outqueue)) {
1591 if (filp->f_flags & O_NONBLOCK) { 1591 if (filp->f_flags & O_NONBLOCK) {
1592 up(&cam->fileop_sem); 1592 mutex_unlock(&cam->fileop_mutex);
1593 return -EAGAIN; 1593 return -EAGAIN;
1594 } 1594 }
1595 err = wait_event_interruptible 1595 err = wait_event_interruptible
@@ -1598,15 +1598,15 @@ sn9c102_read(struct file* filp, char __user * buf, size_t count, loff_t* f_pos)
1598 (cam->state & DEV_DISCONNECTED) || 1598 (cam->state & DEV_DISCONNECTED) ||
1599 (cam->state & DEV_MISCONFIGURED) ); 1599 (cam->state & DEV_MISCONFIGURED) );
1600 if (err) { 1600 if (err) {
1601 up(&cam->fileop_sem); 1601 mutex_unlock(&cam->fileop_mutex);
1602 return err; 1602 return err;
1603 } 1603 }
1604 if (cam->state & DEV_DISCONNECTED) { 1604 if (cam->state & DEV_DISCONNECTED) {
1605 up(&cam->fileop_sem); 1605 mutex_unlock(&cam->fileop_mutex);
1606 return -ENODEV; 1606 return -ENODEV;
1607 } 1607 }
1608 if (cam->state & DEV_MISCONFIGURED) { 1608 if (cam->state & DEV_MISCONFIGURED) {
1609 up(&cam->fileop_sem); 1609 mutex_unlock(&cam->fileop_mutex);
1610 return -EIO; 1610 return -EIO;
1611 } 1611 }
1612 } 1612 }
@@ -1634,7 +1634,7 @@ exit:
1634 PDBGG("Frame #%lu, bytes read: %zu", 1634 PDBGG("Frame #%lu, bytes read: %zu",
1635 (unsigned long)f->buf.index, count); 1635 (unsigned long)f->buf.index, count);
1636 1636
1637 up(&cam->fileop_sem); 1637 mutex_unlock(&cam->fileop_mutex);
1638 1638
1639 return count; 1639 return count;
1640} 1640}
@@ -1647,7 +1647,7 @@ static unsigned int sn9c102_poll(struct file *filp, poll_table *wait)
1647 unsigned long lock_flags; 1647 unsigned long lock_flags;
1648 unsigned int mask = 0; 1648 unsigned int mask = 0;
1649 1649
1650 if (down_interruptible(&cam->fileop_sem)) 1650 if (mutex_lock_interruptible(&cam->fileop_mutex))
1651 return POLLERR; 1651 return POLLERR;
1652 1652
1653 if (cam->state & DEV_DISCONNECTED) { 1653 if (cam->state & DEV_DISCONNECTED) {
@@ -1685,12 +1685,12 @@ static unsigned int sn9c102_poll(struct file *filp, poll_table *wait)
1685 if (!list_empty(&cam->outqueue)) 1685 if (!list_empty(&cam->outqueue))
1686 mask |= POLLIN | POLLRDNORM; 1686 mask |= POLLIN | POLLRDNORM;
1687 1687
1688 up(&cam->fileop_sem); 1688 mutex_unlock(&cam->fileop_mutex);
1689 1689
1690 return mask; 1690 return mask;
1691 1691
1692error: 1692error:
1693 up(&cam->fileop_sem); 1693 mutex_unlock(&cam->fileop_mutex);
1694 return POLLERR; 1694 return POLLERR;
1695} 1695}
1696 1696
@@ -1724,25 +1724,25 @@ static int sn9c102_mmap(struct file* filp, struct vm_area_struct *vma)
1724 void *pos; 1724 void *pos;
1725 u32 i; 1725 u32 i;
1726 1726
1727 if (down_interruptible(&cam->fileop_sem)) 1727 if (mutex_lock_interruptible(&cam->fileop_mutex))
1728 return -ERESTARTSYS; 1728 return -ERESTARTSYS;
1729 1729
1730 if (cam->state & DEV_DISCONNECTED) { 1730 if (cam->state & DEV_DISCONNECTED) {
1731 DBG(1, "Device not present"); 1731 DBG(1, "Device not present");
1732 up(&cam->fileop_sem); 1732 mutex_unlock(&cam->fileop_mutex);
1733 return -ENODEV; 1733 return -ENODEV;
1734 } 1734 }
1735 1735
1736 if (cam->state & DEV_MISCONFIGURED) { 1736 if (cam->state & DEV_MISCONFIGURED) {
1737 DBG(1, "The camera is misconfigured. Close and open it " 1737 DBG(1, "The camera is misconfigured. Close and open it "
1738 "again."); 1738 "again.");
1739 up(&cam->fileop_sem); 1739 mutex_unlock(&cam->fileop_mutex);
1740 return -EIO; 1740 return -EIO;
1741 } 1741 }
1742 1742
1743 if (cam->io != IO_MMAP || !(vma->vm_flags & VM_WRITE) || 1743 if (cam->io != IO_MMAP || !(vma->vm_flags & VM_WRITE) ||
1744 size != PAGE_ALIGN(cam->frame[0].buf.length)) { 1744 size != PAGE_ALIGN(cam->frame[0].buf.length)) {
1745 up(&cam->fileop_sem); 1745 mutex_unlock(&cam->fileop_mutex);
1746 return -EINVAL; 1746 return -EINVAL;
1747 } 1747 }
1748 1748
@@ -1751,7 +1751,7 @@ static int sn9c102_mmap(struct file* filp, struct vm_area_struct *vma)
1751 break; 1751 break;
1752 } 1752 }
1753 if (i == cam->nbuffers) { 1753 if (i == cam->nbuffers) {
1754 up(&cam->fileop_sem); 1754 mutex_unlock(&cam->fileop_mutex);
1755 return -EINVAL; 1755 return -EINVAL;
1756 } 1756 }
1757 1757
@@ -1761,7 +1761,7 @@ static int sn9c102_mmap(struct file* filp, struct vm_area_struct *vma)
1761 pos = cam->frame[i].bufmem; 1761 pos = cam->frame[i].bufmem;
1762 while (size > 0) { /* size is page-aligned */ 1762 while (size > 0) { /* size is page-aligned */
1763 if (vm_insert_page(vma, start, vmalloc_to_page(pos))) { 1763 if (vm_insert_page(vma, start, vmalloc_to_page(pos))) {
1764 up(&cam->fileop_sem); 1764 mutex_unlock(&cam->fileop_mutex);
1765 return -EAGAIN; 1765 return -EAGAIN;
1766 } 1766 }
1767 start += PAGE_SIZE; 1767 start += PAGE_SIZE;
@@ -1774,7 +1774,7 @@ static int sn9c102_mmap(struct file* filp, struct vm_area_struct *vma)
1774 1774
1775 sn9c102_vm_open(vma); 1775 sn9c102_vm_open(vma);
1776 1776
1777 up(&cam->fileop_sem); 1777 mutex_unlock(&cam->fileop_mutex);
1778 1778
1779 return 0; 1779 return 0;
1780} 1780}
@@ -2655,19 +2655,19 @@ static int sn9c102_ioctl(struct inode* inode, struct file* filp,
2655 struct sn9c102_device* cam = video_get_drvdata(video_devdata(filp)); 2655 struct sn9c102_device* cam = video_get_drvdata(video_devdata(filp));
2656 int err = 0; 2656 int err = 0;
2657 2657
2658 if (down_interruptible(&cam->fileop_sem)) 2658 if (mutex_lock_interruptible(&cam->fileop_mutex))
2659 return -ERESTARTSYS; 2659 return -ERESTARTSYS;
2660 2660
2661 if (cam->state & DEV_DISCONNECTED) { 2661 if (cam->state & DEV_DISCONNECTED) {
2662 DBG(1, "Device not present"); 2662 DBG(1, "Device not present");
2663 up(&cam->fileop_sem); 2663 mutex_unlock(&cam->fileop_mutex);
2664 return -ENODEV; 2664 return -ENODEV;
2665 } 2665 }
2666 2666
2667 if (cam->state & DEV_MISCONFIGURED) { 2667 if (cam->state & DEV_MISCONFIGURED) {
2668 DBG(1, "The camera is misconfigured. Close and open it " 2668 DBG(1, "The camera is misconfigured. Close and open it "
2669 "again."); 2669 "again.");
2670 up(&cam->fileop_sem); 2670 mutex_unlock(&cam->fileop_mutex);
2671 return -EIO; 2671 return -EIO;
2672 } 2672 }
2673 2673
@@ -2675,7 +2675,7 @@ static int sn9c102_ioctl(struct inode* inode, struct file* filp,
2675 2675
2676 err = sn9c102_ioctl_v4l2(inode, filp, cmd, (void __user *)arg); 2676 err = sn9c102_ioctl_v4l2(inode, filp, cmd, (void __user *)arg);
2677 2677
2678 up(&cam->fileop_sem); 2678 mutex_unlock(&cam->fileop_mutex);
2679 2679
2680 return err; 2680 return err;
2681} 2681}
@@ -2722,7 +2722,7 @@ sn9c102_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
2722 goto fail; 2722 goto fail;
2723 } 2723 }
2724 2724
2725 init_MUTEX(&cam->dev_sem); 2725 mutex_init(&cam->dev_mutex);
2726 2726
2727 r = sn9c102_read_reg(cam, 0x00); 2727 r = sn9c102_read_reg(cam, 0x00);
2728 if (r < 0 || r != 0x10) { 2728 if (r < 0 || r != 0x10) {
@@ -2776,7 +2776,7 @@ sn9c102_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
2776 cam->v4ldev->release = video_device_release; 2776 cam->v4ldev->release = video_device_release;
2777 video_set_drvdata(cam->v4ldev, cam); 2777 video_set_drvdata(cam->v4ldev, cam);
2778 2778
2779 down(&cam->dev_sem); 2779 mutex_lock(&cam->dev_mutex);
2780 2780
2781 err = video_register_device(cam->v4ldev, VFL_TYPE_GRABBER, 2781 err = video_register_device(cam->v4ldev, VFL_TYPE_GRABBER,
2782 video_nr[dev_nr]); 2782 video_nr[dev_nr]);
@@ -2786,7 +2786,7 @@ sn9c102_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
2786 DBG(1, "Free /dev/videoX node not found"); 2786 DBG(1, "Free /dev/videoX node not found");
2787 video_nr[dev_nr] = -1; 2787 video_nr[dev_nr] = -1;
2788 dev_nr = (dev_nr < SN9C102_MAX_DEVICES-1) ? dev_nr+1 : 0; 2788 dev_nr = (dev_nr < SN9C102_MAX_DEVICES-1) ? dev_nr+1 : 0;
2789 up(&cam->dev_sem); 2789 mutex_unlock(&cam->dev_mutex);
2790 goto fail; 2790 goto fail;
2791 } 2791 }
2792 2792
@@ -2803,7 +2803,7 @@ sn9c102_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
2803 2803
2804 usb_set_intfdata(intf, cam); 2804 usb_set_intfdata(intf, cam);
2805 2805
2806 up(&cam->dev_sem); 2806 mutex_unlock(&cam->dev_mutex);
2807 2807
2808 return 0; 2808 return 0;
2809 2809
@@ -2827,7 +2827,7 @@ static void sn9c102_usb_disconnect(struct usb_interface* intf)
2827 2827
2828 down_write(&sn9c102_disconnect); 2828 down_write(&sn9c102_disconnect);
2829 2829
2830 down(&cam->dev_sem); 2830 mutex_lock(&cam->dev_mutex);
2831 2831
2832 DBG(2, "Disconnecting %s...", cam->v4ldev->name); 2832 DBG(2, "Disconnecting %s...", cam->v4ldev->name);
2833 2833
@@ -2847,7 +2847,7 @@ static void sn9c102_usb_disconnect(struct usb_interface* intf)
2847 sn9c102_release_resources(cam); 2847 sn9c102_release_resources(cam);
2848 } 2848 }
2849 2849
2850 up(&cam->dev_sem); 2850 mutex_unlock(&cam->dev_mutex);
2851 2851
2852 if (!cam->users) 2852 if (!cam->users)
2853 kfree(cam); 2853 kfree(cam);
diff --git a/drivers/usb/media/stv680.c b/drivers/usb/media/stv680.c
index b497a6a0a206..b1a6be2958ed 100644
--- a/drivers/usb/media/stv680.c
+++ b/drivers/usb/media/stv680.c
@@ -67,6 +67,7 @@
67#include <linux/errno.h> 67#include <linux/errno.h>
68#include <linux/videodev.h> 68#include <linux/videodev.h>
69#include <linux/usb.h> 69#include <linux/usb.h>
70#include <linux/mutex.h>
70 71
71#include "stv680.h" 72#include "stv680.h"
72 73
@@ -1258,22 +1259,22 @@ static int stv680_mmap (struct file *file, struct vm_area_struct *vma)
1258 unsigned long size = vma->vm_end-vma->vm_start; 1259 unsigned long size = vma->vm_end-vma->vm_start;
1259 unsigned long page, pos; 1260 unsigned long page, pos;
1260 1261
1261 down (&stv680->lock); 1262 mutex_lock(&stv680->lock);
1262 1263
1263 if (stv680->udev == NULL) { 1264 if (stv680->udev == NULL) {
1264 up (&stv680->lock); 1265 mutex_unlock(&stv680->lock);
1265 return -EIO; 1266 return -EIO;
1266 } 1267 }
1267 if (size > (((STV680_NUMFRAMES * stv680->maxframesize) + PAGE_SIZE - 1) 1268 if (size > (((STV680_NUMFRAMES * stv680->maxframesize) + PAGE_SIZE - 1)
1268 & ~(PAGE_SIZE - 1))) { 1269 & ~(PAGE_SIZE - 1))) {
1269 up (&stv680->lock); 1270 mutex_unlock(&stv680->lock);
1270 return -EINVAL; 1271 return -EINVAL;
1271 } 1272 }
1272 pos = (unsigned long) stv680->fbuf; 1273 pos = (unsigned long) stv680->fbuf;
1273 while (size > 0) { 1274 while (size > 0) {
1274 page = vmalloc_to_pfn((void *)pos); 1275 page = vmalloc_to_pfn((void *)pos);
1275 if (remap_pfn_range(vma, start, page, PAGE_SIZE, PAGE_SHARED)) { 1276 if (remap_pfn_range(vma, start, page, PAGE_SIZE, PAGE_SHARED)) {
1276 up (&stv680->lock); 1277 mutex_unlock(&stv680->lock);
1277 return -EAGAIN; 1278 return -EAGAIN;
1278 } 1279 }
1279 start += PAGE_SIZE; 1280 start += PAGE_SIZE;
@@ -1283,7 +1284,7 @@ static int stv680_mmap (struct file *file, struct vm_area_struct *vma)
1283 else 1284 else
1284 size = 0; 1285 size = 0;
1285 } 1286 }
1286 up (&stv680->lock); 1287 mutex_unlock(&stv680->lock);
1287 1288
1288 return 0; 1289 return 0;
1289} 1290}
@@ -1409,7 +1410,7 @@ static int stv680_probe (struct usb_interface *intf, const struct usb_device_id
1409 1410
1410 memcpy (stv680->vdev->name, stv680->camera_name, strlen (stv680->camera_name)); 1411 memcpy (stv680->vdev->name, stv680->camera_name, strlen (stv680->camera_name));
1411 init_waitqueue_head (&stv680->wq); 1412 init_waitqueue_head (&stv680->wq);
1412 init_MUTEX (&stv680->lock); 1413 mutex_init (&stv680->lock);
1413 wmb (); 1414 wmb ();
1414 1415
1415 if (video_register_device (stv680->vdev, VFL_TYPE_GRABBER, video_nr) == -1) { 1416 if (video_register_device (stv680->vdev, VFL_TYPE_GRABBER, video_nr) == -1) {
diff --git a/drivers/usb/media/stv680.h b/drivers/usb/media/stv680.h
index b0551cdb280b..ea46e0001e6d 100644
--- a/drivers/usb/media/stv680.h
+++ b/drivers/usb/media/stv680.h
@@ -118,7 +118,7 @@ struct usb_stv {
118 int origGain; 118 int origGain;
119 int origMode; /* original camera mode */ 119 int origMode; /* original camera mode */
120 120
121 struct semaphore lock; /* to lock the structure */ 121 struct mutex lock; /* to lock the structure */
122 int user; /* user count for exclusive use */ 122 int user; /* user count for exclusive use */
123 int removed; /* device disconnected */ 123 int removed; /* device disconnected */
124 int streaming; /* Are we streaming video? */ 124 int streaming; /* Are we streaming video? */
diff --git a/drivers/usb/media/usbvideo.c b/drivers/usb/media/usbvideo.c
index 63d279ec722b..0b51fae720a9 100644
--- a/drivers/usb/media/usbvideo.c
+++ b/drivers/usb/media/usbvideo.c
@@ -714,7 +714,7 @@ int usbvideo_register(
714 cams->md_module = md; 714 cams->md_module = md;
715 if (cams->md_module == NULL) 715 if (cams->md_module == NULL)
716 warn("%s: module == NULL!", __FUNCTION__); 716 warn("%s: module == NULL!", __FUNCTION__);
717 init_MUTEX(&cams->lock); /* to 1 == available */ 717 mutex_init(&cams->lock); /* to 1 == available */
718 718
719 for (i = 0; i < num_cams; i++) { 719 for (i = 0; i < num_cams; i++) {
720 struct uvd *up = &cams->cam[i]; 720 struct uvd *up = &cams->cam[i];
@@ -862,7 +862,7 @@ static void usbvideo_Disconnect(struct usb_interface *intf)
862 if (uvd->debug > 0) 862 if (uvd->debug > 0)
863 info("%s(%p.)", __FUNCTION__, intf); 863 info("%s(%p.)", __FUNCTION__, intf);
864 864
865 down(&uvd->lock); 865 mutex_lock(&uvd->lock);
866 uvd->remove_pending = 1; /* Now all ISO data will be ignored */ 866 uvd->remove_pending = 1; /* Now all ISO data will be ignored */
867 867
868 /* At this time we ask to cancel outstanding URBs */ 868 /* At this time we ask to cancel outstanding URBs */
@@ -882,7 +882,7 @@ static void usbvideo_Disconnect(struct usb_interface *intf)
882 info("%s: In use, disconnect pending.", __FUNCTION__); 882 info("%s: In use, disconnect pending.", __FUNCTION__);
883 else 883 else
884 usbvideo_CameraRelease(uvd); 884 usbvideo_CameraRelease(uvd);
885 up(&uvd->lock); 885 mutex_unlock(&uvd->lock);
886 info("USB camera disconnected."); 886 info("USB camera disconnected.");
887 887
888 usbvideo_ClientDecModCount(uvd); 888 usbvideo_ClientDecModCount(uvd);
@@ -929,19 +929,19 @@ static int usbvideo_find_struct(struct usbvideo *cams)
929 err("No usbvideo handle?"); 929 err("No usbvideo handle?");
930 return -1; 930 return -1;
931 } 931 }
932 down(&cams->lock); 932 mutex_lock(&cams->lock);
933 for (u = 0; u < cams->num_cameras; u++) { 933 for (u = 0; u < cams->num_cameras; u++) {
934 struct uvd *uvd = &cams->cam[u]; 934 struct uvd *uvd = &cams->cam[u];
935 if (!uvd->uvd_used) /* This one is free */ 935 if (!uvd->uvd_used) /* This one is free */
936 { 936 {
937 uvd->uvd_used = 1; /* In use now */ 937 uvd->uvd_used = 1; /* In use now */
938 init_MUTEX(&uvd->lock); /* to 1 == available */ 938 mutex_init(&uvd->lock); /* to 1 == available */
939 uvd->dev = NULL; 939 uvd->dev = NULL;
940 rv = u; 940 rv = u;
941 break; 941 break;
942 } 942 }
943 } 943 }
944 up(&cams->lock); 944 mutex_unlock(&cams->lock);
945 return rv; 945 return rv;
946} 946}
947 947
@@ -983,7 +983,7 @@ struct uvd *usbvideo_AllocateDevice(struct usbvideo *cams)
983 /* Not relying upon caller we increase module counter ourselves */ 983 /* Not relying upon caller we increase module counter ourselves */
984 usbvideo_ClientIncModCount(uvd); 984 usbvideo_ClientIncModCount(uvd);
985 985
986 down(&uvd->lock); 986 mutex_lock(&uvd->lock);
987 for (i=0; i < USBVIDEO_NUMSBUF; i++) { 987 for (i=0; i < USBVIDEO_NUMSBUF; i++) {
988 uvd->sbuf[i].urb = usb_alloc_urb(FRAMES_PER_DESC, GFP_KERNEL); 988 uvd->sbuf[i].urb = usb_alloc_urb(FRAMES_PER_DESC, GFP_KERNEL);
989 if (uvd->sbuf[i].urb == NULL) { 989 if (uvd->sbuf[i].urb == NULL) {
@@ -1006,7 +1006,7 @@ struct uvd *usbvideo_AllocateDevice(struct usbvideo *cams)
1006 * return control to the client's probe function right now. 1006 * return control to the client's probe function right now.
1007 */ 1007 */
1008allocate_done: 1008allocate_done:
1009 up (&uvd->lock); 1009 mutex_unlock(&uvd->lock);
1010 usbvideo_ClientDecModCount(uvd); 1010 usbvideo_ClientDecModCount(uvd);
1011 return uvd; 1011 return uvd;
1012} 1012}
@@ -1120,7 +1120,7 @@ static int usbvideo_v4l_open(struct inode *inode, struct file *file)
1120 info("%s($%p)", __FUNCTION__, dev); 1120 info("%s($%p)", __FUNCTION__, dev);
1121 1121
1122 usbvideo_ClientIncModCount(uvd); 1122 usbvideo_ClientIncModCount(uvd);
1123 down(&uvd->lock); 1123 mutex_lock(&uvd->lock);
1124 1124
1125 if (uvd->user) { 1125 if (uvd->user) {
1126 err("%s: Someone tried to open an already opened device!", __FUNCTION__); 1126 err("%s: Someone tried to open an already opened device!", __FUNCTION__);
@@ -1201,7 +1201,7 @@ static int usbvideo_v4l_open(struct inode *inode, struct file *file)
1201 } 1201 }
1202 } 1202 }
1203 } 1203 }
1204 up(&uvd->lock); 1204 mutex_unlock(&uvd->lock);
1205 if (errCode != 0) 1205 if (errCode != 0)
1206 usbvideo_ClientDecModCount(uvd); 1206 usbvideo_ClientDecModCount(uvd);
1207 if (uvd->debug > 0) 1207 if (uvd->debug > 0)
@@ -1230,7 +1230,7 @@ static int usbvideo_v4l_close(struct inode *inode, struct file *file)
1230 if (uvd->debug > 1) 1230 if (uvd->debug > 1)
1231 info("%s($%p)", __FUNCTION__, dev); 1231 info("%s($%p)", __FUNCTION__, dev);
1232 1232
1233 down(&uvd->lock); 1233 mutex_lock(&uvd->lock);
1234 GET_CALLBACK(uvd, stopDataPump)(uvd); 1234 GET_CALLBACK(uvd, stopDataPump)(uvd);
1235 usbvideo_rvfree(uvd->fbuf, uvd->fbuf_size); 1235 usbvideo_rvfree(uvd->fbuf, uvd->fbuf_size);
1236 uvd->fbuf = NULL; 1236 uvd->fbuf = NULL;
@@ -1251,7 +1251,7 @@ static int usbvideo_v4l_close(struct inode *inode, struct file *file)
1251 info("usbvideo_v4l_close: Final disconnect."); 1251 info("usbvideo_v4l_close: Final disconnect.");
1252 usbvideo_CameraRelease(uvd); 1252 usbvideo_CameraRelease(uvd);
1253 } 1253 }
1254 up(&uvd->lock); 1254 mutex_unlock(&uvd->lock);
1255 usbvideo_ClientDecModCount(uvd); 1255 usbvideo_ClientDecModCount(uvd);
1256 1256
1257 if (uvd->debug > 1) 1257 if (uvd->debug > 1)
@@ -1511,7 +1511,7 @@ static ssize_t usbvideo_v4l_read(struct file *file, char __user *buf,
1511 if (uvd->debug >= 1) 1511 if (uvd->debug >= 1)
1512 info("%s: %Zd. bytes, noblock=%d.", __FUNCTION__, count, noblock); 1512 info("%s: %Zd. bytes, noblock=%d.", __FUNCTION__, count, noblock);
1513 1513
1514 down(&uvd->lock); 1514 mutex_lock(&uvd->lock);
1515 1515
1516 /* See if a frame is completed, then use it. */ 1516 /* See if a frame is completed, then use it. */
1517 for(i = 0; i < USBVIDEO_NUMFRAMES; i++) { 1517 for(i = 0; i < USBVIDEO_NUMFRAMES; i++) {
@@ -1643,7 +1643,7 @@ static ssize_t usbvideo_v4l_read(struct file *file, char __user *buf,
1643 } 1643 }
1644 } 1644 }
1645read_done: 1645read_done:
1646 up(&uvd->lock); 1646 mutex_unlock(&uvd->lock);
1647 return count; 1647 return count;
1648} 1648}
1649 1649
diff --git a/drivers/usb/media/usbvideo.h b/drivers/usb/media/usbvideo.h
index 6c390a1f981b..135433c2680a 100644
--- a/drivers/usb/media/usbvideo.h
+++ b/drivers/usb/media/usbvideo.h
@@ -19,6 +19,7 @@
19#include <linux/config.h> 19#include <linux/config.h>
20#include <linux/videodev.h> 20#include <linux/videodev.h>
21#include <linux/usb.h> 21#include <linux/usb.h>
22#include <linux/mutex.h>
22 23
23/* Most helpful debugging aid */ 24/* Most helpful debugging aid */
24#define assert(expr) ((void) ((expr) ? 0 : (err("assert failed at line %d",__LINE__)))) 25#define assert(expr) ((void) ((expr) ? 0 : (err("assert failed at line %d",__LINE__))))
@@ -213,7 +214,7 @@ struct uvd {
213 unsigned long flags; /* FLAGS_USBVIDEO_xxx */ 214 unsigned long flags; /* FLAGS_USBVIDEO_xxx */
214 unsigned long paletteBits; /* Which palettes we accept? */ 215 unsigned long paletteBits; /* Which palettes we accept? */
215 unsigned short defaultPalette; /* What palette to use for read() */ 216 unsigned short defaultPalette; /* What palette to use for read() */
216 struct semaphore lock; 217 struct mutex lock;
217 int user; /* user count for exclusive use */ 218 int user; /* user count for exclusive use */
218 219
219 videosize_t videosize; /* Current setting */ 220 videosize_t videosize; /* Current setting */
@@ -272,7 +273,7 @@ struct usbvideo {
272 int num_cameras; /* As allocated */ 273 int num_cameras; /* As allocated */
273 struct usb_driver usbdrv; /* Interface to the USB stack */ 274 struct usb_driver usbdrv; /* Interface to the USB stack */
274 char drvName[80]; /* Driver name */ 275 char drvName[80]; /* Driver name */
275 struct semaphore lock; /* Mutex protecting camera structures */ 276 struct mutex lock; /* Mutex protecting camera structures */
276 struct usbvideo_cb cb; /* Table of callbacks (virtual methods) */ 277 struct usbvideo_cb cb; /* Table of callbacks (virtual methods) */
277 struct video_device vdt; /* Video device template */ 278 struct video_device vdt; /* Video device template */
278 struct uvd *cam; /* Array of camera structures */ 279 struct uvd *cam; /* Array of camera structures */
diff --git a/drivers/usb/media/vicam.c b/drivers/usb/media/vicam.c
index 5df144073871..8cfc47b831fb 100644
--- a/drivers/usb/media/vicam.c
+++ b/drivers/usb/media/vicam.c
@@ -42,6 +42,7 @@
42#include <linux/vmalloc.h> 42#include <linux/vmalloc.h>
43#include <linux/slab.h> 43#include <linux/slab.h>
44#include <linux/proc_fs.h> 44#include <linux/proc_fs.h>
45#include <linux/mutex.h>
45#include "usbvideo.h" 46#include "usbvideo.h"
46 47
47// #define VICAM_DEBUG 48// #define VICAM_DEBUG
@@ -407,7 +408,7 @@ struct vicam_camera {
407 struct usb_device *udev; // usb device 408 struct usb_device *udev; // usb device
408 409
409 /* guard against simultaneous accesses to the camera */ 410 /* guard against simultaneous accesses to the camera */
410 struct semaphore cam_lock; 411 struct mutex cam_lock;
411 412
412 int is_initialized; 413 int is_initialized;
413 u8 open_count; 414 u8 open_count;
@@ -461,12 +462,12 @@ static int send_control_msg(struct vicam_camera *cam,
461 u16 size) 462 u16 size)
462{ 463{
463 int status = -ENODEV; 464 int status = -ENODEV;
464 down(&cam->cam_lock); 465 mutex_lock(&cam->cam_lock);
465 if (cam->udev) { 466 if (cam->udev) {
466 status = __send_control_msg(cam, request, value, 467 status = __send_control_msg(cam, request, value,
467 index, cp, size); 468 index, cp, size);
468 } 469 }
469 up(&cam->cam_lock); 470 mutex_unlock(&cam->cam_lock);
470 return status; 471 return status;
471} 472}
472static int 473static int
@@ -831,13 +832,13 @@ vicam_close(struct inode *inode, struct file *file)
831 rvfree(cam->framebuf, VICAM_MAX_FRAME_SIZE * VICAM_FRAMES); 832 rvfree(cam->framebuf, VICAM_MAX_FRAME_SIZE * VICAM_FRAMES);
832 kfree(cam->cntrlbuf); 833 kfree(cam->cntrlbuf);
833 834
834 down(&cam->cam_lock); 835 mutex_lock(&cam->cam_lock);
835 836
836 cam->open_count--; 837 cam->open_count--;
837 open_count = cam->open_count; 838 open_count = cam->open_count;
838 udev = cam->udev; 839 udev = cam->udev;
839 840
840 up(&cam->cam_lock); 841 mutex_unlock(&cam->cam_lock);
841 842
842 if (!open_count && !udev) { 843 if (!open_count && !udev) {
843 kfree(cam); 844 kfree(cam);
@@ -960,7 +961,7 @@ read_frame(struct vicam_camera *cam, int framenum)
960 request[8] = 0; 961 request[8] = 0;
961 // bytes 9-15 do not seem to affect exposure or image quality 962 // bytes 9-15 do not seem to affect exposure or image quality
962 963
963 down(&cam->cam_lock); 964 mutex_lock(&cam->cam_lock);
964 965
965 if (!cam->udev) { 966 if (!cam->udev) {
966 goto done; 967 goto done;
@@ -985,7 +986,7 @@ read_frame(struct vicam_camera *cam, int framenum)
985 } 986 }
986 987
987 done: 988 done:
988 up(&cam->cam_lock); 989 mutex_unlock(&cam->cam_lock);
989} 990}
990 991
991static ssize_t 992static ssize_t
@@ -1309,7 +1310,7 @@ vicam_probe( struct usb_interface *intf, const struct usb_device_id *id)
1309 1310
1310 cam->shutter_speed = 15; 1311 cam->shutter_speed = 15;
1311 1312
1312 init_MUTEX(&cam->cam_lock); 1313 mutex_init(&cam->cam_lock);
1313 1314
1314 memcpy(&cam->vdev, &vicam_template, 1315 memcpy(&cam->vdev, &vicam_template,
1315 sizeof (vicam_template)); 1316 sizeof (vicam_template));
@@ -1351,7 +1352,7 @@ vicam_disconnect(struct usb_interface *intf)
1351 1352
1352 /* stop the camera from being used */ 1353 /* stop the camera from being used */
1353 1354
1354 down(&cam->cam_lock); 1355 mutex_lock(&cam->cam_lock);
1355 1356
1356 /* mark the camera as gone */ 1357 /* mark the camera as gone */
1357 1358
@@ -1368,7 +1369,7 @@ vicam_disconnect(struct usb_interface *intf)
1368 1369
1369 open_count = cam->open_count; 1370 open_count = cam->open_count;
1370 1371
1371 up(&cam->cam_lock); 1372 mutex_unlock(&cam->cam_lock);
1372 1373
1373 if (!open_count) { 1374 if (!open_count) {
1374 kfree(cam); 1375 kfree(cam);
diff --git a/drivers/usb/media/w9968cf.c b/drivers/usb/media/w9968cf.c
index 78cd1a577d26..b57dec3782e0 100644
--- a/drivers/usb/media/w9968cf.c
+++ b/drivers/usb/media/w9968cf.c
@@ -47,6 +47,13 @@
47#include "w9968cf.h" 47#include "w9968cf.h"
48#include "w9968cf_decoder.h" 48#include "w9968cf_decoder.h"
49 49
50static struct w9968cf_vpp_t* w9968cf_vpp;
51static DECLARE_WAIT_QUEUE_HEAD(w9968cf_vppmod_wait);
52
53static LIST_HEAD(w9968cf_dev_list); /* head of V4L registered cameras list */
54static DEFINE_MUTEX(w9968cf_devlist_mutex); /* semaphore for list traversal */
55
56static DECLARE_RWSEM(w9968cf_disconnect); /* prevent races with open() */
50 57
51 58
52/**************************************************************************** 59/****************************************************************************
@@ -2418,7 +2425,7 @@ w9968cf_configure_camera(struct w9968cf_device* cam,
2418 enum w9968cf_model_id mod_id, 2425 enum w9968cf_model_id mod_id,
2419 const unsigned short dev_nr) 2426 const unsigned short dev_nr)
2420{ 2427{
2421 init_MUTEX(&cam->fileop_sem); 2428 mutex_init(&cam->fileop_mutex);
2422 init_waitqueue_head(&cam->open); 2429 init_waitqueue_head(&cam->open);
2423 spin_lock_init(&cam->urb_lock); 2430 spin_lock_init(&cam->urb_lock);
2424 spin_lock_init(&cam->flist_lock); 2431 spin_lock_init(&cam->flist_lock);
@@ -2646,7 +2653,7 @@ static void w9968cf_adjust_configuration(struct w9968cf_device* cam)
2646 --------------------------------------------------------------------------*/ 2653 --------------------------------------------------------------------------*/
2647static void w9968cf_release_resources(struct w9968cf_device* cam) 2654static void w9968cf_release_resources(struct w9968cf_device* cam)
2648{ 2655{
2649 down(&w9968cf_devlist_sem); 2656 mutex_lock(&w9968cf_devlist_mutex);
2650 2657
2651 DBG(2, "V4L device deregistered: /dev/video%d", cam->v4ldev->minor) 2658 DBG(2, "V4L device deregistered: /dev/video%d", cam->v4ldev->minor)
2652 2659
@@ -2657,7 +2664,7 @@ static void w9968cf_release_resources(struct w9968cf_device* cam)
2657 kfree(cam->control_buffer); 2664 kfree(cam->control_buffer);
2658 kfree(cam->data_buffer); 2665 kfree(cam->data_buffer);
2659 2666
2660 up(&w9968cf_devlist_sem); 2667 mutex_unlock(&w9968cf_devlist_mutex);
2661} 2668}
2662 2669
2663 2670
@@ -2677,14 +2684,14 @@ static int w9968cf_open(struct inode* inode, struct file* filp)
2677 2684
2678 cam = (struct w9968cf_device*)video_get_drvdata(video_devdata(filp)); 2685 cam = (struct w9968cf_device*)video_get_drvdata(video_devdata(filp));
2679 2686
2680 down(&cam->dev_sem); 2687 mutex_lock(&cam->dev_mutex);
2681 2688
2682 if (cam->sensor == CC_UNKNOWN) { 2689 if (cam->sensor == CC_UNKNOWN) {
2683 DBG(2, "No supported image sensor has been detected by the " 2690 DBG(2, "No supported image sensor has been detected by the "
2684 "'ovcamchip' module for the %s (/dev/video%d). Make " 2691 "'ovcamchip' module for the %s (/dev/video%d). Make "
2685 "sure it is loaded *before* (re)connecting the camera.", 2692 "sure it is loaded *before* (re)connecting the camera.",
2686 symbolic(camlist, cam->id), cam->v4ldev->minor) 2693 symbolic(camlist, cam->id), cam->v4ldev->minor)
2687 up(&cam->dev_sem); 2694 mutex_unlock(&cam->dev_mutex);
2688 up_read(&w9968cf_disconnect); 2695 up_read(&w9968cf_disconnect);
2689 return -ENODEV; 2696 return -ENODEV;
2690 } 2697 }
@@ -2693,11 +2700,11 @@ static int w9968cf_open(struct inode* inode, struct file* filp)
2693 DBG(2, "%s (/dev/video%d) has been already occupied by '%s'", 2700 DBG(2, "%s (/dev/video%d) has been already occupied by '%s'",
2694 symbolic(camlist, cam->id),cam->v4ldev->minor,cam->command) 2701 symbolic(camlist, cam->id),cam->v4ldev->minor,cam->command)
2695 if ((filp->f_flags & O_NONBLOCK)||(filp->f_flags & O_NDELAY)) { 2702 if ((filp->f_flags & O_NONBLOCK)||(filp->f_flags & O_NDELAY)) {
2696 up(&cam->dev_sem); 2703 mutex_unlock(&cam->dev_mutex);
2697 up_read(&w9968cf_disconnect); 2704 up_read(&w9968cf_disconnect);
2698 return -EWOULDBLOCK; 2705 return -EWOULDBLOCK;
2699 } 2706 }
2700 up(&cam->dev_sem); 2707 mutex_unlock(&cam->dev_mutex);
2701 err = wait_event_interruptible_exclusive(cam->open, 2708 err = wait_event_interruptible_exclusive(cam->open,
2702 cam->disconnected || 2709 cam->disconnected ||
2703 !cam->users); 2710 !cam->users);
@@ -2709,7 +2716,7 @@ static int w9968cf_open(struct inode* inode, struct file* filp)
2709 up_read(&w9968cf_disconnect); 2716 up_read(&w9968cf_disconnect);
2710 return -ENODEV; 2717 return -ENODEV;
2711 } 2718 }
2712 down(&cam->dev_sem); 2719 mutex_lock(&cam->dev_mutex);
2713 } 2720 }
2714 2721
2715 DBG(5, "Opening '%s', /dev/video%d ...", 2722 DBG(5, "Opening '%s', /dev/video%d ...",
@@ -2738,7 +2745,7 @@ static int w9968cf_open(struct inode* inode, struct file* filp)
2738 2745
2739 DBG(5, "Video device is open") 2746 DBG(5, "Video device is open")
2740 2747
2741 up(&cam->dev_sem); 2748 mutex_unlock(&cam->dev_mutex);
2742 up_read(&w9968cf_disconnect); 2749 up_read(&w9968cf_disconnect);
2743 2750
2744 return 0; 2751 return 0;
@@ -2746,7 +2753,7 @@ static int w9968cf_open(struct inode* inode, struct file* filp)
2746deallocate_memory: 2753deallocate_memory:
2747 w9968cf_deallocate_memory(cam); 2754 w9968cf_deallocate_memory(cam);
2748 DBG(2, "Failed to open the video device") 2755 DBG(2, "Failed to open the video device")
2749 up(&cam->dev_sem); 2756 mutex_unlock(&cam->dev_mutex);
2750 up_read(&w9968cf_disconnect); 2757 up_read(&w9968cf_disconnect);
2751 return err; 2758 return err;
2752} 2759}
@@ -2758,13 +2765,13 @@ static int w9968cf_release(struct inode* inode, struct file* filp)
2758 2765
2759 cam = (struct w9968cf_device*)video_get_drvdata(video_devdata(filp)); 2766 cam = (struct w9968cf_device*)video_get_drvdata(video_devdata(filp));
2760 2767
2761 down(&cam->dev_sem); /* prevent disconnect() to be called */ 2768 mutex_lock(&cam->dev_mutex); /* prevent disconnect() to be called */
2762 2769
2763 w9968cf_stop_transfer(cam); 2770 w9968cf_stop_transfer(cam);
2764 2771
2765 if (cam->disconnected) { 2772 if (cam->disconnected) {
2766 w9968cf_release_resources(cam); 2773 w9968cf_release_resources(cam);
2767 up(&cam->dev_sem); 2774 mutex_unlock(&cam->dev_mutex);
2768 kfree(cam); 2775 kfree(cam);
2769 return 0; 2776 return 0;
2770 } 2777 }
@@ -2774,7 +2781,7 @@ static int w9968cf_release(struct inode* inode, struct file* filp)
2774 wake_up_interruptible_nr(&cam->open, 1); 2781 wake_up_interruptible_nr(&cam->open, 1);
2775 2782
2776 DBG(5, "Video device closed") 2783 DBG(5, "Video device closed")
2777 up(&cam->dev_sem); 2784 mutex_unlock(&cam->dev_mutex);
2778 return 0; 2785 return 0;
2779} 2786}
2780 2787
@@ -2791,18 +2798,18 @@ w9968cf_read(struct file* filp, char __user * buf, size_t count, loff_t* f_pos)
2791 if (filp->f_flags & O_NONBLOCK) 2798 if (filp->f_flags & O_NONBLOCK)
2792 return -EWOULDBLOCK; 2799 return -EWOULDBLOCK;
2793 2800
2794 if (down_interruptible(&cam->fileop_sem)) 2801 if (mutex_lock_interruptible(&cam->fileop_mutex))
2795 return -ERESTARTSYS; 2802 return -ERESTARTSYS;
2796 2803
2797 if (cam->disconnected) { 2804 if (cam->disconnected) {
2798 DBG(2, "Device not present") 2805 DBG(2, "Device not present")
2799 up(&cam->fileop_sem); 2806 mutex_unlock(&cam->fileop_mutex);
2800 return -ENODEV; 2807 return -ENODEV;
2801 } 2808 }
2802 2809
2803 if (cam->misconfigured) { 2810 if (cam->misconfigured) {
2804 DBG(2, "The camera is misconfigured. Close and open it again.") 2811 DBG(2, "The camera is misconfigured. Close and open it again.")
2805 up(&cam->fileop_sem); 2812 mutex_unlock(&cam->fileop_mutex);
2806 return -EIO; 2813 return -EIO;
2807 } 2814 }
2808 2815
@@ -2817,11 +2824,11 @@ w9968cf_read(struct file* filp, char __user * buf, size_t count, loff_t* f_pos)
2817 cam->frame[1].status == F_READY || 2824 cam->frame[1].status == F_READY ||
2818 cam->disconnected); 2825 cam->disconnected);
2819 if (err) { 2826 if (err) {
2820 up(&cam->fileop_sem); 2827 mutex_unlock(&cam->fileop_mutex);
2821 return err; 2828 return err;
2822 } 2829 }
2823 if (cam->disconnected) { 2830 if (cam->disconnected) {
2824 up(&cam->fileop_sem); 2831 mutex_unlock(&cam->fileop_mutex);
2825 return -ENODEV; 2832 return -ENODEV;
2826 } 2833 }
2827 2834
@@ -2835,7 +2842,7 @@ w9968cf_read(struct file* filp, char __user * buf, size_t count, loff_t* f_pos)
2835 2842
2836 if (copy_to_user(buf, fr->buffer, count)) { 2843 if (copy_to_user(buf, fr->buffer, count)) {
2837 fr->status = F_UNUSED; 2844 fr->status = F_UNUSED;
2838 up(&cam->fileop_sem); 2845 mutex_unlock(&cam->fileop_mutex);
2839 return -EFAULT; 2846 return -EFAULT;
2840 } 2847 }
2841 *f_pos += count; 2848 *f_pos += count;
@@ -2844,7 +2851,7 @@ w9968cf_read(struct file* filp, char __user * buf, size_t count, loff_t* f_pos)
2844 2851
2845 DBG(5, "%zu bytes read", count) 2852 DBG(5, "%zu bytes read", count)
2846 2853
2847 up(&cam->fileop_sem); 2854 mutex_unlock(&cam->fileop_mutex);
2848 return count; 2855 return count;
2849} 2856}
2850 2857
@@ -2898,24 +2905,24 @@ w9968cf_ioctl(struct inode* inode, struct file* filp,
2898 2905
2899 cam = (struct w9968cf_device*)video_get_drvdata(video_devdata(filp)); 2906 cam = (struct w9968cf_device*)video_get_drvdata(video_devdata(filp));
2900 2907
2901 if (down_interruptible(&cam->fileop_sem)) 2908 if (mutex_lock_interruptible(&cam->fileop_mutex))
2902 return -ERESTARTSYS; 2909 return -ERESTARTSYS;
2903 2910
2904 if (cam->disconnected) { 2911 if (cam->disconnected) {
2905 DBG(2, "Device not present") 2912 DBG(2, "Device not present")
2906 up(&cam->fileop_sem); 2913 mutex_unlock(&cam->fileop_mutex);
2907 return -ENODEV; 2914 return -ENODEV;
2908 } 2915 }
2909 2916
2910 if (cam->misconfigured) { 2917 if (cam->misconfigured) {
2911 DBG(2, "The camera is misconfigured. Close and open it again.") 2918 DBG(2, "The camera is misconfigured. Close and open it again.")
2912 up(&cam->fileop_sem); 2919 mutex_unlock(&cam->fileop_mutex);
2913 return -EIO; 2920 return -EIO;
2914 } 2921 }
2915 2922
2916 err = w9968cf_v4l_ioctl(inode, filp, cmd, (void __user *)arg); 2923 err = w9968cf_v4l_ioctl(inode, filp, cmd, (void __user *)arg);
2917 2924
2918 up(&cam->fileop_sem); 2925 mutex_unlock(&cam->fileop_mutex);
2919 return err; 2926 return err;
2920} 2927}
2921 2928
@@ -3502,8 +3509,8 @@ w9968cf_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
3502 if (!cam) 3509 if (!cam)
3503 return -ENOMEM; 3510 return -ENOMEM;
3504 3511
3505 init_MUTEX(&cam->dev_sem); 3512 mutex_init(&cam->dev_mutex);
3506 down(&cam->dev_sem); 3513 mutex_lock(&cam->dev_mutex);
3507 3514
3508 cam->usbdev = udev; 3515 cam->usbdev = udev;
3509 /* NOTE: a local copy is used to avoid possible race conditions */ 3516 /* NOTE: a local copy is used to avoid possible race conditions */
@@ -3515,10 +3522,10 @@ w9968cf_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
3515 simcams = W9968CF_SIMCAMS; 3522 simcams = W9968CF_SIMCAMS;
3516 3523
3517 /* How many cameras are connected ? */ 3524 /* How many cameras are connected ? */
3518 down(&w9968cf_devlist_sem); 3525 mutex_lock(&w9968cf_devlist_mutex);
3519 list_for_each(ptr, &w9968cf_dev_list) 3526 list_for_each(ptr, &w9968cf_dev_list)
3520 sc++; 3527 sc++;
3521 up(&w9968cf_devlist_sem); 3528 mutex_unlock(&w9968cf_devlist_mutex);
3522 3529
3523 if (sc >= simcams) { 3530 if (sc >= simcams) {
3524 DBG(2, "Device rejected: too many connected cameras " 3531 DBG(2, "Device rejected: too many connected cameras "
@@ -3578,9 +3585,9 @@ w9968cf_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
3578 w9968cf_configure_camera(cam, udev, mod_id, dev_nr); 3585 w9968cf_configure_camera(cam, udev, mod_id, dev_nr);
3579 3586
3580 /* Add a new entry into the list of V4L registered devices */ 3587 /* Add a new entry into the list of V4L registered devices */
3581 down(&w9968cf_devlist_sem); 3588 mutex_lock(&w9968cf_devlist_mutex);
3582 list_add(&cam->v4llist, &w9968cf_dev_list); 3589 list_add(&cam->v4llist, &w9968cf_dev_list);
3583 up(&w9968cf_devlist_sem); 3590 mutex_unlock(&w9968cf_devlist_mutex);
3584 dev_nr = (dev_nr < W9968CF_MAX_DEVICES-1) ? dev_nr+1 : 0; 3591 dev_nr = (dev_nr < W9968CF_MAX_DEVICES-1) ? dev_nr+1 : 0;
3585 3592
3586 w9968cf_turn_on_led(cam); 3593 w9968cf_turn_on_led(cam);
@@ -3588,7 +3595,7 @@ w9968cf_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
3588 w9968cf_i2c_init(cam); 3595 w9968cf_i2c_init(cam);
3589 3596
3590 usb_set_intfdata(intf, cam); 3597 usb_set_intfdata(intf, cam);
3591 up(&cam->dev_sem); 3598 mutex_unlock(&cam->dev_mutex);
3592 return 0; 3599 return 0;
3593 3600
3594fail: /* Free unused memory */ 3601fail: /* Free unused memory */
@@ -3596,7 +3603,7 @@ fail: /* Free unused memory */
3596 kfree(cam->data_buffer); 3603 kfree(cam->data_buffer);
3597 if (cam->v4ldev) 3604 if (cam->v4ldev)
3598 video_device_release(cam->v4ldev); 3605 video_device_release(cam->v4ldev);
3599 up(&cam->dev_sem); 3606 mutex_unlock(&cam->dev_mutex);
3600 kfree(cam); 3607 kfree(cam);
3601 return err; 3608 return err;
3602} 3609}
@@ -3611,7 +3618,7 @@ static void w9968cf_usb_disconnect(struct usb_interface* intf)
3611 3618
3612 if (cam) { 3619 if (cam) {
3613 /* Prevent concurrent accesses to data */ 3620 /* Prevent concurrent accesses to data */
3614 down(&cam->dev_sem); 3621 mutex_lock(&cam->dev_mutex);
3615 3622
3616 cam->disconnected = 1; 3623 cam->disconnected = 1;
3617 3624
@@ -3630,7 +3637,7 @@ static void w9968cf_usb_disconnect(struct usb_interface* intf)
3630 } else 3637 } else
3631 w9968cf_release_resources(cam); 3638 w9968cf_release_resources(cam);
3632 3639
3633 up(&cam->dev_sem); 3640 mutex_unlock(&cam->dev_mutex);
3634 3641
3635 if (!cam->users) 3642 if (!cam->users)
3636 kfree(cam); 3643 kfree(cam);
diff --git a/drivers/usb/media/w9968cf.h b/drivers/usb/media/w9968cf.h
index 47a6ff794171..a87be719a281 100644
--- a/drivers/usb/media/w9968cf.h
+++ b/drivers/usb/media/w9968cf.h
@@ -32,7 +32,7 @@
32#include <linux/param.h> 32#include <linux/param.h>
33#include <linux/types.h> 33#include <linux/types.h>
34#include <linux/rwsem.h> 34#include <linux/rwsem.h>
35#include <asm/semaphore.h> 35#include <linux/mutex.h>
36 36
37#include <media/ovcamchip.h> 37#include <media/ovcamchip.h>
38 38
@@ -194,14 +194,6 @@ enum w9968cf_vpp_flag {
194 VPP_UYVY_TO_RGBX = 0x08, 194 VPP_UYVY_TO_RGBX = 0x08,
195}; 195};
196 196
197static struct w9968cf_vpp_t* w9968cf_vpp;
198static DECLARE_WAIT_QUEUE_HEAD(w9968cf_vppmod_wait);
199
200static LIST_HEAD(w9968cf_dev_list); /* head of V4L registered cameras list */
201static DECLARE_MUTEX(w9968cf_devlist_sem); /* semaphore for list traversal */
202
203static DECLARE_RWSEM(w9968cf_disconnect); /* prevent races with open() */
204
205/* Main device driver structure */ 197/* Main device driver structure */
206struct w9968cf_device { 198struct w9968cf_device {
207 struct device dev; /* device structure */ 199 struct device dev; /* device structure */
@@ -277,8 +269,8 @@ struct w9968cf_device {
277 struct i2c_client* sensor_client; 269 struct i2c_client* sensor_client;
278 270
279 /* Locks */ 271 /* Locks */
280 struct semaphore dev_sem, /* for probe, disconnect,open and close */ 272 struct mutex dev_mutex, /* for probe, disconnect,open and close */
281 fileop_sem; /* for read and ioctl */ 273 fileop_mutex; /* for read and ioctl */
282 spinlock_t urb_lock, /* for submit_urb() and unlink_urb() */ 274 spinlock_t urb_lock, /* for submit_urb() and unlink_urb() */
283 flist_lock; /* for requested frame list accesses */ 275 flist_lock; /* for requested frame list accesses */
284 wait_queue_head_t open, wait_queue; 276 wait_queue_head_t open, wait_queue;