diff options
author | Arjan van de Ven <arjan@infradead.org> | 2006-01-11 09:55:29 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2006-03-20 17:49:55 -0500 |
commit | 4186ecf8ad16dd05759a09594de6a87e48759ba6 (patch) | |
tree | 3ee5292d9f4a36e3eb359b586289ec972bcbaf39 /drivers/usb/core | |
parent | 35cce732d9d4d9af6b4ad4d26d8f8c0eddb573a2 (diff) |
[PATCH] USB: convert a bunch of USB semaphores to mutexes
the patch below converts a bunch of semaphores-used-as-mutex in the USB
code to mutexes
Signed-off-by: Arjan van de Ven <arjan@infradead.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb/core')
-rw-r--r-- | drivers/usb/core/devices.c | 7 | ||||
-rw-r--r-- | drivers/usb/core/hcd.c | 25 | ||||
-rw-r--r-- | drivers/usb/core/hcd.h | 2 | ||||
-rw-r--r-- | drivers/usb/core/hub.c | 7 | ||||
-rw-r--r-- | drivers/usb/core/notify.c | 15 | ||||
-rw-r--r-- | drivers/usb/core/usb.c | 5 |
6 files changed, 33 insertions, 28 deletions
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 { | |||
93 | static struct usb_busmap busmap; | 94 | static struct usb_busmap busmap; |
94 | 95 | ||
95 | /* used when updating list of hcds */ | 96 | /* used when updating list of hcds */ |
96 | DECLARE_MUTEX (usb_bus_list_lock); /* exported only for usbfs */ | 97 | DEFINE_MUTEX(usb_bus_list_lock); /* exported only for usbfs */ |
97 | EXPORT_SYMBOL_GPL (usb_bus_list_lock); | 98 | EXPORT_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 | ||
366 | extern struct list_head usb_bus_list; | 366 | extern struct list_head usb_bus_list; |
367 | extern struct semaphore usb_bus_list_lock; | 367 | extern struct mutex usb_bus_list_lock; |
368 | extern wait_queue_head_t usb_kill_urb_queue; | 368 | extern wait_queue_head_t usb_kill_urb_queue; |
369 | 369 | ||
370 | extern struct usb_bus *usb_bus_get (struct usb_bus *bus); | 370 | extern 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 | |||
2162 | hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1, | 2163 | hub_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, | |||
2381 | fail: | 2382 | fail: |
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 | ||
19 | static struct notifier_block *usb_notifier_list; | 20 | static struct notifier_block *usb_notifier_list; |
20 | static DECLARE_MUTEX(usb_notifier_lock); | 21 | static DEFINE_MUTEX(usb_notifier_lock); |
21 | 22 | ||
22 | static void usb_notifier_chain_register(struct notifier_block **list, | 23 | static 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 | ||
36 | static void usb_notifier_chain_unregister(struct notifier_block **nl, | 37 | static 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 | } |
47 | exit: | 48 | exit: |
48 | up(&usb_notifier_lock); | 49 | mutex_unlock(&usb_notifier_lock); |
49 | } | 50 | } |
50 | 51 | ||
51 | static int usb_notifier_call_chain(struct notifier_block **n, | 52 | static 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 | } |
65 | exit: | 66 | exit: |
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 | } |
655 | exit: | 656 | exit: |
656 | up(&usb_bus_list_lock); | 657 | mutex_unlock(&usb_bus_list_lock); |
657 | return dev; | 658 | return dev; |
658 | } | 659 | } |
659 | 660 | ||