diff options
Diffstat (limited to 'sound/core/seq/seq_device.c')
-rw-r--r-- | sound/core/seq/seq_device.c | 53 |
1 files changed, 27 insertions, 26 deletions
diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c index 9ece443fba55..d9a3e5a18d6a 100644 --- a/sound/core/seq/seq_device.c +++ b/sound/core/seq/seq_device.c | |||
@@ -45,6 +45,7 @@ | |||
45 | #include <sound/initval.h> | 45 | #include <sound/initval.h> |
46 | #include <linux/kmod.h> | 46 | #include <linux/kmod.h> |
47 | #include <linux/slab.h> | 47 | #include <linux/slab.h> |
48 | #include <linux/mutex.h> | ||
48 | 49 | ||
49 | MODULE_AUTHOR("Takashi Iwai <tiwai@suse.de>"); | 50 | MODULE_AUTHOR("Takashi Iwai <tiwai@suse.de>"); |
50 | MODULE_DESCRIPTION("ALSA sequencer device management"); | 51 | MODULE_DESCRIPTION("ALSA sequencer device management"); |
@@ -69,7 +70,7 @@ struct ops_list { | |||
69 | struct list_head dev_list; /* list of devices */ | 70 | struct list_head dev_list; /* list of devices */ |
70 | int num_devices; /* number of associated devices */ | 71 | int num_devices; /* number of associated devices */ |
71 | int num_init_devices; /* number of initialized devices */ | 72 | int num_init_devices; /* number of initialized devices */ |
72 | struct semaphore reg_mutex; | 73 | struct mutex reg_mutex; |
73 | 74 | ||
74 | struct list_head list; /* next driver */ | 75 | struct list_head list; /* next driver */ |
75 | }; | 76 | }; |
@@ -77,7 +78,7 @@ struct ops_list { | |||
77 | 78 | ||
78 | static LIST_HEAD(opslist); | 79 | static LIST_HEAD(opslist); |
79 | static int num_ops; | 80 | static int num_ops; |
80 | static DECLARE_MUTEX(ops_mutex); | 81 | static DEFINE_MUTEX(ops_mutex); |
81 | #ifdef CONFIG_PROC_FS | 82 | #ifdef CONFIG_PROC_FS |
82 | static struct snd_info_entry *info_entry = NULL; | 83 | static struct snd_info_entry *info_entry = NULL; |
83 | #endif | 84 | #endif |
@@ -108,7 +109,7 @@ static void snd_seq_device_info(struct snd_info_entry *entry, | |||
108 | { | 109 | { |
109 | struct list_head *head; | 110 | struct list_head *head; |
110 | 111 | ||
111 | down(&ops_mutex); | 112 | mutex_lock(&ops_mutex); |
112 | list_for_each(head, &opslist) { | 113 | list_for_each(head, &opslist) { |
113 | struct ops_list *ops = list_entry(head, struct ops_list, list); | 114 | struct ops_list *ops = list_entry(head, struct ops_list, list); |
114 | snd_iprintf(buffer, "snd-%s%s%s%s,%d\n", | 115 | snd_iprintf(buffer, "snd-%s%s%s%s,%d\n", |
@@ -118,7 +119,7 @@ static void snd_seq_device_info(struct snd_info_entry *entry, | |||
118 | ops->driver & DRIVER_LOCKED ? ",locked" : "", | 119 | ops->driver & DRIVER_LOCKED ? ",locked" : "", |
119 | ops->num_devices); | 120 | ops->num_devices); |
120 | } | 121 | } |
121 | up(&ops_mutex); | 122 | mutex_unlock(&ops_mutex); |
122 | } | 123 | } |
123 | #endif | 124 | #endif |
124 | 125 | ||
@@ -154,20 +155,20 @@ void snd_seq_device_load_drivers(void) | |||
154 | if (! current->fs->root) | 155 | if (! current->fs->root) |
155 | return; | 156 | return; |
156 | 157 | ||
157 | down(&ops_mutex); | 158 | mutex_lock(&ops_mutex); |
158 | list_for_each(head, &opslist) { | 159 | list_for_each(head, &opslist) { |
159 | struct ops_list *ops = list_entry(head, struct ops_list, list); | 160 | struct ops_list *ops = list_entry(head, struct ops_list, list); |
160 | if (! (ops->driver & DRIVER_LOADED) && | 161 | if (! (ops->driver & DRIVER_LOADED) && |
161 | ! (ops->driver & DRIVER_REQUESTED)) { | 162 | ! (ops->driver & DRIVER_REQUESTED)) { |
162 | ops->used++; | 163 | ops->used++; |
163 | up(&ops_mutex); | 164 | mutex_unlock(&ops_mutex); |
164 | ops->driver |= DRIVER_REQUESTED; | 165 | ops->driver |= DRIVER_REQUESTED; |
165 | request_module("snd-%s", ops->id); | 166 | request_module("snd-%s", ops->id); |
166 | down(&ops_mutex); | 167 | mutex_lock(&ops_mutex); |
167 | ops->used--; | 168 | ops->used--; |
168 | } | 169 | } |
169 | } | 170 | } |
170 | up(&ops_mutex); | 171 | mutex_unlock(&ops_mutex); |
171 | #endif | 172 | #endif |
172 | } | 173 | } |
173 | 174 | ||
@@ -214,10 +215,10 @@ int snd_seq_device_new(struct snd_card *card, int device, char *id, int argsize, | |||
214 | dev->status = SNDRV_SEQ_DEVICE_FREE; | 215 | dev->status = SNDRV_SEQ_DEVICE_FREE; |
215 | 216 | ||
216 | /* add this device to the list */ | 217 | /* add this device to the list */ |
217 | down(&ops->reg_mutex); | 218 | mutex_lock(&ops->reg_mutex); |
218 | list_add_tail(&dev->list, &ops->dev_list); | 219 | list_add_tail(&dev->list, &ops->dev_list); |
219 | ops->num_devices++; | 220 | ops->num_devices++; |
220 | up(&ops->reg_mutex); | 221 | mutex_unlock(&ops->reg_mutex); |
221 | 222 | ||
222 | unlock_driver(ops); | 223 | unlock_driver(ops); |
223 | 224 | ||
@@ -246,10 +247,10 @@ static int snd_seq_device_free(struct snd_seq_device *dev) | |||
246 | return -ENXIO; | 247 | return -ENXIO; |
247 | 248 | ||
248 | /* remove the device from the list */ | 249 | /* remove the device from the list */ |
249 | down(&ops->reg_mutex); | 250 | mutex_lock(&ops->reg_mutex); |
250 | list_del(&dev->list); | 251 | list_del(&dev->list); |
251 | ops->num_devices--; | 252 | ops->num_devices--; |
252 | up(&ops->reg_mutex); | 253 | mutex_unlock(&ops->reg_mutex); |
253 | 254 | ||
254 | free_device(dev, ops); | 255 | free_device(dev, ops); |
255 | if (dev->private_free) | 256 | if (dev->private_free) |
@@ -344,7 +345,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry, | |||
344 | return -EBUSY; | 345 | return -EBUSY; |
345 | } | 346 | } |
346 | 347 | ||
347 | down(&ops->reg_mutex); | 348 | mutex_lock(&ops->reg_mutex); |
348 | /* copy driver operators */ | 349 | /* copy driver operators */ |
349 | ops->ops = *entry; | 350 | ops->ops = *entry; |
350 | ops->driver |= DRIVER_LOADED; | 351 | ops->driver |= DRIVER_LOADED; |
@@ -355,7 +356,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry, | |||
355 | struct snd_seq_device *dev = list_entry(head, struct snd_seq_device, list); | 356 | struct snd_seq_device *dev = list_entry(head, struct snd_seq_device, list); |
356 | init_device(dev, ops); | 357 | init_device(dev, ops); |
357 | } | 358 | } |
358 | up(&ops->reg_mutex); | 359 | mutex_unlock(&ops->reg_mutex); |
359 | 360 | ||
360 | unlock_driver(ops); | 361 | unlock_driver(ops); |
361 | snd_seq_autoload_unlock(); | 362 | snd_seq_autoload_unlock(); |
@@ -378,17 +379,17 @@ static struct ops_list * create_driver(char *id) | |||
378 | 379 | ||
379 | /* set up driver entry */ | 380 | /* set up driver entry */ |
380 | strlcpy(ops->id, id, sizeof(ops->id)); | 381 | strlcpy(ops->id, id, sizeof(ops->id)); |
381 | init_MUTEX(&ops->reg_mutex); | 382 | mutex_init(&ops->reg_mutex); |
382 | ops->driver = DRIVER_EMPTY; | 383 | ops->driver = DRIVER_EMPTY; |
383 | INIT_LIST_HEAD(&ops->dev_list); | 384 | INIT_LIST_HEAD(&ops->dev_list); |
384 | /* lock this instance */ | 385 | /* lock this instance */ |
385 | ops->used = 1; | 386 | ops->used = 1; |
386 | 387 | ||
387 | /* register driver entry */ | 388 | /* register driver entry */ |
388 | down(&ops_mutex); | 389 | mutex_lock(&ops_mutex); |
389 | list_add_tail(&ops->list, &opslist); | 390 | list_add_tail(&ops->list, &opslist); |
390 | num_ops++; | 391 | num_ops++; |
391 | up(&ops_mutex); | 392 | mutex_unlock(&ops_mutex); |
392 | 393 | ||
393 | return ops; | 394 | return ops; |
394 | } | 395 | } |
@@ -414,7 +415,7 @@ int snd_seq_device_unregister_driver(char *id) | |||
414 | } | 415 | } |
415 | 416 | ||
416 | /* close and release all devices associated with this driver */ | 417 | /* close and release all devices associated with this driver */ |
417 | down(&ops->reg_mutex); | 418 | mutex_lock(&ops->reg_mutex); |
418 | ops->driver |= DRIVER_LOCKED; /* do not remove this driver recursively */ | 419 | ops->driver |= DRIVER_LOCKED; /* do not remove this driver recursively */ |
419 | list_for_each(head, &ops->dev_list) { | 420 | list_for_each(head, &ops->dev_list) { |
420 | struct snd_seq_device *dev = list_entry(head, struct snd_seq_device, list); | 421 | struct snd_seq_device *dev = list_entry(head, struct snd_seq_device, list); |
@@ -425,7 +426,7 @@ int snd_seq_device_unregister_driver(char *id) | |||
425 | if (ops->num_init_devices > 0) | 426 | if (ops->num_init_devices > 0) |
426 | snd_printk(KERN_ERR "free_driver: init_devices > 0!! (%d)\n", | 427 | snd_printk(KERN_ERR "free_driver: init_devices > 0!! (%d)\n", |
427 | ops->num_init_devices); | 428 | ops->num_init_devices); |
428 | up(&ops->reg_mutex); | 429 | mutex_unlock(&ops->reg_mutex); |
429 | 430 | ||
430 | unlock_driver(ops); | 431 | unlock_driver(ops); |
431 | 432 | ||
@@ -443,7 +444,7 @@ static void remove_drivers(void) | |||
443 | { | 444 | { |
444 | struct list_head *head; | 445 | struct list_head *head; |
445 | 446 | ||
446 | down(&ops_mutex); | 447 | mutex_lock(&ops_mutex); |
447 | head = opslist.next; | 448 | head = opslist.next; |
448 | while (head != &opslist) { | 449 | while (head != &opslist) { |
449 | struct ops_list *ops = list_entry(head, struct ops_list, list); | 450 | struct ops_list *ops = list_entry(head, struct ops_list, list); |
@@ -456,7 +457,7 @@ static void remove_drivers(void) | |||
456 | } else | 457 | } else |
457 | head = head->next; | 458 | head = head->next; |
458 | } | 459 | } |
459 | up(&ops_mutex); | 460 | mutex_unlock(&ops_mutex); |
460 | } | 461 | } |
461 | 462 | ||
462 | /* | 463 | /* |
@@ -519,16 +520,16 @@ static struct ops_list * find_driver(char *id, int create_if_empty) | |||
519 | { | 520 | { |
520 | struct list_head *head; | 521 | struct list_head *head; |
521 | 522 | ||
522 | down(&ops_mutex); | 523 | mutex_lock(&ops_mutex); |
523 | list_for_each(head, &opslist) { | 524 | list_for_each(head, &opslist) { |
524 | struct ops_list *ops = list_entry(head, struct ops_list, list); | 525 | struct ops_list *ops = list_entry(head, struct ops_list, list); |
525 | if (strcmp(ops->id, id) == 0) { | 526 | if (strcmp(ops->id, id) == 0) { |
526 | ops->used++; | 527 | ops->used++; |
527 | up(&ops_mutex); | 528 | mutex_unlock(&ops_mutex); |
528 | return ops; | 529 | return ops; |
529 | } | 530 | } |
530 | } | 531 | } |
531 | up(&ops_mutex); | 532 | mutex_unlock(&ops_mutex); |
532 | if (create_if_empty) | 533 | if (create_if_empty) |
533 | return create_driver(id); | 534 | return create_driver(id); |
534 | return NULL; | 535 | return NULL; |
@@ -536,9 +537,9 @@ static struct ops_list * find_driver(char *id, int create_if_empty) | |||
536 | 537 | ||
537 | static void unlock_driver(struct ops_list *ops) | 538 | static void unlock_driver(struct ops_list *ops) |
538 | { | 539 | { |
539 | down(&ops_mutex); | 540 | mutex_lock(&ops_mutex); |
540 | ops->used--; | 541 | ops->used--; |
541 | up(&ops_mutex); | 542 | mutex_unlock(&ops_mutex); |
542 | } | 543 | } |
543 | 544 | ||
544 | 545 | ||