aboutsummaryrefslogtreecommitdiffstats
path: root/sound/core
diff options
context:
space:
mode:
authorJaroslav Kysela <perex@perex.cz>2009-06-03 18:12:18 -0400
committerTakashi Iwai <tiwai@suse.de>2009-06-03 19:22:07 -0400
commit5fdc18d938c99399b73fe894bc24cb9400a1a2ee (patch)
tree1fb20990d3d6e784f4394d762e87f6322ca1cd72 /sound/core
parent872c78202c58d26596e25743791ee81a7d24abad (diff)
ALSA: Core - clean up snd_card_set_id* calls and remove possible id collision
Move locking outside snd_card_set_id_internal() function and rename it to snd_card_set_id_no_lock() for better function description. User defined id is just copied to card structure at allocation time. The real unique id procedure is called in snd_card_register() to ensure real atomicity. Signed-off-by: Jaroslav Kysela <perex@perex.cz> Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound/core')
-rw-r--r--sound/core/init.c26
1 files changed, 10 insertions, 16 deletions
diff --git a/sound/core/init.c b/sound/core/init.c
index a578d05f9e13..d5d40d78c409 100644
--- a/sound/core/init.c
+++ b/sound/core/init.c
@@ -153,7 +153,7 @@ int snd_card_create(int idx, const char *xid,
153 if (!card) 153 if (!card)
154 return -ENOMEM; 154 return -ENOMEM;
155 if (xid) 155 if (xid)
156 snd_card_set_id(card, xid); 156 strlcpy(card->id, xid, sizeof(card->id));
157 err = 0; 157 err = 0;
158 mutex_lock(&snd_card_mutex); 158 mutex_lock(&snd_card_mutex);
159 if (idx < 0) { 159 if (idx < 0) {
@@ -476,16 +476,12 @@ int snd_card_free(struct snd_card *card)
476 476
477EXPORT_SYMBOL(snd_card_free); 477EXPORT_SYMBOL(snd_card_free);
478 478
479static void snd_card_set_id_internal(struct snd_card *card, const char *nid, 479static void snd_card_set_id_no_lock(struct snd_card *card, const char *nid)
480 int do_locking)
481{ 480{
482 int i, len, idx_flag = 0, loops = SNDRV_CARDS; 481 int i, len, idx_flag = 0, loops = SNDRV_CARDS;
483 const char *spos, *src; 482 const char *spos, *src;
484 char *id; 483 char *id;
485 484
486 /* check if user specified own card->id */
487 if (card->id[0] != '\0')
488 return;
489 if (nid == NULL) { 485 if (nid == NULL) {
490 id = card->shortname; 486 id = card->shortname;
491 spos = src = id; 487 spos = src = id;
@@ -522,16 +518,10 @@ static void snd_card_set_id_internal(struct snd_card *card, const char *nid,
522 } 518 }
523 if (!snd_info_check_reserved_words(id)) 519 if (!snd_info_check_reserved_words(id))
524 goto __change; 520 goto __change;
525 if (do_locking)
526 mutex_lock(&snd_card_mutex);
527 for (i = 0; i < snd_ecards_limit; i++) { 521 for (i = 0; i < snd_ecards_limit; i++) {
528 if (snd_cards[i] && !strcmp(snd_cards[i]->id, id)) { 522 if (snd_cards[i] && !strcmp(snd_cards[i]->id, id))
529 mutex_unlock(&snd_card_mutex);
530 goto __change; 523 goto __change;
531 }
532 } 524 }
533 if (do_locking)
534 mutex_unlock(&snd_card_mutex);
535 break; 525 break;
536 526
537 __change: 527 __change:
@@ -566,7 +556,12 @@ static void snd_card_set_id_internal(struct snd_card *card, const char *nid,
566 */ 556 */
567void snd_card_set_id(struct snd_card *card, const char *nid) 557void snd_card_set_id(struct snd_card *card, const char *nid)
568{ 558{
569 snd_card_set_id_internal(card, nid, 1); 559 /* check if user specified own card->id */
560 if (card->id[0] != '\0')
561 return;
562 mutex_lock(&snd_card_mutex);
563 snd_card_set_id_no_lock(card, nid);
564 mutex_unlock(&snd_card_mutex);
570} 565}
571EXPORT_SYMBOL(snd_card_set_id); 566EXPORT_SYMBOL(snd_card_set_id);
572 567
@@ -663,8 +658,7 @@ int snd_card_register(struct snd_card *card)
663 mutex_unlock(&snd_card_mutex); 658 mutex_unlock(&snd_card_mutex);
664 return 0; 659 return 0;
665 } 660 }
666 if (card->id[0] == '\0') 661 snd_card_set_id_no_lock(card, card->id[0] == '\0' ? NULL : card->id);
667 snd_card_set_id_internal(card, NULL, 0);
668 snd_cards[card->number] = card; 662 snd_cards[card->number] = card;
669 mutex_unlock(&snd_card_mutex); 663 mutex_unlock(&snd_card_mutex);
670 init_info_for_card(card); 664 init_info_for_card(card);