diff options
Diffstat (limited to 'drivers/usb')
-rw-r--r-- | drivers/usb/core/notify.c | 65 |
1 files changed, 8 insertions, 57 deletions
diff --git a/drivers/usb/core/notify.c b/drivers/usb/core/notify.c index 4b55285de9a0..fe0ed54fa0ae 100644 --- a/drivers/usb/core/notify.c +++ b/drivers/usb/core/notify.c | |||
@@ -16,57 +16,7 @@ | |||
16 | #include <linux/mutex.h> | 16 | #include <linux/mutex.h> |
17 | #include "usb.h" | 17 | #include "usb.h" |
18 | 18 | ||
19 | 19 | static BLOCKING_NOTIFIER_HEAD(usb_notifier_list); | |
20 | static struct notifier_block *usb_notifier_list; | ||
21 | static DEFINE_MUTEX(usb_notifier_lock); | ||
22 | |||
23 | static void usb_notifier_chain_register(struct notifier_block **list, | ||
24 | struct notifier_block *n) | ||
25 | { | ||
26 | mutex_lock(&usb_notifier_lock); | ||
27 | while (*list) { | ||
28 | if (n->priority > (*list)->priority) | ||
29 | break; | ||
30 | list = &((*list)->next); | ||
31 | } | ||
32 | n->next = *list; | ||
33 | *list = n; | ||
34 | mutex_unlock(&usb_notifier_lock); | ||
35 | } | ||
36 | |||
37 | static void usb_notifier_chain_unregister(struct notifier_block **nl, | ||
38 | struct notifier_block *n) | ||
39 | { | ||
40 | mutex_lock(&usb_notifier_lock); | ||
41 | while ((*nl)!=NULL) { | ||
42 | if ((*nl)==n) { | ||
43 | *nl = n->next; | ||
44 | goto exit; | ||
45 | } | ||
46 | nl=&((*nl)->next); | ||
47 | } | ||
48 | exit: | ||
49 | mutex_unlock(&usb_notifier_lock); | ||
50 | } | ||
51 | |||
52 | static int usb_notifier_call_chain(struct notifier_block **n, | ||
53 | unsigned long val, void *v) | ||
54 | { | ||
55 | int ret=NOTIFY_DONE; | ||
56 | struct notifier_block *nb = *n; | ||
57 | |||
58 | mutex_lock(&usb_notifier_lock); | ||
59 | while (nb) { | ||
60 | ret = nb->notifier_call(nb,val,v); | ||
61 | if (ret&NOTIFY_STOP_MASK) { | ||
62 | goto exit; | ||
63 | } | ||
64 | nb = nb->next; | ||
65 | } | ||
66 | exit: | ||
67 | mutex_unlock(&usb_notifier_lock); | ||
68 | return ret; | ||
69 | } | ||
70 | 20 | ||
71 | /** | 21 | /** |
72 | * usb_register_notify - register a notifier callback whenever a usb change happens | 22 | * usb_register_notify - register a notifier callback whenever a usb change happens |
@@ -76,7 +26,7 @@ exit: | |||
76 | */ | 26 | */ |
77 | void usb_register_notify(struct notifier_block *nb) | 27 | void usb_register_notify(struct notifier_block *nb) |
78 | { | 28 | { |
79 | usb_notifier_chain_register(&usb_notifier_list, nb); | 29 | blocking_notifier_chain_register(&usb_notifier_list, nb); |
80 | } | 30 | } |
81 | EXPORT_SYMBOL_GPL(usb_register_notify); | 31 | EXPORT_SYMBOL_GPL(usb_register_notify); |
82 | 32 | ||
@@ -89,27 +39,28 @@ EXPORT_SYMBOL_GPL(usb_register_notify); | |||
89 | */ | 39 | */ |
90 | void usb_unregister_notify(struct notifier_block *nb) | 40 | void usb_unregister_notify(struct notifier_block *nb) |
91 | { | 41 | { |
92 | usb_notifier_chain_unregister(&usb_notifier_list, nb); | 42 | blocking_notifier_chain_unregister(&usb_notifier_list, nb); |
93 | } | 43 | } |
94 | EXPORT_SYMBOL_GPL(usb_unregister_notify); | 44 | EXPORT_SYMBOL_GPL(usb_unregister_notify); |
95 | 45 | ||
96 | 46 | ||
97 | void usb_notify_add_device(struct usb_device *udev) | 47 | void usb_notify_add_device(struct usb_device *udev) |
98 | { | 48 | { |
99 | usb_notifier_call_chain(&usb_notifier_list, USB_DEVICE_ADD, udev); | 49 | blocking_notifier_call_chain(&usb_notifier_list, USB_DEVICE_ADD, udev); |
100 | } | 50 | } |
101 | 51 | ||
102 | void usb_notify_remove_device(struct usb_device *udev) | 52 | void usb_notify_remove_device(struct usb_device *udev) |
103 | { | 53 | { |
104 | usb_notifier_call_chain(&usb_notifier_list, USB_DEVICE_REMOVE, udev); | 54 | blocking_notifier_call_chain(&usb_notifier_list, |
55 | USB_DEVICE_REMOVE, udev); | ||
105 | } | 56 | } |
106 | 57 | ||
107 | void usb_notify_add_bus(struct usb_bus *ubus) | 58 | void usb_notify_add_bus(struct usb_bus *ubus) |
108 | { | 59 | { |
109 | usb_notifier_call_chain(&usb_notifier_list, USB_BUS_ADD, ubus); | 60 | blocking_notifier_call_chain(&usb_notifier_list, USB_BUS_ADD, ubus); |
110 | } | 61 | } |
111 | 62 | ||
112 | void usb_notify_remove_bus(struct usb_bus *ubus) | 63 | void usb_notify_remove_bus(struct usb_bus *ubus) |
113 | { | 64 | { |
114 | usb_notifier_call_chain(&usb_notifier_list, USB_BUS_REMOVE, ubus); | 65 | blocking_notifier_call_chain(&usb_notifier_list, USB_BUS_REMOVE, ubus); |
115 | } | 66 | } |