diff options
-rw-r--r-- | include/sound/core.h | 1 | ||||
-rw-r--r-- | sound/core/init.c | 62 |
2 files changed, 40 insertions, 23 deletions
diff --git a/include/sound/core.h b/include/sound/core.h index 3dea79829acc..0e8ae10155ab 100644 --- a/include/sound/core.h +++ b/include/sound/core.h | |||
@@ -313,6 +313,7 @@ struct snd_card *snd_card_new(int idx, const char *id, | |||
313 | int snd_card_disconnect(struct snd_card *card); | 313 | int snd_card_disconnect(struct snd_card *card); |
314 | int snd_card_free(struct snd_card *card); | 314 | int snd_card_free(struct snd_card *card); |
315 | int snd_card_free_when_closed(struct snd_card *card); | 315 | int snd_card_free_when_closed(struct snd_card *card); |
316 | void snd_card_set_id(struct snd_card *card, const char *id); | ||
316 | int snd_card_register(struct snd_card *card); | 317 | int snd_card_register(struct snd_card *card); |
317 | int snd_card_info_init(void); | 318 | int snd_card_info_init(void); |
318 | int snd_card_info_done(void); | 319 | int snd_card_info_done(void); |
diff --git a/sound/core/init.c b/sound/core/init.c index fd56afe846ed..6557dd85e191 100644 --- a/sound/core/init.c +++ b/sound/core/init.c | |||
@@ -152,15 +152,8 @@ int snd_card_create(int idx, const char *xid, | |||
152 | card = kzalloc(sizeof(*card) + extra_size, GFP_KERNEL); | 152 | card = kzalloc(sizeof(*card) + extra_size, GFP_KERNEL); |
153 | if (!card) | 153 | if (!card) |
154 | return -ENOMEM; | 154 | return -ENOMEM; |
155 | if (xid) { | 155 | if (xid) |
156 | if (!snd_info_check_reserved_words(xid)) { | 156 | snd_card_set_id(card, xid); |
157 | snd_printk(KERN_ERR | ||
158 | "given id string '%s' is reserved.\n", xid); | ||
159 | err = -EBUSY; | ||
160 | goto __error; | ||
161 | } | ||
162 | strlcpy(card->id, xid, sizeof(card->id)); | ||
163 | } | ||
164 | err = 0; | 157 | err = 0; |
165 | mutex_lock(&snd_card_mutex); | 158 | mutex_lock(&snd_card_mutex); |
166 | if (idx < 0) { | 159 | if (idx < 0) { |
@@ -483,22 +476,39 @@ int snd_card_free(struct snd_card *card) | |||
483 | 476 | ||
484 | EXPORT_SYMBOL(snd_card_free); | 477 | EXPORT_SYMBOL(snd_card_free); |
485 | 478 | ||
486 | static void choose_default_id(struct snd_card *card) | 479 | /** |
480 | * snd_card_set_id - set card identification name | ||
481 | * @card: soundcard structure | ||
482 | * @nid: new identification string | ||
483 | * | ||
484 | * This function sets the card identification and checks for name | ||
485 | * collisions. | ||
486 | */ | ||
487 | void snd_card_set_id(struct snd_card *card, const char *nid) | ||
487 | { | 488 | { |
488 | int i, len, idx_flag = 0, loops = SNDRV_CARDS; | 489 | int i, len, idx_flag = 0, loops = SNDRV_CARDS; |
489 | char *id, *spos; | 490 | const char *spos, *src; |
491 | char *id; | ||
490 | 492 | ||
491 | id = spos = card->shortname; | 493 | /* check if user specified own card->id */ |
492 | while (*id != '\0') { | 494 | if (card->id[0] != '\0') |
493 | if (*id == ' ') | 495 | return; |
494 | spos = id + 1; | 496 | if (nid == NULL) { |
495 | id++; | 497 | id = card->shortname; |
498 | spos = src = id; | ||
499 | while (*id != '\0') { | ||
500 | if (*id == ' ') | ||
501 | spos = id + 1; | ||
502 | id++; | ||
503 | } | ||
504 | } else { | ||
505 | spos = src = nid; | ||
496 | } | 506 | } |
497 | id = card->id; | 507 | id = card->id; |
498 | while (*spos != '\0' && !isalnum(*spos)) | 508 | while (*spos != '\0' && !isalnum(*spos)) |
499 | spos++; | 509 | spos++; |
500 | if (isdigit(*spos)) | 510 | if (isdigit(*spos)) |
501 | *id++ = isalpha(card->shortname[0]) ? card->shortname[0] : 'D'; | 511 | *id++ = isalpha(src[0]) ? src[0] : 'D'; |
502 | while (*spos != '\0' && (size_t)(id - card->id) < sizeof(card->id) - 1) { | 512 | while (*spos != '\0' && (size_t)(id - card->id) < sizeof(card->id) - 1) { |
503 | if (isalnum(*spos)) | 513 | if (isalnum(*spos)) |
504 | *id++ = *spos; | 514 | *id++ = *spos; |
@@ -513,16 +523,20 @@ static void choose_default_id(struct snd_card *card) | |||
513 | 523 | ||
514 | while (1) { | 524 | while (1) { |
515 | if (loops-- == 0) { | 525 | if (loops-- == 0) { |
516 | snd_printk(KERN_ERR "unable to choose default card id (%s)\n", id); | 526 | snd_printk(KERN_ERR "unable to set card id (%s)\n", id); |
517 | strcpy(card->id, card->proc_root->name); | 527 | strcpy(card->id, card->proc_root->name); |
518 | return; | 528 | return; |
519 | } | 529 | } |
520 | if (!snd_info_check_reserved_words(id)) | 530 | if (!snd_info_check_reserved_words(id)) |
521 | goto __change; | 531 | goto __change; |
532 | mutex_lock(&snd_card_mutex); | ||
522 | for (i = 0; i < snd_ecards_limit; i++) { | 533 | for (i = 0; i < snd_ecards_limit; i++) { |
523 | if (snd_cards[i] && !strcmp(snd_cards[i]->id, id)) | 534 | if (snd_cards[i] && !strcmp(snd_cards[i]->id, id)) { |
535 | mutex_unlock(&snd_card_mutex); | ||
524 | goto __change; | 536 | goto __change; |
537 | } | ||
525 | } | 538 | } |
539 | mutex_unlock(&snd_card_mutex); | ||
526 | break; | 540 | break; |
527 | 541 | ||
528 | __change: | 542 | __change: |
@@ -539,14 +553,16 @@ static void choose_default_id(struct snd_card *card) | |||
539 | spos = id + len - 2; | 553 | spos = id + len - 2; |
540 | if ((size_t)len <= sizeof(card->id) - 2) | 554 | if ((size_t)len <= sizeof(card->id) - 2) |
541 | spos++; | 555 | spos++; |
542 | *spos++ = '_'; | 556 | *(char *)spos++ = '_'; |
543 | *spos++ = '1'; | 557 | *(char *)spos++ = '1'; |
544 | *spos++ = '\0'; | 558 | *(char *)spos++ = '\0'; |
545 | idx_flag++; | 559 | idx_flag++; |
546 | } | 560 | } |
547 | } | 561 | } |
548 | } | 562 | } |
549 | 563 | ||
564 | EXPORT_SYMBOL(snd_card_set_id); | ||
565 | |||
550 | #ifndef CONFIG_SYSFS_DEPRECATED | 566 | #ifndef CONFIG_SYSFS_DEPRECATED |
551 | static ssize_t | 567 | static ssize_t |
552 | card_id_show_attr(struct device *dev, | 568 | card_id_show_attr(struct device *dev, |
@@ -641,7 +657,7 @@ int snd_card_register(struct snd_card *card) | |||
641 | return 0; | 657 | return 0; |
642 | } | 658 | } |
643 | if (card->id[0] == '\0') | 659 | if (card->id[0] == '\0') |
644 | choose_default_id(card); | 660 | snd_card_set_id(card, NULL); |
645 | snd_cards[card->number] = card; | 661 | snd_cards[card->number] = card; |
646 | mutex_unlock(&snd_card_mutex); | 662 | mutex_unlock(&snd_card_mutex); |
647 | init_info_for_card(card); | 663 | init_info_for_card(card); |