diff options
-rw-r--r-- | sound/core/init.c | 66 |
1 files changed, 65 insertions, 1 deletions
diff --git a/sound/core/init.c b/sound/core/init.c index b47ff8b44be8..5ff297d1d89a 100644 --- a/sound/core/init.c +++ b/sound/core/init.c | |||
@@ -533,6 +533,64 @@ static void choose_default_id(struct snd_card *card) | |||
533 | } | 533 | } |
534 | } | 534 | } |
535 | 535 | ||
536 | #ifndef CONFIG_SYSFS_DEPRECATED | ||
537 | static ssize_t | ||
538 | card_id_show_attr(struct device *dev, | ||
539 | struct device_attribute *attr, char *buf) | ||
540 | { | ||
541 | struct snd_card *card = dev_get_drvdata(dev); | ||
542 | return snprintf(buf, PAGE_SIZE, "%s\n", card ? card->id : "(null)"); | ||
543 | } | ||
544 | |||
545 | static ssize_t | ||
546 | card_id_store_attr(struct device *dev, struct device_attribute *attr, | ||
547 | const char *buf, size_t count) | ||
548 | { | ||
549 | struct snd_card *card = dev_get_drvdata(dev); | ||
550 | char buf1[sizeof(card->id)]; | ||
551 | size_t copy = count > sizeof(card->id) - 1 ? | ||
552 | sizeof(card->id) - 1 : count; | ||
553 | size_t idx; | ||
554 | int c; | ||
555 | |||
556 | for (idx = 0; idx < copy; idx++) { | ||
557 | c = buf[idx]; | ||
558 | if (!isalnum(c) && c != '_' && c != '-') | ||
559 | return -EINVAL; | ||
560 | } | ||
561 | memcpy(buf1, buf, copy); | ||
562 | buf1[copy] = '\0'; | ||
563 | mutex_lock(&snd_card_mutex); | ||
564 | if (!snd_info_check_reserved_words(buf1)) { | ||
565 | __exist: | ||
566 | mutex_unlock(&snd_card_mutex); | ||
567 | return -EEXIST; | ||
568 | } | ||
569 | for (idx = 0; idx < snd_ecards_limit; idx++) { | ||
570 | if (snd_cards[idx] && !strcmp(snd_cards[idx]->id, buf1)) | ||
571 | goto __exist; | ||
572 | } | ||
573 | strcpy(card->id, buf1); | ||
574 | mutex_unlock(&snd_card_mutex); | ||
575 | |||
576 | return count; | ||
577 | } | ||
578 | |||
579 | static struct device_attribute card_id_attrs = | ||
580 | __ATTR(id, S_IRUGO | S_IWUSR, card_id_show_attr, card_id_store_attr); | ||
581 | |||
582 | static ssize_t | ||
583 | card_number_show_attr(struct device *dev, | ||
584 | struct device_attribute *attr, char *buf) | ||
585 | { | ||
586 | struct snd_card *card = dev_get_drvdata(dev); | ||
587 | return snprintf(buf, PAGE_SIZE, "%i\n", card ? card->number : -1); | ||
588 | } | ||
589 | |||
590 | static struct device_attribute card_number_attrs = | ||
591 | __ATTR(number, S_IRUGO, card_number_show_attr, NULL); | ||
592 | #endif /* CONFIG_SYSFS_DEPRECATED */ | ||
593 | |||
536 | /** | 594 | /** |
537 | * snd_card_register - register the soundcard | 595 | * snd_card_register - register the soundcard |
538 | * @card: soundcard structure | 596 | * @card: soundcard structure |
@@ -553,7 +611,7 @@ int snd_card_register(struct snd_card *card) | |||
553 | #ifndef CONFIG_SYSFS_DEPRECATED | 611 | #ifndef CONFIG_SYSFS_DEPRECATED |
554 | if (!card->card_dev) { | 612 | if (!card->card_dev) { |
555 | card->card_dev = device_create(sound_class, card->dev, | 613 | card->card_dev = device_create(sound_class, card->dev, |
556 | MKDEV(0, 0), NULL, | 614 | MKDEV(0, 0), card, |
557 | "card%i", card->number); | 615 | "card%i", card->number); |
558 | if (IS_ERR(card->card_dev)) | 616 | if (IS_ERR(card->card_dev)) |
559 | card->card_dev = NULL; | 617 | card->card_dev = NULL; |
@@ -576,6 +634,12 @@ int snd_card_register(struct snd_card *card) | |||
576 | if (snd_mixer_oss_notify_callback) | 634 | if (snd_mixer_oss_notify_callback) |
577 | snd_mixer_oss_notify_callback(card, SND_MIXER_OSS_NOTIFY_REGISTER); | 635 | snd_mixer_oss_notify_callback(card, SND_MIXER_OSS_NOTIFY_REGISTER); |
578 | #endif | 636 | #endif |
637 | #ifndef CONFIG_SYSFS_DEPRECATED | ||
638 | if (card->card_dev) { | ||
639 | device_create_file(card->card_dev, &card_id_attrs); | ||
640 | device_create_file(card->card_dev, &card_number_attrs); | ||
641 | } | ||
642 | #endif | ||
579 | return 0; | 643 | return 0; |
580 | } | 644 | } |
581 | 645 | ||