aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/usb/class/cdc-acm.c23
-rw-r--r--drivers/usb/class/usblp.c15
-rw-r--r--drivers/usb/core/devices.c7
-rw-r--r--drivers/usb/core/hcd.c25
-rw-r--r--drivers/usb/core/hcd.h2
-rw-r--r--drivers/usb/core/hub.c7
-rw-r--r--drivers/usb/core/notify.c15
-rw-r--r--drivers/usb/core/usb.c5
-rw-r--r--drivers/usb/image/mdc800.c63
-rw-r--r--drivers/usb/input/ati_remote.c2
-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
-rw-r--r--drivers/usb/misc/idmouse.c25
-rw-r--r--drivers/usb/misc/ldusb.c11
-rw-r--r--drivers/usb/misc/legousbtower.c11
-rw-r--r--drivers/usb/mon/mon_main.c19
-rw-r--r--drivers/usb/mon/mon_text.c21
-rw-r--r--drivers/usb/mon/usb_mon.h2
-rw-r--r--drivers/usb/storage/scsiglue.c9
-rw-r--r--drivers/usb/storage/usb.c25
-rw-r--r--drivers/usb/storage/usb.h5
34 files changed, 389 insertions, 372 deletions
diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
index 97bdeb1c2181..6dd339f4c0fc 100644
--- a/drivers/usb/class/cdc-acm.c
+++ b/drivers/usb/class/cdc-acm.c
@@ -60,6 +60,7 @@
60#include <linux/tty_flip.h> 60#include <linux/tty_flip.h>
61#include <linux/module.h> 61#include <linux/module.h>
62#include <linux/smp_lock.h> 62#include <linux/smp_lock.h>
63#include <linux/mutex.h>
63#include <asm/uaccess.h> 64#include <asm/uaccess.h>
64#include <linux/usb.h> 65#include <linux/usb.h>
65#include <linux/usb_cdc.h> 66#include <linux/usb_cdc.h>
@@ -80,7 +81,7 @@ static struct usb_driver acm_driver;
80static struct tty_driver *acm_tty_driver; 81static struct tty_driver *acm_tty_driver;
81static struct acm *acm_table[ACM_TTY_MINORS]; 82static struct acm *acm_table[ACM_TTY_MINORS];
82 83
83static DECLARE_MUTEX(open_sem); 84static DEFINE_MUTEX(open_mutex);
84 85
85#define ACM_READY(acm) (acm && acm->dev && acm->used) 86#define ACM_READY(acm) (acm && acm->dev && acm->used)
86 87
@@ -431,8 +432,8 @@ static int acm_tty_open(struct tty_struct *tty, struct file *filp)
431 int rv = -EINVAL; 432 int rv = -EINVAL;
432 int i; 433 int i;
433 dbg("Entering acm_tty_open.\n"); 434 dbg("Entering acm_tty_open.\n");
434 435
435 down(&open_sem); 436 mutex_lock(&open_mutex);
436 437
437 acm = acm_table[tty->index]; 438 acm = acm_table[tty->index];
438 if (!acm || !acm->dev) 439 if (!acm || !acm->dev)
@@ -474,14 +475,14 @@ static int acm_tty_open(struct tty_struct *tty, struct file *filp)
474 475
475done: 476done:
476err_out: 477err_out:
477 up(&open_sem); 478 mutex_unlock(&open_mutex);
478 return rv; 479 return rv;
479 480
480full_bailout: 481full_bailout:
481 usb_kill_urb(acm->ctrlurb); 482 usb_kill_urb(acm->ctrlurb);
482bail_out: 483bail_out:
483 acm->used--; 484 acm->used--;
484 up(&open_sem); 485 mutex_unlock(&open_mutex);
485 return -EIO; 486 return -EIO;
486} 487}
487 488
@@ -507,7 +508,7 @@ static void acm_tty_close(struct tty_struct *tty, struct file *filp)
507 if (!acm || !acm->used) 508 if (!acm || !acm->used)
508 return; 509 return;
509 510
510 down(&open_sem); 511 mutex_lock(&open_mutex);
511 if (!--acm->used) { 512 if (!--acm->used) {
512 if (acm->dev) { 513 if (acm->dev) {
513 acm_set_control(acm, acm->ctrlout = 0); 514 acm_set_control(acm, acm->ctrlout = 0);
@@ -518,7 +519,7 @@ static void acm_tty_close(struct tty_struct *tty, struct file *filp)
518 } else 519 } else
519 acm_tty_unregister(acm); 520 acm_tty_unregister(acm);
520 } 521 }
521 up(&open_sem); 522 mutex_unlock(&open_mutex);
522} 523}
523 524
524static int acm_tty_write(struct tty_struct *tty, const unsigned char *buf, int count) 525static int acm_tty_write(struct tty_struct *tty, const unsigned char *buf, int count)
@@ -1013,9 +1014,9 @@ static void acm_disconnect(struct usb_interface *intf)
1013 return; 1014 return;
1014 } 1015 }
1015 1016
1016 down(&open_sem); 1017 mutex_lock(&open_mutex);
1017 if (!usb_get_intfdata(intf)) { 1018 if (!usb_get_intfdata(intf)) {
1018 up(&open_sem); 1019 mutex_unlock(&open_mutex);
1019 return; 1020 return;
1020 } 1021 }
1021 acm->dev = NULL; 1022 acm->dev = NULL;
@@ -1045,11 +1046,11 @@ static void acm_disconnect(struct usb_interface *intf)
1045 1046
1046 if (!acm->used) { 1047 if (!acm->used) {
1047 acm_tty_unregister(acm); 1048 acm_tty_unregister(acm);
1048 up(&open_sem); 1049 mutex_unlock(&open_mutex);
1049 return; 1050 return;
1050 } 1051 }
1051 1052
1052 up(&open_sem); 1053 mutex_unlock(&open_mutex);
1053 1054
1054 if (acm->tty) 1055 if (acm->tty)
1055 tty_hangup(acm->tty); 1056 tty_hangup(acm->tty);
diff --git a/drivers/usb/class/usblp.c b/drivers/usb/class/usblp.c
index d34848ac30b0..48dee4b8d8e5 100644
--- a/drivers/usb/class/usblp.c
+++ b/drivers/usb/class/usblp.c
@@ -55,6 +55,7 @@
55#include <linux/init.h> 55#include <linux/init.h>
56#include <linux/slab.h> 56#include <linux/slab.h>
57#include <linux/lp.h> 57#include <linux/lp.h>
58#include <linux/mutex.h>
58#undef DEBUG 59#undef DEBUG
59#include <linux/usb.h> 60#include <linux/usb.h>
60 61
@@ -223,7 +224,7 @@ static int usblp_cache_device_id_string(struct usblp *usblp);
223 224
224/* forward reference to make our lives easier */ 225/* forward reference to make our lives easier */
225static struct usb_driver usblp_driver; 226static struct usb_driver usblp_driver;
226static DECLARE_MUTEX(usblp_sem); /* locks the existence of usblp's */ 227static DEFINE_MUTEX(usblp_mutex); /* locks the existence of usblp's */
227 228
228/* 229/*
229 * Functions for usblp control messages. 230 * Functions for usblp control messages.
@@ -351,7 +352,7 @@ static int usblp_open(struct inode *inode, struct file *file)
351 if (minor < 0) 352 if (minor < 0)
352 return -ENODEV; 353 return -ENODEV;
353 354
354 down (&usblp_sem); 355 mutex_lock (&usblp_mutex);
355 356
356 retval = -ENODEV; 357 retval = -ENODEV;
357 intf = usb_find_interface(&usblp_driver, minor); 358 intf = usb_find_interface(&usblp_driver, minor);
@@ -399,7 +400,7 @@ static int usblp_open(struct inode *inode, struct file *file)
399 } 400 }
400 } 401 }
401out: 402out:
402 up (&usblp_sem); 403 mutex_unlock (&usblp_mutex);
403 return retval; 404 return retval;
404} 405}
405 406
@@ -425,13 +426,13 @@ static int usblp_release(struct inode *inode, struct file *file)
425{ 426{
426 struct usblp *usblp = file->private_data; 427 struct usblp *usblp = file->private_data;
427 428
428 down (&usblp_sem); 429 mutex_lock (&usblp_mutex);
429 usblp->used = 0; 430 usblp->used = 0;
430 if (usblp->present) { 431 if (usblp->present) {
431 usblp_unlink_urbs(usblp); 432 usblp_unlink_urbs(usblp);
432 } else /* finish cleanup from disconnect */ 433 } else /* finish cleanup from disconnect */
433 usblp_cleanup (usblp); 434 usblp_cleanup (usblp);
434 up (&usblp_sem); 435 mutex_unlock (&usblp_mutex);
435 return 0; 436 return 0;
436} 437}
437 438
@@ -1152,7 +1153,7 @@ static void usblp_disconnect(struct usb_interface *intf)
1152 1153
1153 device_remove_file(&intf->dev, &dev_attr_ieee1284_id); 1154 device_remove_file(&intf->dev, &dev_attr_ieee1284_id);
1154 1155
1155 down (&usblp_sem); 1156 mutex_lock (&usblp_mutex);
1156 down (&usblp->sem); 1157 down (&usblp->sem);
1157 usblp->present = 0; 1158 usblp->present = 0;
1158 usb_set_intfdata (intf, NULL); 1159 usb_set_intfdata (intf, NULL);
@@ -1166,7 +1167,7 @@ static void usblp_disconnect(struct usb_interface *intf)
1166 1167
1167 if (!usblp->used) 1168 if (!usblp->used)
1168 usblp_cleanup (usblp); 1169 usblp_cleanup (usblp);
1169 up (&usblp_sem); 1170 mutex_unlock (&usblp_mutex);
1170} 1171}
1171 1172
1172static struct usb_device_id usblp_ids [] = { 1173static struct usb_device_id usblp_ids [] = {
diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
index 2684e15b813b..c0f37343a276 100644
--- a/drivers/usb/core/devices.c
+++ b/drivers/usb/core/devices.c
@@ -57,6 +57,7 @@
57#include <linux/usb.h> 57#include <linux/usb.h>
58#include <linux/smp_lock.h> 58#include <linux/smp_lock.h>
59#include <linux/usbdevice_fs.h> 59#include <linux/usbdevice_fs.h>
60#include <linux/mutex.h>
60#include <asm/uaccess.h> 61#include <asm/uaccess.h>
61 62
62#include "usb.h" 63#include "usb.h"
@@ -570,7 +571,7 @@ static ssize_t usb_device_read(struct file *file, char __user *buf, size_t nbyte
570 if (!access_ok(VERIFY_WRITE, buf, nbytes)) 571 if (!access_ok(VERIFY_WRITE, buf, nbytes))
571 return -EFAULT; 572 return -EFAULT;
572 573
573 down (&usb_bus_list_lock); 574 mutex_lock(&usb_bus_list_lock);
574 /* print devices for all busses */ 575 /* print devices for all busses */
575 list_for_each_entry(bus, &usb_bus_list, bus_list) { 576 list_for_each_entry(bus, &usb_bus_list, bus_list) {
576 /* recurse through all children of the root hub */ 577 /* recurse through all children of the root hub */
@@ -580,12 +581,12 @@ static ssize_t usb_device_read(struct file *file, char __user *buf, size_t nbyte
580 ret = usb_device_dump(&buf, &nbytes, &skip_bytes, ppos, bus->root_hub, bus, 0, 0, 0); 581 ret = usb_device_dump(&buf, &nbytes, &skip_bytes, ppos, bus->root_hub, bus, 0, 0, 0);
581 usb_unlock_device(bus->root_hub); 582 usb_unlock_device(bus->root_hub);
582 if (ret < 0) { 583 if (ret < 0) {
583 up(&usb_bus_list_lock); 584 mutex_unlock(&usb_bus_list_lock);
584 return ret; 585 return ret;
585 } 586 }
586 total_written += ret; 587 total_written += ret;
587 } 588 }
588 up (&usb_bus_list_lock); 589 mutex_unlock(&usb_bus_list_lock);
589 return total_written; 590 return total_written;
590} 591}
591 592
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index 0018bbc4de34..9223f2869674 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -34,6 +34,7 @@
34#include <asm/scatterlist.h> 34#include <asm/scatterlist.h>
35#include <linux/device.h> 35#include <linux/device.h>
36#include <linux/dma-mapping.h> 36#include <linux/dma-mapping.h>
37#include <linux/mutex.h>
37#include <asm/irq.h> 38#include <asm/irq.h>
38#include <asm/byteorder.h> 39#include <asm/byteorder.h>
39 40
@@ -93,7 +94,7 @@ struct usb_busmap {
93static struct usb_busmap busmap; 94static struct usb_busmap busmap;
94 95
95/* used when updating list of hcds */ 96/* used when updating list of hcds */
96DECLARE_MUTEX (usb_bus_list_lock); /* exported only for usbfs */ 97DEFINE_MUTEX(usb_bus_list_lock); /* exported only for usbfs */
97EXPORT_SYMBOL_GPL (usb_bus_list_lock); 98EXPORT_SYMBOL_GPL (usb_bus_list_lock);
98 99
99/* used for controlling access to virtual root hubs */ 100/* used for controlling access to virtual root hubs */
@@ -761,14 +762,14 @@ static int usb_register_bus(struct usb_bus *bus)
761{ 762{
762 int busnum; 763 int busnum;
763 764
764 down (&usb_bus_list_lock); 765 mutex_lock(&usb_bus_list_lock);
765 busnum = find_next_zero_bit (busmap.busmap, USB_MAXBUS, 1); 766 busnum = find_next_zero_bit (busmap.busmap, USB_MAXBUS, 1);
766 if (busnum < USB_MAXBUS) { 767 if (busnum < USB_MAXBUS) {
767 set_bit (busnum, busmap.busmap); 768 set_bit (busnum, busmap.busmap);
768 bus->busnum = busnum; 769 bus->busnum = busnum;
769 } else { 770 } else {
770 printk (KERN_ERR "%s: too many buses\n", usbcore_name); 771 printk (KERN_ERR "%s: too many buses\n", usbcore_name);
771 up(&usb_bus_list_lock); 772 mutex_unlock(&usb_bus_list_lock);
772 return -E2BIG; 773 return -E2BIG;
773 } 774 }
774 775
@@ -776,7 +777,7 @@ static int usb_register_bus(struct usb_bus *bus)
776 bus->controller, "usb_host%d", busnum); 777 bus->controller, "usb_host%d", busnum);
777 if (IS_ERR(bus->class_dev)) { 778 if (IS_ERR(bus->class_dev)) {
778 clear_bit(busnum, busmap.busmap); 779 clear_bit(busnum, busmap.busmap);
779 up(&usb_bus_list_lock); 780 mutex_unlock(&usb_bus_list_lock);
780 return PTR_ERR(bus->class_dev); 781 return PTR_ERR(bus->class_dev);
781 } 782 }
782 783
@@ -784,7 +785,7 @@ static int usb_register_bus(struct usb_bus *bus)
784 785
785 /* Add it to the local list of buses */ 786 /* Add it to the local list of buses */
786 list_add (&bus->bus_list, &usb_bus_list); 787 list_add (&bus->bus_list, &usb_bus_list);
787 up (&usb_bus_list_lock); 788 mutex_unlock(&usb_bus_list_lock);
788 789
789 usb_notify_add_bus(bus); 790 usb_notify_add_bus(bus);
790 791
@@ -809,9 +810,9 @@ static void usb_deregister_bus (struct usb_bus *bus)
809 * controller code, as well as having it call this when cleaning 810 * controller code, as well as having it call this when cleaning
810 * itself up 811 * itself up
811 */ 812 */
812 down (&usb_bus_list_lock); 813 mutex_lock(&usb_bus_list_lock);
813 list_del (&bus->bus_list); 814 list_del (&bus->bus_list);
814 up (&usb_bus_list_lock); 815 mutex_unlock(&usb_bus_list_lock);
815 816
816 usb_notify_remove_bus(bus); 817 usb_notify_remove_bus(bus);
817 818
@@ -844,14 +845,14 @@ static int register_root_hub (struct usb_device *usb_dev,
844 set_bit (devnum, usb_dev->bus->devmap.devicemap); 845 set_bit (devnum, usb_dev->bus->devmap.devicemap);
845 usb_set_device_state(usb_dev, USB_STATE_ADDRESS); 846 usb_set_device_state(usb_dev, USB_STATE_ADDRESS);
846 847
847 down (&usb_bus_list_lock); 848 mutex_lock(&usb_bus_list_lock);
848 usb_dev->bus->root_hub = usb_dev; 849 usb_dev->bus->root_hub = usb_dev;
849 850
850 usb_dev->ep0.desc.wMaxPacketSize = __constant_cpu_to_le16(64); 851 usb_dev->ep0.desc.wMaxPacketSize = __constant_cpu_to_le16(64);
851 retval = usb_get_device_descriptor(usb_dev, USB_DT_DEVICE_SIZE); 852 retval = usb_get_device_descriptor(usb_dev, USB_DT_DEVICE_SIZE);
852 if (retval != sizeof usb_dev->descriptor) { 853 if (retval != sizeof usb_dev->descriptor) {
853 usb_dev->bus->root_hub = NULL; 854 usb_dev->bus->root_hub = NULL;
854 up (&usb_bus_list_lock); 855 mutex_unlock(&usb_bus_list_lock);
855 dev_dbg (parent_dev, "can't read %s device descriptor %d\n", 856 dev_dbg (parent_dev, "can't read %s device descriptor %d\n",
856 usb_dev->dev.bus_id, retval); 857 usb_dev->dev.bus_id, retval);
857 return (retval < 0) ? retval : -EMSGSIZE; 858 return (retval < 0) ? retval : -EMSGSIZE;
@@ -863,7 +864,7 @@ static int register_root_hub (struct usb_device *usb_dev,
863 dev_err (parent_dev, "can't register root hub for %s, %d\n", 864 dev_err (parent_dev, "can't register root hub for %s, %d\n",
864 usb_dev->dev.bus_id, retval); 865 usb_dev->dev.bus_id, retval);
865 } 866 }
866 up (&usb_bus_list_lock); 867 mutex_unlock(&usb_bus_list_lock);
867 868
868 if (retval == 0) { 869 if (retval == 0) {
869 spin_lock_irq (&hcd_root_hub_lock); 870 spin_lock_irq (&hcd_root_hub_lock);
@@ -1891,9 +1892,9 @@ void usb_remove_hcd(struct usb_hcd *hcd)
1891 hcd->rh_registered = 0; 1892 hcd->rh_registered = 0;
1892 spin_unlock_irq (&hcd_root_hub_lock); 1893 spin_unlock_irq (&hcd_root_hub_lock);
1893 1894
1894 down(&usb_bus_list_lock); 1895 mutex_lock(&usb_bus_list_lock);
1895 usb_disconnect(&hcd->self.root_hub); 1896 usb_disconnect(&hcd->self.root_hub);
1896 up(&usb_bus_list_lock); 1897 mutex_unlock(&usb_bus_list_lock);
1897 1898
1898 hcd->poll_rh = 0; 1899 hcd->poll_rh = 0;
1899 del_timer_sync(&hcd->rh_timer); 1900 del_timer_sync(&hcd->rh_timer);
diff --git a/drivers/usb/core/hcd.h b/drivers/usb/core/hcd.h
index 591b5aad1a18..f44a2fe62a9d 100644
--- a/drivers/usb/core/hcd.h
+++ b/drivers/usb/core/hcd.h
@@ -364,7 +364,7 @@ extern void usb_set_device_state(struct usb_device *udev,
364/* exported only within usbcore */ 364/* exported only within usbcore */
365 365
366extern struct list_head usb_bus_list; 366extern struct list_head usb_bus_list;
367extern struct semaphore usb_bus_list_lock; 367extern struct mutex usb_bus_list_lock;
368extern wait_queue_head_t usb_kill_urb_queue; 368extern wait_queue_head_t usb_kill_urb_queue;
369 369
370extern struct usb_bus *usb_bus_get (struct usb_bus *bus); 370extern struct usb_bus *usb_bus_get (struct usb_bus *bus);
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 650d5ee5871b..867fa8130238 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -22,6 +22,7 @@
22#include <linux/usb.h> 22#include <linux/usb.h>
23#include <linux/usbdevice_fs.h> 23#include <linux/usbdevice_fs.h>
24#include <linux/kthread.h> 24#include <linux/kthread.h>
25#include <linux/mutex.h>
25 26
26#include <asm/semaphore.h> 27#include <asm/semaphore.h>
27#include <asm/uaccess.h> 28#include <asm/uaccess.h>
@@ -2162,7 +2163,7 @@ static int
2162hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1, 2163hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1,
2163 int retry_counter) 2164 int retry_counter)
2164{ 2165{
2165 static DECLARE_MUTEX(usb_address0_sem); 2166 static DEFINE_MUTEX(usb_address0_mutex);
2166 2167
2167 struct usb_device *hdev = hub->hdev; 2168 struct usb_device *hdev = hub->hdev;
2168 int i, j, retval; 2169 int i, j, retval;
@@ -2183,7 +2184,7 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1,
2183 if (oldspeed == USB_SPEED_LOW) 2184 if (oldspeed == USB_SPEED_LOW)
2184 delay = HUB_LONG_RESET_TIME; 2185 delay = HUB_LONG_RESET_TIME;
2185 2186
2186 down(&usb_address0_sem); 2187 mutex_lock(&usb_address0_mutex);
2187 2188
2188 /* Reset the device; full speed may morph to high speed */ 2189 /* Reset the device; full speed may morph to high speed */
2189 retval = hub_port_reset(hub, port1, udev, delay); 2190 retval = hub_port_reset(hub, port1, udev, delay);
@@ -2381,7 +2382,7 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1,
2381fail: 2382fail:
2382 if (retval) 2383 if (retval)
2383 hub_port_disable(hub, port1, 0); 2384 hub_port_disable(hub, port1, 0);
2384 up(&usb_address0_sem); 2385 mutex_unlock(&usb_address0_mutex);
2385 return retval; 2386 return retval;
2386} 2387}
2387 2388
diff --git a/drivers/usb/core/notify.c b/drivers/usb/core/notify.c
index fbbebab52fbd..4b55285de9a0 100644
--- a/drivers/usb/core/notify.c
+++ b/drivers/usb/core/notify.c
@@ -13,16 +13,17 @@
13#include <linux/kernel.h> 13#include <linux/kernel.h>
14#include <linux/notifier.h> 14#include <linux/notifier.h>
15#include <linux/usb.h> 15#include <linux/usb.h>
16#include <linux/mutex.h>
16#include "usb.h" 17#include "usb.h"
17 18
18 19
19static struct notifier_block *usb_notifier_list; 20static struct notifier_block *usb_notifier_list;
20static DECLARE_MUTEX(usb_notifier_lock); 21static DEFINE_MUTEX(usb_notifier_lock);
21 22
22static void usb_notifier_chain_register(struct notifier_block **list, 23static void usb_notifier_chain_register(struct notifier_block **list,
23 struct notifier_block *n) 24 struct notifier_block *n)
24{ 25{
25 down(&usb_notifier_lock); 26 mutex_lock(&usb_notifier_lock);
26 while (*list) { 27 while (*list) {
27 if (n->priority > (*list)->priority) 28 if (n->priority > (*list)->priority)
28 break; 29 break;
@@ -30,13 +31,13 @@ static void usb_notifier_chain_register(struct notifier_block **list,
30 } 31 }
31 n->next = *list; 32 n->next = *list;
32 *list = n; 33 *list = n;
33 up(&usb_notifier_lock); 34 mutex_unlock(&usb_notifier_lock);
34} 35}
35 36
36static void usb_notifier_chain_unregister(struct notifier_block **nl, 37static void usb_notifier_chain_unregister(struct notifier_block **nl,
37 struct notifier_block *n) 38 struct notifier_block *n)
38{ 39{
39 down(&usb_notifier_lock); 40 mutex_lock(&usb_notifier_lock);
40 while ((*nl)!=NULL) { 41 while ((*nl)!=NULL) {
41 if ((*nl)==n) { 42 if ((*nl)==n) {
42 *nl = n->next; 43 *nl = n->next;
@@ -45,7 +46,7 @@ static void usb_notifier_chain_unregister(struct notifier_block **nl,
45 nl=&((*nl)->next); 46 nl=&((*nl)->next);
46 } 47 }
47exit: 48exit:
48 up(&usb_notifier_lock); 49 mutex_unlock(&usb_notifier_lock);
49} 50}
50 51
51static int usb_notifier_call_chain(struct notifier_block **n, 52static int usb_notifier_call_chain(struct notifier_block **n,
@@ -54,7 +55,7 @@ static int usb_notifier_call_chain(struct notifier_block **n,
54 int ret=NOTIFY_DONE; 55 int ret=NOTIFY_DONE;
55 struct notifier_block *nb = *n; 56 struct notifier_block *nb = *n;
56 57
57 down(&usb_notifier_lock); 58 mutex_lock(&usb_notifier_lock);
58 while (nb) { 59 while (nb) {
59 ret = nb->notifier_call(nb,val,v); 60 ret = nb->notifier_call(nb,val,v);
60 if (ret&NOTIFY_STOP_MASK) { 61 if (ret&NOTIFY_STOP_MASK) {
@@ -63,7 +64,7 @@ static int usb_notifier_call_chain(struct notifier_block **n,
63 nb = nb->next; 64 nb = nb->next;
64 } 65 }
65exit: 66exit:
66 up(&usb_notifier_lock); 67 mutex_unlock(&usb_notifier_lock);
67 return ret; 68 return ret;
68} 69}
69 70
diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
index 13d1d367f7f1..d7352aa73b5e 100644
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -33,6 +33,7 @@
33#include <linux/errno.h> 33#include <linux/errno.h>
34#include <linux/smp_lock.h> 34#include <linux/smp_lock.h>
35#include <linux/usb.h> 35#include <linux/usb.h>
36#include <linux/mutex.h>
36 37
37#include <asm/io.h> 38#include <asm/io.h>
38#include <asm/scatterlist.h> 39#include <asm/scatterlist.h>
@@ -639,7 +640,7 @@ struct usb_device *usb_find_device(u16 vendor_id, u16 product_id)
639 struct usb_bus *bus; 640 struct usb_bus *bus;
640 struct usb_device *dev = NULL; 641 struct usb_device *dev = NULL;
641 642
642 down(&usb_bus_list_lock); 643 mutex_lock(&usb_bus_list_lock);
643 for (buslist = usb_bus_list.next; 644 for (buslist = usb_bus_list.next;
644 buslist != &usb_bus_list; 645 buslist != &usb_bus_list;
645 buslist = buslist->next) { 646 buslist = buslist->next) {
@@ -653,7 +654,7 @@ struct usb_device *usb_find_device(u16 vendor_id, u16 product_id)
653 goto exit; 654 goto exit;
654 } 655 }
655exit: 656exit:
656 up(&usb_bus_list_lock); 657 mutex_unlock(&usb_bus_list_lock);
657 return dev; 658 return dev;
658} 659}
659 660
diff --git a/drivers/usb/image/mdc800.c b/drivers/usb/image/mdc800.c
index 4e3e4d048c14..08daf400f985 100644
--- a/drivers/usb/image/mdc800.c
+++ b/drivers/usb/image/mdc800.c
@@ -96,6 +96,7 @@
96#include <linux/module.h> 96#include <linux/module.h>
97#include <linux/smp_lock.h> 97#include <linux/smp_lock.h>
98#include <linux/wait.h> 98#include <linux/wait.h>
99#include <linux/mutex.h>
99 100
100#include <linux/usb.h> 101#include <linux/usb.h>
101#include <linux/fs.h> 102#include <linux/fs.h>
@@ -169,7 +170,7 @@ struct mdc800_data
169 int out_count; // Bytes in the buffer 170 int out_count; // Bytes in the buffer
170 171
171 int open; // Camera device open ? 172 int open; // Camera device open ?
172 struct semaphore io_lock; // IO -lock 173 struct mutex io_lock; // IO -lock
173 174
174 char in [8]; // Command Input Buffer 175 char in [8]; // Command Input Buffer
175 int in_count; 176 int in_count;
@@ -497,7 +498,7 @@ static int mdc800_usb_probe (struct usb_interface *intf,
497 498
498 info ("Found Mustek MDC800 on USB."); 499 info ("Found Mustek MDC800 on USB.");
499 500
500 down (&mdc800->io_lock); 501 mutex_lock(&mdc800->io_lock);
501 502
502 retval = usb_register_dev(intf, &mdc800_class); 503 retval = usb_register_dev(intf, &mdc800_class);
503 if (retval) { 504 if (retval) {
@@ -542,7 +543,7 @@ static int mdc800_usb_probe (struct usb_interface *intf,
542 543
543 mdc800->state=READY; 544 mdc800->state=READY;
544 545
545 up (&mdc800->io_lock); 546 mutex_unlock(&mdc800->io_lock);
546 547
547 usb_set_intfdata(intf, mdc800); 548 usb_set_intfdata(intf, mdc800);
548 return 0; 549 return 0;
@@ -620,7 +621,7 @@ static int mdc800_device_open (struct inode* inode, struct file *file)
620 int retval=0; 621 int retval=0;
621 int errn=0; 622 int errn=0;
622 623
623 down (&mdc800->io_lock); 624 mutex_lock(&mdc800->io_lock);
624 625
625 if (mdc800->state == NOT_CONNECTED) 626 if (mdc800->state == NOT_CONNECTED)
626 { 627 {
@@ -656,7 +657,7 @@ static int mdc800_device_open (struct inode* inode, struct file *file)
656 dbg ("Mustek MDC800 device opened."); 657 dbg ("Mustek MDC800 device opened.");
657 658
658error_out: 659error_out:
659 up (&mdc800->io_lock); 660 mutex_unlock(&mdc800->io_lock);
660 return errn; 661 return errn;
661} 662}
662 663
@@ -669,7 +670,7 @@ static int mdc800_device_release (struct inode* inode, struct file *file)
669 int retval=0; 670 int retval=0;
670 dbg ("Mustek MDC800 device closed."); 671 dbg ("Mustek MDC800 device closed.");
671 672
672 down (&mdc800->io_lock); 673 mutex_lock(&mdc800->io_lock);
673 if (mdc800->open && (mdc800->state != NOT_CONNECTED)) 674 if (mdc800->open && (mdc800->state != NOT_CONNECTED))
674 { 675 {
675 usb_kill_urb(mdc800->irq_urb); 676 usb_kill_urb(mdc800->irq_urb);
@@ -682,7 +683,7 @@ static int mdc800_device_release (struct inode* inode, struct file *file)
682 retval=-EIO; 683 retval=-EIO;
683 } 684 }
684 685
685 up(&mdc800->io_lock); 686 mutex_unlock(&mdc800->io_lock);
686 return retval; 687 return retval;
687} 688}
688 689
@@ -695,21 +696,21 @@ static ssize_t mdc800_device_read (struct file *file, char __user *buf, size_t l
695 size_t left=len, sts=len; /* single transfer size */ 696 size_t left=len, sts=len; /* single transfer size */
696 char __user *ptr = buf; 697 char __user *ptr = buf;
697 698
698 down (&mdc800->io_lock); 699 mutex_lock(&mdc800->io_lock);
699 if (mdc800->state == NOT_CONNECTED) 700 if (mdc800->state == NOT_CONNECTED)
700 { 701 {
701 up (&mdc800->io_lock); 702 mutex_unlock(&mdc800->io_lock);
702 return -EBUSY; 703 return -EBUSY;
703 } 704 }
704 if (mdc800->state == WORKING) 705 if (mdc800->state == WORKING)
705 { 706 {
706 warn ("Illegal State \"working\" reached during read ?!"); 707 warn ("Illegal State \"working\" reached during read ?!");
707 up (&mdc800->io_lock); 708 mutex_unlock(&mdc800->io_lock);
708 return -EBUSY; 709 return -EBUSY;
709 } 710 }
710 if (!mdc800->open) 711 if (!mdc800->open)
711 { 712 {
712 up (&mdc800->io_lock); 713 mutex_unlock(&mdc800->io_lock);
713 return -EBUSY; 714 return -EBUSY;
714 } 715 }
715 716
@@ -717,7 +718,7 @@ static ssize_t mdc800_device_read (struct file *file, char __user *buf, size_t l
717 { 718 {
718 if (signal_pending (current)) 719 if (signal_pending (current))
719 { 720 {
720 up (&mdc800->io_lock); 721 mutex_unlock(&mdc800->io_lock);
721 return -EINTR; 722 return -EINTR;
722 } 723 }
723 724
@@ -736,7 +737,7 @@ static ssize_t mdc800_device_read (struct file *file, char __user *buf, size_t l
736 if (usb_submit_urb (mdc800->download_urb, GFP_KERNEL)) 737 if (usb_submit_urb (mdc800->download_urb, GFP_KERNEL))
737 { 738 {
738 err ("Can't submit download urb (status=%i)",mdc800->download_urb->status); 739 err ("Can't submit download urb (status=%i)",mdc800->download_urb->status);
739 up (&mdc800->io_lock); 740 mutex_unlock(&mdc800->io_lock);
740 return len-left; 741 return len-left;
741 } 742 }
742 wait_event_timeout(mdc800->download_wait, mdc800->downloaded, 743 wait_event_timeout(mdc800->download_wait, mdc800->downloaded,
@@ -745,14 +746,14 @@ static ssize_t mdc800_device_read (struct file *file, char __user *buf, size_t l
745 if (mdc800->download_urb->status != 0) 746 if (mdc800->download_urb->status != 0)
746 { 747 {
747 err ("request download-bytes fails (status=%i)",mdc800->download_urb->status); 748 err ("request download-bytes fails (status=%i)",mdc800->download_urb->status);
748 up (&mdc800->io_lock); 749 mutex_unlock(&mdc800->io_lock);
749 return len-left; 750 return len-left;
750 } 751 }
751 } 752 }
752 else 753 else
753 { 754 {
754 /* No more bytes -> that's an error*/ 755 /* No more bytes -> that's an error*/
755 up (&mdc800->io_lock); 756 mutex_unlock(&mdc800->io_lock);
756 return -EIO; 757 return -EIO;
757 } 758 }
758 } 759 }
@@ -761,7 +762,7 @@ static ssize_t mdc800_device_read (struct file *file, char __user *buf, size_t l
761 /* Copy Bytes */ 762 /* Copy Bytes */
762 if (copy_to_user(ptr, &mdc800->out [mdc800->out_ptr], 763 if (copy_to_user(ptr, &mdc800->out [mdc800->out_ptr],
763 sts)) { 764 sts)) {
764 up(&mdc800->io_lock); 765 mutex_unlock(&mdc800->io_lock);
765 return -EFAULT; 766 return -EFAULT;
766 } 767 }
767 ptr+=sts; 768 ptr+=sts;
@@ -770,7 +771,7 @@ static ssize_t mdc800_device_read (struct file *file, char __user *buf, size_t l
770 } 771 }
771 } 772 }
772 773
773 up (&mdc800->io_lock); 774 mutex_unlock(&mdc800->io_lock);
774 return len-left; 775 return len-left;
775} 776}
776 777
@@ -785,15 +786,15 @@ static ssize_t mdc800_device_write (struct file *file, const char __user *buf, s
785{ 786{
786 size_t i=0; 787 size_t i=0;
787 788
788 down (&mdc800->io_lock); 789 mutex_lock(&mdc800->io_lock);
789 if (mdc800->state != READY) 790 if (mdc800->state != READY)
790 { 791 {
791 up (&mdc800->io_lock); 792 mutex_unlock(&mdc800->io_lock);
792 return -EBUSY; 793 return -EBUSY;
793 } 794 }
794 if (!mdc800->open ) 795 if (!mdc800->open )
795 { 796 {
796 up (&mdc800->io_lock); 797 mutex_unlock(&mdc800->io_lock);
797 return -EBUSY; 798 return -EBUSY;
798 } 799 }
799 800
@@ -802,13 +803,13 @@ static ssize_t mdc800_device_write (struct file *file, const char __user *buf, s
802 unsigned char c; 803 unsigned char c;
803 if (signal_pending (current)) 804 if (signal_pending (current))
804 { 805 {
805 up (&mdc800->io_lock); 806 mutex_unlock(&mdc800->io_lock);
806 return -EINTR; 807 return -EINTR;
807 } 808 }
808 809
809 if(get_user(c, buf+i)) 810 if(get_user(c, buf+i))
810 { 811 {
811 up(&mdc800->io_lock); 812 mutex_unlock(&mdc800->io_lock);
812 return -EFAULT; 813 return -EFAULT;
813 } 814 }
814 815
@@ -829,7 +830,7 @@ static ssize_t mdc800_device_write (struct file *file, const char __user *buf, s
829 } 830 }
830 else 831 else
831 { 832 {
832 up (&mdc800->io_lock); 833 mutex_unlock(&mdc800->io_lock);
833 return -EIO; 834 return -EIO;
834 } 835 }
835 836
@@ -841,7 +842,7 @@ static ssize_t mdc800_device_write (struct file *file, const char __user *buf, s
841 if (mdc800_usb_waitForIRQ (0,TO_GET_READY)) 842 if (mdc800_usb_waitForIRQ (0,TO_GET_READY))
842 { 843 {
843 err ("Camera didn't get ready.\n"); 844 err ("Camera didn't get ready.\n");
844 up (&mdc800->io_lock); 845 mutex_unlock(&mdc800->io_lock);
845 return -EIO; 846 return -EIO;
846 } 847 }
847 848
@@ -853,7 +854,7 @@ static ssize_t mdc800_device_write (struct file *file, const char __user *buf, s
853 if (usb_submit_urb (mdc800->write_urb, GFP_KERNEL)) 854 if (usb_submit_urb (mdc800->write_urb, GFP_KERNEL))
854 { 855 {
855 err ("submitting write urb fails (status=%i)", mdc800->write_urb->status); 856 err ("submitting write urb fails (status=%i)", mdc800->write_urb->status);
856 up (&mdc800->io_lock); 857 mutex_unlock(&mdc800->io_lock);
857 return -EIO; 858 return -EIO;
858 } 859 }
859 wait_event_timeout(mdc800->write_wait, mdc800->written, TO_WRITE_GET_READY*HZ/1000); 860 wait_event_timeout(mdc800->write_wait, mdc800->written, TO_WRITE_GET_READY*HZ/1000);
@@ -861,7 +862,7 @@ static ssize_t mdc800_device_write (struct file *file, const char __user *buf, s
861 if (mdc800->state == WORKING) 862 if (mdc800->state == WORKING)
862 { 863 {
863 usb_kill_urb(mdc800->write_urb); 864 usb_kill_urb(mdc800->write_urb);
864 up (&mdc800->io_lock); 865 mutex_unlock(&mdc800->io_lock);
865 return -EIO; 866 return -EIO;
866 } 867 }
867 868
@@ -873,7 +874,7 @@ static ssize_t mdc800_device_write (struct file *file, const char __user *buf, s
873 { 874 {
874 err ("call 0x07 before 0x05,0x3e"); 875 err ("call 0x07 before 0x05,0x3e");
875 mdc800->state=READY; 876 mdc800->state=READY;
876 up (&mdc800->io_lock); 877 mutex_unlock(&mdc800->io_lock);
877 return -EIO; 878 return -EIO;
878 } 879 }
879 mdc800->pic_len=-1; 880 mdc800->pic_len=-1;
@@ -892,7 +893,7 @@ static ssize_t mdc800_device_write (struct file *file, const char __user *buf, s
892 if (mdc800_usb_waitForIRQ (1,TO_READ_FROM_IRQ)) 893 if (mdc800_usb_waitForIRQ (1,TO_READ_FROM_IRQ))
893 { 894 {
894 err ("requesting answer from irq fails"); 895 err ("requesting answer from irq fails");
895 up (&mdc800->io_lock); 896 mutex_unlock(&mdc800->io_lock);
896 return -EIO; 897 return -EIO;
897 } 898 }
898 899
@@ -920,7 +921,7 @@ static ssize_t mdc800_device_write (struct file *file, const char __user *buf, s
920 if (mdc800_usb_waitForIRQ (0,TO_DEFAULT_COMMAND)) 921 if (mdc800_usb_waitForIRQ (0,TO_DEFAULT_COMMAND))
921 { 922 {
922 err ("Command Timeout."); 923 err ("Command Timeout.");
923 up (&mdc800->io_lock); 924 mutex_unlock(&mdc800->io_lock);
924 return -EIO; 925 return -EIO;
925 } 926 }
926 } 927 }
@@ -930,7 +931,7 @@ static ssize_t mdc800_device_write (struct file *file, const char __user *buf, s
930 } 931 }
931 i++; 932 i++;
932 } 933 }
933 up (&mdc800->io_lock); 934 mutex_unlock(&mdc800->io_lock);
934 return i; 935 return i;
935} 936}
936 937
@@ -984,7 +985,7 @@ static int __init usb_mdc800_init (void)
984 985
985 mdc800->dev = NULL; 986 mdc800->dev = NULL;
986 mdc800->state=NOT_CONNECTED; 987 mdc800->state=NOT_CONNECTED;
987 init_MUTEX (&mdc800->io_lock); 988 mutex_init (&mdc800->io_lock);
988 989
989 init_waitqueue_head (&mdc800->irq_wait); 990 init_waitqueue_head (&mdc800->irq_wait);
990 init_waitqueue_head (&mdc800->write_wait); 991 init_waitqueue_head (&mdc800->write_wait);
diff --git a/drivers/usb/input/ati_remote.c b/drivers/usb/input/ati_remote.c
index f7bdc506e613..99f986cb6e95 100644
--- a/drivers/usb/input/ati_remote.c
+++ b/drivers/usb/input/ati_remote.c
@@ -159,8 +159,6 @@ static const char accel[] = { 1, 2, 4, 6, 9, 13, 20 };
159 */ 159 */
160#define FILTER_TIME (HZ / 20) 160#define FILTER_TIME (HZ / 20)
161 161
162static DECLARE_MUTEX(disconnect_sem);
163
164struct ati_remote { 162struct ati_remote {
165 struct input_dev *idev; 163 struct input_dev *idev;
166 struct usb_device *udev; 164 struct usb_device *udev;
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;
diff --git a/drivers/usb/misc/idmouse.c b/drivers/usb/misc/idmouse.c
index b3aca5124339..d0b167256699 100644
--- a/drivers/usb/misc/idmouse.c
+++ b/drivers/usb/misc/idmouse.c
@@ -25,6 +25,7 @@
25#include <linux/module.h> 25#include <linux/module.h>
26#include <linux/smp_lock.h> 26#include <linux/smp_lock.h>
27#include <linux/completion.h> 27#include <linux/completion.h>
28#include <linux/mutex.h>
28#include <asm/uaccess.h> 29#include <asm/uaccess.h>
29#include <linux/usb.h> 30#include <linux/usb.h>
30 31
@@ -121,7 +122,7 @@ static struct usb_driver idmouse_driver = {
121}; 122};
122 123
123/* prevent races between open() and disconnect() */ 124/* prevent races between open() and disconnect() */
124static DECLARE_MUTEX(disconnect_sem); 125static DEFINE_MUTEX(disconnect_mutex);
125 126
126static int idmouse_create_image(struct usb_idmouse *dev) 127static int idmouse_create_image(struct usb_idmouse *dev)
127{ 128{
@@ -213,18 +214,18 @@ static int idmouse_open(struct inode *inode, struct file *file)
213 int result = 0; 214 int result = 0;
214 215
215 /* prevent disconnects */ 216 /* prevent disconnects */
216 down(&disconnect_sem); 217 mutex_lock(&disconnect_mutex);
217 218
218 /* get the interface from minor number and driver information */ 219 /* get the interface from minor number and driver information */
219 interface = usb_find_interface (&idmouse_driver, iminor (inode)); 220 interface = usb_find_interface (&idmouse_driver, iminor (inode));
220 if (!interface) { 221 if (!interface) {
221 up(&disconnect_sem); 222 mutex_unlock(&disconnect_mutex);
222 return -ENODEV; 223 return -ENODEV;
223 } 224 }
224 /* get the device information block from the interface */ 225 /* get the device information block from the interface */
225 dev = usb_get_intfdata(interface); 226 dev = usb_get_intfdata(interface);
226 if (!dev) { 227 if (!dev) {
227 up(&disconnect_sem); 228 mutex_unlock(&disconnect_mutex);
228 return -ENODEV; 229 return -ENODEV;
229 } 230 }
230 231
@@ -258,7 +259,7 @@ error:
258 up(&dev->sem); 259 up(&dev->sem);
259 260
260 /* unlock the disconnect semaphore */ 261 /* unlock the disconnect semaphore */
261 up(&disconnect_sem); 262 mutex_unlock(&disconnect_mutex);
262 return result; 263 return result;
263} 264}
264 265
@@ -267,12 +268,12 @@ static int idmouse_release(struct inode *inode, struct file *file)
267 struct usb_idmouse *dev; 268 struct usb_idmouse *dev;
268 269
269 /* prevent a race condition with open() */ 270 /* prevent a race condition with open() */
270 down(&disconnect_sem); 271 mutex_lock(&disconnect_mutex);
271 272
272 dev = (struct usb_idmouse *) file->private_data; 273 dev = (struct usb_idmouse *) file->private_data;
273 274
274 if (dev == NULL) { 275 if (dev == NULL) {
275 up(&disconnect_sem); 276 mutex_unlock(&disconnect_mutex);
276 return -ENODEV; 277 return -ENODEV;
277 } 278 }
278 279
@@ -282,7 +283,7 @@ static int idmouse_release(struct inode *inode, struct file *file)
282 /* are we really open? */ 283 /* are we really open? */
283 if (dev->open <= 0) { 284 if (dev->open <= 0) {
284 up(&dev->sem); 285 up(&dev->sem);
285 up(&disconnect_sem); 286 mutex_unlock(&disconnect_mutex);
286 return -ENODEV; 287 return -ENODEV;
287 } 288 }
288 289
@@ -292,12 +293,12 @@ static int idmouse_release(struct inode *inode, struct file *file)
292 /* the device was unplugged before the file was released */ 293 /* the device was unplugged before the file was released */
293 up(&dev->sem); 294 up(&dev->sem);
294 idmouse_delete(dev); 295 idmouse_delete(dev);
295 up(&disconnect_sem); 296 mutex_unlock(&disconnect_mutex);
296 return 0; 297 return 0;
297 } 298 }
298 299
299 up(&dev->sem); 300 up(&dev->sem);
300 up(&disconnect_sem); 301 mutex_unlock(&disconnect_mutex);
301 return 0; 302 return 0;
302} 303}
303 304
@@ -399,7 +400,7 @@ static void idmouse_disconnect(struct usb_interface *interface)
399 struct usb_idmouse *dev; 400 struct usb_idmouse *dev;
400 401
401 /* prevent races with open() */ 402 /* prevent races with open() */
402 down(&disconnect_sem); 403 mutex_lock(&disconnect_mutex);
403 404
404 /* get device structure */ 405 /* get device structure */
405 dev = usb_get_intfdata(interface); 406 dev = usb_get_intfdata(interface);
@@ -421,7 +422,7 @@ static void idmouse_disconnect(struct usb_interface *interface)
421 if (!dev->open) 422 if (!dev->open)
422 idmouse_delete(dev); 423 idmouse_delete(dev);
423 424
424 up(&disconnect_sem); 425 mutex_unlock(&disconnect_mutex);
425 426
426 info("%s disconnected", DRIVER_DESC); 427 info("%s disconnected", DRIVER_DESC);
427} 428}
diff --git a/drivers/usb/misc/ldusb.c b/drivers/usb/misc/ldusb.c
index f6bdaf08a80f..966acb474f67 100644
--- a/drivers/usb/misc/ldusb.c
+++ b/drivers/usb/misc/ldusb.c
@@ -33,6 +33,7 @@
33#include <linux/init.h> 33#include <linux/init.h>
34#include <linux/slab.h> 34#include <linux/slab.h>
35#include <linux/module.h> 35#include <linux/module.h>
36#include <linux/mutex.h>
36 37
37#include <asm/uaccess.h> 38#include <asm/uaccess.h>
38#include <linux/input.h> 39#include <linux/input.h>
@@ -172,7 +173,7 @@ struct ld_usb {
172}; 173};
173 174
174/* prevent races between open() and disconnect() */ 175/* prevent races between open() and disconnect() */
175static DECLARE_MUTEX(disconnect_sem); 176static DEFINE_MUTEX(disconnect_mutex);
176 177
177static struct usb_driver ld_usb_driver; 178static struct usb_driver ld_usb_driver;
178 179
@@ -293,7 +294,7 @@ static int ld_usb_open(struct inode *inode, struct file *file)
293 nonseekable_open(inode, file); 294 nonseekable_open(inode, file);
294 subminor = iminor(inode); 295 subminor = iminor(inode);
295 296
296 down(&disconnect_sem); 297 mutex_lock(&disconnect_mutex);
297 298
298 interface = usb_find_interface(&ld_usb_driver, subminor); 299 interface = usb_find_interface(&ld_usb_driver, subminor);
299 300
@@ -355,7 +356,7 @@ unlock_exit:
355 up(&dev->sem); 356 up(&dev->sem);
356 357
357unlock_disconnect_exit: 358unlock_disconnect_exit:
358 up(&disconnect_sem); 359 mutex_unlock(&disconnect_mutex);
359 360
360 return retval; 361 return retval;
361} 362}
@@ -740,7 +741,7 @@ static void ld_usb_disconnect(struct usb_interface *intf)
740 struct ld_usb *dev; 741 struct ld_usb *dev;
741 int minor; 742 int minor;
742 743
743 down(&disconnect_sem); 744 mutex_lock(&disconnect_mutex);
744 745
745 dev = usb_get_intfdata(intf); 746 dev = usb_get_intfdata(intf);
746 usb_set_intfdata(intf, NULL); 747 usb_set_intfdata(intf, NULL);
@@ -761,7 +762,7 @@ static void ld_usb_disconnect(struct usb_interface *intf)
761 up(&dev->sem); 762 up(&dev->sem);
762 } 763 }
763 764
764 up(&disconnect_sem); 765 mutex_unlock(&disconnect_mutex);
765 766
766 dev_info(&intf->dev, "LD USB Device #%d now disconnected\n", 767 dev_info(&intf->dev, "LD USB Device #%d now disconnected\n",
767 (minor - USB_LD_MINOR_BASE)); 768 (minor - USB_LD_MINOR_BASE));
diff --git a/drivers/usb/misc/legousbtower.c b/drivers/usb/misc/legousbtower.c
index 1336745b8f55..779bcf0373ad 100644
--- a/drivers/usb/misc/legousbtower.c
+++ b/drivers/usb/misc/legousbtower.c
@@ -83,6 +83,7 @@
83#include <linux/module.h> 83#include <linux/module.h>
84#include <linux/smp_lock.h> 84#include <linux/smp_lock.h>
85#include <linux/completion.h> 85#include <linux/completion.h>
86#include <linux/mutex.h>
86#include <asm/uaccess.h> 87#include <asm/uaccess.h>
87#include <linux/usb.h> 88#include <linux/usb.h>
88#include <linux/poll.h> 89#include <linux/poll.h>
@@ -256,7 +257,7 @@ static void tower_disconnect (struct usb_interface *interface);
256 257
257 258
258/* prevent races between open() and disconnect */ 259/* prevent races between open() and disconnect */
259static DECLARE_MUTEX (disconnect_sem); 260static DEFINE_MUTEX (disconnect_mutex);
260 261
261/* file operations needed when we register this driver */ 262/* file operations needed when we register this driver */
262static struct file_operations tower_fops = { 263static struct file_operations tower_fops = {
@@ -349,7 +350,7 @@ static int tower_open (struct inode *inode, struct file *file)
349 nonseekable_open(inode, file); 350 nonseekable_open(inode, file);
350 subminor = iminor(inode); 351 subminor = iminor(inode);
351 352
352 down (&disconnect_sem); 353 mutex_lock (&disconnect_mutex);
353 354
354 interface = usb_find_interface (&tower_driver, subminor); 355 interface = usb_find_interface (&tower_driver, subminor);
355 356
@@ -427,7 +428,7 @@ unlock_exit:
427 up (&dev->sem); 428 up (&dev->sem);
428 429
429unlock_disconnect_exit: 430unlock_disconnect_exit:
430 up (&disconnect_sem); 431 mutex_unlock (&disconnect_mutex);
431 432
432 dbg(2, "%s: leave, return value %d ", __FUNCTION__, retval); 433 dbg(2, "%s: leave, return value %d ", __FUNCTION__, retval);
433 434
@@ -1005,7 +1006,7 @@ static void tower_disconnect (struct usb_interface *interface)
1005 1006
1006 dbg(2, "%s: enter", __FUNCTION__); 1007 dbg(2, "%s: enter", __FUNCTION__);
1007 1008
1008 down (&disconnect_sem); 1009 mutex_lock (&disconnect_mutex);
1009 1010
1010 dev = usb_get_intfdata (interface); 1011 dev = usb_get_intfdata (interface);
1011 usb_set_intfdata (interface, NULL); 1012 usb_set_intfdata (interface, NULL);
@@ -1027,7 +1028,7 @@ static void tower_disconnect (struct usb_interface *interface)
1027 up (&dev->sem); 1028 up (&dev->sem);
1028 } 1029 }
1029 1030
1030 up (&disconnect_sem); 1031 mutex_unlock (&disconnect_mutex);
1031 1032
1032 info("LEGO USB Tower #%d now disconnected", (minor - LEGO_USB_TOWER_MINOR_BASE)); 1033 info("LEGO USB Tower #%d now disconnected", (minor - LEGO_USB_TOWER_MINOR_BASE));
1033 1034
diff --git a/drivers/usb/mon/mon_main.c b/drivers/usb/mon/mon_main.c
index c34944c75047..b03e346e33f1 100644
--- a/drivers/usb/mon/mon_main.c
+++ b/drivers/usb/mon/mon_main.c
@@ -12,6 +12,7 @@
12#include <linux/debugfs.h> 12#include <linux/debugfs.h>
13#include <linux/smp_lock.h> 13#include <linux/smp_lock.h>
14#include <linux/notifier.h> 14#include <linux/notifier.h>
15#include <linux/mutex.h>
15 16
16#include "usb_mon.h" 17#include "usb_mon.h"
17#include "../core/hcd.h" 18#include "../core/hcd.h"
@@ -23,7 +24,7 @@ static void mon_dissolve(struct mon_bus *mbus, struct usb_bus *ubus);
23static void mon_bus_drop(struct kref *r); 24static void mon_bus_drop(struct kref *r);
24static void mon_bus_init(struct dentry *mondir, struct usb_bus *ubus); 25static void mon_bus_init(struct dentry *mondir, struct usb_bus *ubus);
25 26
26DECLARE_MUTEX(mon_lock); 27DEFINE_MUTEX(mon_lock);
27 28
28static struct dentry *mon_dir; /* /dbg/usbmon */ 29static struct dentry *mon_dir; /* /dbg/usbmon */
29static LIST_HEAD(mon_buses); /* All buses we know: struct mon_bus */ 30static LIST_HEAD(mon_buses); /* All buses we know: struct mon_bus */
@@ -196,14 +197,14 @@ static void mon_bus_remove(struct usb_bus *ubus)
196{ 197{
197 struct mon_bus *mbus = ubus->mon_bus; 198 struct mon_bus *mbus = ubus->mon_bus;
198 199
199 down(&mon_lock); 200 mutex_lock(&mon_lock);
200 list_del(&mbus->bus_link); 201 list_del(&mbus->bus_link);
201 debugfs_remove(mbus->dent_t); 202 debugfs_remove(mbus->dent_t);
202 debugfs_remove(mbus->dent_s); 203 debugfs_remove(mbus->dent_s);
203 204
204 mon_dissolve(mbus, ubus); 205 mon_dissolve(mbus, ubus);
205 kref_put(&mbus->ref, mon_bus_drop); 206 kref_put(&mbus->ref, mon_bus_drop);
206 up(&mon_lock); 207 mutex_unlock(&mon_lock);
207} 208}
208 209
209static int mon_notify(struct notifier_block *self, unsigned long action, 210static int mon_notify(struct notifier_block *self, unsigned long action,
@@ -307,9 +308,9 @@ static void mon_bus_init(struct dentry *mondir, struct usb_bus *ubus)
307 goto err_create_s; 308 goto err_create_s;
308 mbus->dent_s = d; 309 mbus->dent_s = d;
309 310
310 down(&mon_lock); 311 mutex_lock(&mon_lock);
311 list_add_tail(&mbus->bus_link, &mon_buses); 312 list_add_tail(&mbus->bus_link, &mon_buses);
312 up(&mon_lock); 313 mutex_unlock(&mon_lock);
313 return; 314 return;
314 315
315err_create_s: 316err_create_s:
@@ -347,11 +348,11 @@ static int __init mon_init(void)
347 348
348 usb_register_notify(&mon_nb); 349 usb_register_notify(&mon_nb);
349 350
350 down(&usb_bus_list_lock); 351 mutex_lock(&usb_bus_list_lock);
351 list_for_each_entry (ubus, &usb_bus_list, bus_list) { 352 list_for_each_entry (ubus, &usb_bus_list, bus_list) {
352 mon_bus_init(mondir, ubus); 353 mon_bus_init(mondir, ubus);
353 } 354 }
354 up(&usb_bus_list_lock); 355 mutex_unlock(&usb_bus_list_lock);
355 return 0; 356 return 0;
356} 357}
357 358
@@ -363,7 +364,7 @@ static void __exit mon_exit(void)
363 usb_unregister_notify(&mon_nb); 364 usb_unregister_notify(&mon_nb);
364 usb_mon_deregister(); 365 usb_mon_deregister();
365 366
366 down(&mon_lock); 367 mutex_lock(&mon_lock);
367 while (!list_empty(&mon_buses)) { 368 while (!list_empty(&mon_buses)) {
368 p = mon_buses.next; 369 p = mon_buses.next;
369 mbus = list_entry(p, struct mon_bus, bus_link); 370 mbus = list_entry(p, struct mon_bus, bus_link);
@@ -387,7 +388,7 @@ static void __exit mon_exit(void)
387 mon_dissolve(mbus, mbus->u_bus); 388 mon_dissolve(mbus, mbus->u_bus);
388 kref_put(&mbus->ref, mon_bus_drop); 389 kref_put(&mbus->ref, mon_bus_drop);
389 } 390 }
390 up(&mon_lock); 391 mutex_unlock(&mon_lock);
391 392
392 debugfs_remove(mon_dir); 393 debugfs_remove(mon_dir);
393} 394}
diff --git a/drivers/usb/mon/mon_text.c b/drivers/usb/mon/mon_text.c
index 611612146ae9..59089e8b7e5e 100644
--- a/drivers/usb/mon/mon_text.c
+++ b/drivers/usb/mon/mon_text.c
@@ -8,6 +8,7 @@
8#include <linux/list.h> 8#include <linux/list.h>
9#include <linux/usb.h> 9#include <linux/usb.h>
10#include <linux/time.h> 10#include <linux/time.h>
11#include <linux/mutex.h>
11#include <asm/uaccess.h> 12#include <asm/uaccess.h>
12 13
13#include "usb_mon.h" 14#include "usb_mon.h"
@@ -54,7 +55,7 @@ struct mon_reader_text {
54 wait_queue_head_t wait; 55 wait_queue_head_t wait;
55 int printf_size; 56 int printf_size;
56 char *printf_buf; 57 char *printf_buf;
57 struct semaphore printf_lock; 58 struct mutex printf_lock;
58 59
59 char slab_name[SLAB_NAME_SZ]; 60 char slab_name[SLAB_NAME_SZ];
60}; 61};
@@ -208,7 +209,7 @@ static int mon_text_open(struct inode *inode, struct file *file)
208 struct mon_reader_text *rp; 209 struct mon_reader_text *rp;
209 int rc; 210 int rc;
210 211
211 down(&mon_lock); 212 mutex_lock(&mon_lock);
212 mbus = inode->u.generic_ip; 213 mbus = inode->u.generic_ip;
213 ubus = mbus->u_bus; 214 ubus = mbus->u_bus;
214 215
@@ -220,7 +221,7 @@ static int mon_text_open(struct inode *inode, struct file *file)
220 memset(rp, 0, sizeof(struct mon_reader_text)); 221 memset(rp, 0, sizeof(struct mon_reader_text));
221 INIT_LIST_HEAD(&rp->e_list); 222 INIT_LIST_HEAD(&rp->e_list);
222 init_waitqueue_head(&rp->wait); 223 init_waitqueue_head(&rp->wait);
223 init_MUTEX(&rp->printf_lock); 224 mutex_init(&rp->printf_lock);
224 225
225 rp->printf_size = PRINTF_DFL; 226 rp->printf_size = PRINTF_DFL;
226 rp->printf_buf = kmalloc(rp->printf_size, GFP_KERNEL); 227 rp->printf_buf = kmalloc(rp->printf_size, GFP_KERNEL);
@@ -247,7 +248,7 @@ static int mon_text_open(struct inode *inode, struct file *file)
247 mon_reader_add(mbus, &rp->r); 248 mon_reader_add(mbus, &rp->r);
248 249
249 file->private_data = rp; 250 file->private_data = rp;
250 up(&mon_lock); 251 mutex_unlock(&mon_lock);
251 return 0; 252 return 0;
252 253
253// err_busy: 254// err_busy:
@@ -257,7 +258,7 @@ err_slab:
257err_alloc_pr: 258err_alloc_pr:
258 kfree(rp); 259 kfree(rp);
259err_alloc: 260err_alloc:
260 up(&mon_lock); 261 mutex_unlock(&mon_lock);
261 return rc; 262 return rc;
262} 263}
263 264
@@ -301,7 +302,7 @@ static ssize_t mon_text_read(struct file *file, char __user *buf,
301 set_current_state(TASK_RUNNING); 302 set_current_state(TASK_RUNNING);
302 remove_wait_queue(&rp->wait, &waita); 303 remove_wait_queue(&rp->wait, &waita);
303 304
304 down(&rp->printf_lock); 305 mutex_lock(&rp->printf_lock);
305 cnt = 0; 306 cnt = 0;
306 pbuf = rp->printf_buf; 307 pbuf = rp->printf_buf;
307 limit = rp->printf_size; 308 limit = rp->printf_size;
@@ -358,7 +359,7 @@ static ssize_t mon_text_read(struct file *file, char __user *buf,
358 359
359 if (copy_to_user(buf, rp->printf_buf, cnt)) 360 if (copy_to_user(buf, rp->printf_buf, cnt))
360 cnt = -EFAULT; 361 cnt = -EFAULT;
361 up(&rp->printf_lock); 362 mutex_unlock(&rp->printf_lock);
362 kmem_cache_free(rp->e_slab, ep); 363 kmem_cache_free(rp->e_slab, ep);
363 return cnt; 364 return cnt;
364} 365}
@@ -371,12 +372,12 @@ static int mon_text_release(struct inode *inode, struct file *file)
371 struct list_head *p; 372 struct list_head *p;
372 struct mon_event_text *ep; 373 struct mon_event_text *ep;
373 374
374 down(&mon_lock); 375 mutex_lock(&mon_lock);
375 mbus = inode->u.generic_ip; 376 mbus = inode->u.generic_ip;
376 377
377 if (mbus->nreaders <= 0) { 378 if (mbus->nreaders <= 0) {
378 printk(KERN_ERR TAG ": consistency error on close\n"); 379 printk(KERN_ERR TAG ": consistency error on close\n");
379 up(&mon_lock); 380 mutex_unlock(&mon_lock);
380 return 0; 381 return 0;
381 } 382 }
382 mon_reader_del(mbus, &rp->r); 383 mon_reader_del(mbus, &rp->r);
@@ -402,7 +403,7 @@ static int mon_text_release(struct inode *inode, struct file *file)
402 kfree(rp->printf_buf); 403 kfree(rp->printf_buf);
403 kfree(rp); 404 kfree(rp);
404 405
405 up(&mon_lock); 406 mutex_unlock(&mon_lock);
406 return 0; 407 return 0;
407} 408}
408 409
diff --git a/drivers/usb/mon/usb_mon.h b/drivers/usb/mon/usb_mon.h
index 4be0f9346071..8e0613c350cc 100644
--- a/drivers/usb/mon/usb_mon.h
+++ b/drivers/usb/mon/usb_mon.h
@@ -49,7 +49,7 @@ void mon_reader_del(struct mon_bus *mbus, struct mon_reader *r);
49 */ 49 */
50extern char mon_dmapeek(unsigned char *dst, dma_addr_t dma_addr, int len); 50extern char mon_dmapeek(unsigned char *dst, dma_addr_t dma_addr, int len);
51 51
52extern struct semaphore mon_lock; 52extern struct mutex mon_lock;
53 53
54extern struct file_operations mon_fops_text; 54extern struct file_operations mon_fops_text;
55extern struct file_operations mon_fops_stat; 55extern struct file_operations mon_fops_stat;
diff --git a/drivers/usb/storage/scsiglue.c b/drivers/usb/storage/scsiglue.c
index 4ef5527028c5..5f11e19eaae3 100644
--- a/drivers/usb/storage/scsiglue.c
+++ b/drivers/usb/storage/scsiglue.c
@@ -47,6 +47,7 @@
47 47
48#include <linux/slab.h> 48#include <linux/slab.h>
49#include <linux/module.h> 49#include <linux/module.h>
50#include <linux/mutex.h>
50 51
51#include <scsi/scsi.h> 52#include <scsi/scsi.h>
52#include <scsi/scsi_cmnd.h> 53#include <scsi/scsi_cmnd.h>
@@ -271,9 +272,9 @@ static int device_reset(struct scsi_cmnd *srb)
271 US_DEBUGP("%s called\n", __FUNCTION__); 272 US_DEBUGP("%s called\n", __FUNCTION__);
272 273
273 /* lock the device pointers and do the reset */ 274 /* lock the device pointers and do the reset */
274 down(&(us->dev_semaphore)); 275 mutex_lock(&(us->dev_mutex));
275 result = us->transport_reset(us); 276 result = us->transport_reset(us);
276 up(&(us->dev_semaphore)); 277 mutex_unlock(&us->dev_mutex);
277 278
278 return result < 0 ? FAILED : SUCCESS; 279 return result < 0 ? FAILED : SUCCESS;
279} 280}
@@ -286,9 +287,9 @@ static int bus_reset(struct scsi_cmnd *srb)
286 287
287 US_DEBUGP("%s called\n", __FUNCTION__); 288 US_DEBUGP("%s called\n", __FUNCTION__);
288 289
289 down(&(us->dev_semaphore)); 290 mutex_lock(&(us->dev_mutex));
290 result = usb_stor_port_reset(us); 291 result = usb_stor_port_reset(us);
291 up(&(us->dev_semaphore)); 292 mutex_unlock(&us->dev_mutex);
292 293
293 return result < 0 ? FAILED : SUCCESS; 294 return result < 0 ? FAILED : SUCCESS;
294} 295}
diff --git a/drivers/usb/storage/usb.c b/drivers/usb/storage/usb.c
index dbcf23980ff1..dd108634348e 100644
--- a/drivers/usb/storage/usb.c
+++ b/drivers/usb/storage/usb.c
@@ -55,6 +55,7 @@
55#include <linux/init.h> 55#include <linux/init.h>
56#include <linux/slab.h> 56#include <linux/slab.h>
57#include <linux/kthread.h> 57#include <linux/kthread.h>
58#include <linux/mutex.h>
58 59
59#include <scsi/scsi.h> 60#include <scsi/scsi.h>
60#include <scsi/scsi_cmnd.h> 61#include <scsi/scsi_cmnd.h>
@@ -188,7 +189,7 @@ static int storage_suspend(struct usb_interface *iface, pm_message_t message)
188 struct us_data *us = usb_get_intfdata(iface); 189 struct us_data *us = usb_get_intfdata(iface);
189 190
190 /* Wait until no command is running */ 191 /* Wait until no command is running */
191 down(&us->dev_semaphore); 192 mutex_lock(&us->dev_mutex);
192 193
193 US_DEBUGP("%s\n", __FUNCTION__); 194 US_DEBUGP("%s\n", __FUNCTION__);
194 if (us->suspend_resume_hook) 195 if (us->suspend_resume_hook)
@@ -198,7 +199,7 @@ static int storage_suspend(struct usb_interface *iface, pm_message_t message)
198 /* When runtime PM is working, we'll set a flag to indicate 199 /* When runtime PM is working, we'll set a flag to indicate
199 * whether we should autoresume when a SCSI request arrives. */ 200 * whether we should autoresume when a SCSI request arrives. */
200 201
201 up(&us->dev_semaphore); 202 mutex_unlock(&us->dev_mutex);
202 return 0; 203 return 0;
203} 204}
204 205
@@ -206,14 +207,14 @@ static int storage_resume(struct usb_interface *iface)
206{ 207{
207 struct us_data *us = usb_get_intfdata(iface); 208 struct us_data *us = usb_get_intfdata(iface);
208 209
209 down(&us->dev_semaphore); 210 mutex_lock(&us->dev_mutex);
210 211
211 US_DEBUGP("%s\n", __FUNCTION__); 212 US_DEBUGP("%s\n", __FUNCTION__);
212 if (us->suspend_resume_hook) 213 if (us->suspend_resume_hook)
213 (us->suspend_resume_hook)(us, US_RESUME); 214 (us->suspend_resume_hook)(us, US_RESUME);
214 iface->dev.power.power_state.event = PM_EVENT_ON; 215 iface->dev.power.power_state.event = PM_EVENT_ON;
215 216
216 up(&us->dev_semaphore); 217 mutex_unlock(&us->dev_mutex);
217 return 0; 218 return 0;
218} 219}
219 220
@@ -276,12 +277,12 @@ static int usb_stor_control_thread(void * __us)
276 US_DEBUGP("*** thread awakened.\n"); 277 US_DEBUGP("*** thread awakened.\n");
277 278
278 /* lock the device pointers */ 279 /* lock the device pointers */
279 down(&(us->dev_semaphore)); 280 mutex_lock(&(us->dev_mutex));
280 281
281 /* if the device has disconnected, we are free to exit */ 282 /* if the device has disconnected, we are free to exit */
282 if (test_bit(US_FLIDX_DISCONNECTING, &us->flags)) { 283 if (test_bit(US_FLIDX_DISCONNECTING, &us->flags)) {
283 US_DEBUGP("-- exiting\n"); 284 US_DEBUGP("-- exiting\n");
284 up(&(us->dev_semaphore)); 285 mutex_unlock(&us->dev_mutex);
285 break; 286 break;
286 } 287 }
287 288
@@ -370,7 +371,7 @@ SkipForAbort:
370 scsi_unlock(host); 371 scsi_unlock(host);
371 372
372 /* unlock the device pointers */ 373 /* unlock the device pointers */
373 up(&(us->dev_semaphore)); 374 mutex_unlock(&us->dev_mutex);
374 } /* for (;;) */ 375 } /* for (;;) */
375 376
376 scsi_host_put(host); 377 scsi_host_put(host);
@@ -815,8 +816,8 @@ static void quiesce_and_remove_host(struct us_data *us)
815 * The thread will exit when it sees the DISCONNECTING flag. */ 816 * The thread will exit when it sees the DISCONNECTING flag. */
816 817
817 /* Wait for the current command to finish, then remove the host */ 818 /* Wait for the current command to finish, then remove the host */
818 down(&us->dev_semaphore); 819 mutex_lock(&us->dev_mutex);
819 up(&us->dev_semaphore); 820 mutex_unlock(&us->dev_mutex);
820 821
821 /* queuecommand won't accept any new commands and the control 822 /* queuecommand won't accept any new commands and the control
822 * thread won't execute a previously-queued command. If there 823 * thread won't execute a previously-queued command. If there
@@ -870,9 +871,9 @@ retry:
870 /* For bulk-only devices, determine the max LUN value */ 871 /* For bulk-only devices, determine the max LUN value */
871 if (us->protocol == US_PR_BULK && 872 if (us->protocol == US_PR_BULK &&
872 !(us->flags & US_FL_SINGLE_LUN)) { 873 !(us->flags & US_FL_SINGLE_LUN)) {
873 down(&us->dev_semaphore); 874 mutex_lock(&us->dev_mutex);
874 us->max_lun = usb_stor_Bulk_max_lun(us); 875 us->max_lun = usb_stor_Bulk_max_lun(us);
875 up(&us->dev_semaphore); 876 mutex_unlock(&us->dev_mutex);
876 } 877 }
877 scsi_scan_host(us_to_host(us)); 878 scsi_scan_host(us_to_host(us));
878 printk(KERN_DEBUG "usb-storage: device scan complete\n"); 879 printk(KERN_DEBUG "usb-storage: device scan complete\n");
@@ -912,7 +913,7 @@ static int storage_probe(struct usb_interface *intf,
912 913
913 us = host_to_us(host); 914 us = host_to_us(host);
914 memset(us, 0, sizeof(struct us_data)); 915 memset(us, 0, sizeof(struct us_data));
915 init_MUTEX(&(us->dev_semaphore)); 916 mutex_init(&(us->dev_mutex));
916 init_MUTEX_LOCKED(&(us->sema)); 917 init_MUTEX_LOCKED(&(us->sema));
917 init_completion(&(us->notify)); 918 init_completion(&(us->notify));
918 init_waitqueue_head(&us->delay_wait); 919 init_waitqueue_head(&us->delay_wait);
diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
index 7259fd1f6b0d..009fb0953a56 100644
--- a/drivers/usb/storage/usb.h
+++ b/drivers/usb/storage/usb.h
@@ -49,6 +49,7 @@
49#include <linux/blkdev.h> 49#include <linux/blkdev.h>
50#include <linux/smp_lock.h> 50#include <linux/smp_lock.h>
51#include <linux/completion.h> 51#include <linux/completion.h>
52#include <linux/mutex.h>
52#include <scsi/scsi_host.h> 53#include <scsi/scsi_host.h>
53 54
54struct us_data; 55struct us_data;
@@ -103,9 +104,9 @@ typedef void (*pm_hook)(struct us_data *, int); /* power management hook */
103struct us_data { 104struct us_data {
104 /* The device we're working with 105 /* The device we're working with
105 * It's important to note: 106 * It's important to note:
106 * (o) you must hold dev_semaphore to change pusb_dev 107 * (o) you must hold dev_mutex to change pusb_dev
107 */ 108 */
108 struct semaphore dev_semaphore; /* protect pusb_dev */ 109 struct mutex dev_mutex; /* protect pusb_dev */
109 struct usb_device *pusb_dev; /* this usb_device */ 110 struct usb_device *pusb_dev; /* this usb_device */
110 struct usb_interface *pusb_intf; /* this interface */ 111 struct usb_interface *pusb_intf; /* this interface */
111 struct us_unusual_dev *unusual_dev; /* device-filter entry */ 112 struct us_unusual_dev *unusual_dev; /* device-filter entry */