diff options
Diffstat (limited to 'sound/core/init.c')
-rw-r--r-- | sound/core/init.c | 61 |
1 files changed, 39 insertions, 22 deletions
diff --git a/sound/core/init.c b/sound/core/init.c index fd56afe846ed..d5d40d78c409 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)) { | ||
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)); | 156 | 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,28 @@ 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 | static void snd_card_set_id_no_lock(struct snd_card *card, const char *nid) |
487 | { | 480 | { |
488 | int i, len, idx_flag = 0, loops = SNDRV_CARDS; | 481 | int i, len, idx_flag = 0, loops = SNDRV_CARDS; |
489 | char *id, *spos; | 482 | const char *spos, *src; |
483 | char *id; | ||
490 | 484 | ||
491 | id = spos = card->shortname; | 485 | if (nid == NULL) { |
492 | while (*id != '\0') { | 486 | id = card->shortname; |
493 | if (*id == ' ') | 487 | spos = src = id; |
494 | spos = id + 1; | 488 | while (*id != '\0') { |
495 | id++; | 489 | if (*id == ' ') |
490 | spos = id + 1; | ||
491 | id++; | ||
492 | } | ||
493 | } else { | ||
494 | spos = src = nid; | ||
496 | } | 495 | } |
497 | id = card->id; | 496 | id = card->id; |
498 | while (*spos != '\0' && !isalnum(*spos)) | 497 | while (*spos != '\0' && !isalnum(*spos)) |
499 | spos++; | 498 | spos++; |
500 | if (isdigit(*spos)) | 499 | if (isdigit(*spos)) |
501 | *id++ = isalpha(card->shortname[0]) ? card->shortname[0] : 'D'; | 500 | *id++ = isalpha(src[0]) ? src[0] : 'D'; |
502 | while (*spos != '\0' && (size_t)(id - card->id) < sizeof(card->id) - 1) { | 501 | while (*spos != '\0' && (size_t)(id - card->id) < sizeof(card->id) - 1) { |
503 | if (isalnum(*spos)) | 502 | if (isalnum(*spos)) |
504 | *id++ = *spos; | 503 | *id++ = *spos; |
@@ -513,7 +512,7 @@ static void choose_default_id(struct snd_card *card) | |||
513 | 512 | ||
514 | while (1) { | 513 | while (1) { |
515 | if (loops-- == 0) { | 514 | if (loops-- == 0) { |
516 | snd_printk(KERN_ERR "unable to choose default card id (%s)\n", id); | 515 | snd_printk(KERN_ERR "unable to set card id (%s)\n", id); |
517 | strcpy(card->id, card->proc_root->name); | 516 | strcpy(card->id, card->proc_root->name); |
518 | return; | 517 | return; |
519 | } | 518 | } |
@@ -539,14 +538,33 @@ static void choose_default_id(struct snd_card *card) | |||
539 | spos = id + len - 2; | 538 | spos = id + len - 2; |
540 | if ((size_t)len <= sizeof(card->id) - 2) | 539 | if ((size_t)len <= sizeof(card->id) - 2) |
541 | spos++; | 540 | spos++; |
542 | *spos++ = '_'; | 541 | *(char *)spos++ = '_'; |
543 | *spos++ = '1'; | 542 | *(char *)spos++ = '1'; |
544 | *spos++ = '\0'; | 543 | *(char *)spos++ = '\0'; |
545 | idx_flag++; | 544 | idx_flag++; |
546 | } | 545 | } |
547 | } | 546 | } |
548 | } | 547 | } |
549 | 548 | ||
549 | /** | ||
550 | * snd_card_set_id - set card identification name | ||
551 | * @card: soundcard structure | ||
552 | * @nid: new identification string | ||
553 | * | ||
554 | * This function sets the card identification and checks for name | ||
555 | * collisions. | ||
556 | */ | ||
557 | void snd_card_set_id(struct snd_card *card, const char *nid) | ||
558 | { | ||
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); | ||
565 | } | ||
566 | EXPORT_SYMBOL(snd_card_set_id); | ||
567 | |||
550 | #ifndef CONFIG_SYSFS_DEPRECATED | 568 | #ifndef CONFIG_SYSFS_DEPRECATED |
551 | static ssize_t | 569 | static ssize_t |
552 | card_id_show_attr(struct device *dev, | 570 | card_id_show_attr(struct device *dev, |
@@ -640,8 +658,7 @@ int snd_card_register(struct snd_card *card) | |||
640 | mutex_unlock(&snd_card_mutex); | 658 | mutex_unlock(&snd_card_mutex); |
641 | return 0; | 659 | return 0; |
642 | } | 660 | } |
643 | if (card->id[0] == '\0') | 661 | snd_card_set_id_no_lock(card, card->id[0] == '\0' ? NULL : card->id); |
644 | choose_default_id(card); | ||
645 | snd_cards[card->number] = card; | 662 | snd_cards[card->number] = card; |
646 | mutex_unlock(&snd_card_mutex); | 663 | mutex_unlock(&snd_card_mutex); |
647 | init_info_for_card(card); | 664 | init_info_for_card(card); |