diff options
author | Daniel Walker <dwalker@mvista.com> | 2008-02-05 02:57:42 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2008-04-25 00:16:33 -0400 |
commit | 75c43b6ec6eb114e875e43fb151987c1a558e4f4 (patch) | |
tree | ddaf1f977cb79e7668c7f759acf8e786241d1f5d /drivers/usb/storage/libusual.c | |
parent | d99388aa0a504f69532db353a976ec133361bb4f (diff) |
USB: libusual: locking cleanup
I converted the usu_init_notify semaphore to normal mutex usage, and it
should still prevent the request_module before the init routine is
complete. Before it acted more like a complete, now the mutex protects two
distinct section from running at the same time.
Signed-off-by: Daniel Walker <dwalker@mvista.com>
Cc: Pete Zaitcev <zaitcev@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb/storage/libusual.c')
-rw-r--r-- | drivers/usb/storage/libusual.c | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/drivers/usb/storage/libusual.c b/drivers/usb/storage/libusual.c index 55b952084f0c..a28d49122e7a 100644 --- a/drivers/usb/storage/libusual.c +++ b/drivers/usb/storage/libusual.c | |||
@@ -9,6 +9,7 @@ | |||
9 | #include <linux/usb_usual.h> | 9 | #include <linux/usb_usual.h> |
10 | #include <linux/vmalloc.h> | 10 | #include <linux/vmalloc.h> |
11 | #include <linux/kthread.h> | 11 | #include <linux/kthread.h> |
12 | #include <linux/mutex.h> | ||
12 | 13 | ||
13 | /* | 14 | /* |
14 | */ | 15 | */ |
@@ -30,7 +31,7 @@ static atomic_t usu_bias = ATOMIC_INIT(USB_US_DEFAULT_BIAS); | |||
30 | #define BIAS_NAME_SIZE (sizeof("usb-storage")) | 31 | #define BIAS_NAME_SIZE (sizeof("usb-storage")) |
31 | static const char *bias_names[3] = { "none", "usb-storage", "ub" }; | 32 | static const char *bias_names[3] = { "none", "usb-storage", "ub" }; |
32 | 33 | ||
33 | static struct semaphore usu_init_notify; | 34 | static DEFINE_MUTEX(usu_probe_mutex); |
34 | static DECLARE_COMPLETION(usu_end_notify); | 35 | static DECLARE_COMPLETION(usu_end_notify); |
35 | static atomic_t total_threads = ATOMIC_INIT(0); | 36 | static atomic_t total_threads = ATOMIC_INIT(0); |
36 | 37 | ||
@@ -178,10 +179,7 @@ static int usu_probe_thread(void *arg) | |||
178 | int rc; | 179 | int rc; |
179 | unsigned long flags; | 180 | unsigned long flags; |
180 | 181 | ||
181 | /* A completion does not work here because it's counted. */ | 182 | mutex_lock(&usu_probe_mutex); |
182 | down(&usu_init_notify); | ||
183 | up(&usu_init_notify); | ||
184 | |||
185 | rc = request_module(bias_names[type]); | 183 | rc = request_module(bias_names[type]); |
186 | spin_lock_irqsave(&usu_lock, flags); | 184 | spin_lock_irqsave(&usu_lock, flags); |
187 | if (rc == 0 && (st->fls & USU_MOD_FL_PRESENT) == 0) { | 185 | if (rc == 0 && (st->fls & USU_MOD_FL_PRESENT) == 0) { |
@@ -194,6 +192,7 @@ static int usu_probe_thread(void *arg) | |||
194 | } | 192 | } |
195 | st->fls &= ~USU_MOD_FL_THREAD; | 193 | st->fls &= ~USU_MOD_FL_THREAD; |
196 | spin_unlock_irqrestore(&usu_lock, flags); | 194 | spin_unlock_irqrestore(&usu_lock, flags); |
195 | mutex_unlock(&usu_probe_mutex); | ||
197 | 196 | ||
198 | complete_and_exit(&usu_end_notify, 0); | 197 | complete_and_exit(&usu_end_notify, 0); |
199 | } | 198 | } |
@@ -204,10 +203,9 @@ static int __init usb_usual_init(void) | |||
204 | { | 203 | { |
205 | int rc; | 204 | int rc; |
206 | 205 | ||
207 | sema_init(&usu_init_notify, 0); | 206 | mutex_lock(&usu_probe_mutex); |
208 | |||
209 | rc = usb_register(&usu_driver); | 207 | rc = usb_register(&usu_driver); |
210 | up(&usu_init_notify); | 208 | mutex_unlock(&usu_probe_mutex); |
211 | return rc; | 209 | return rc; |
212 | } | 210 | } |
213 | 211 | ||