aboutsummaryrefslogtreecommitdiffstats
path: root/sound/core
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2008-12-25 05:40:34 -0500
committerTakashi Iwai <tiwai@suse.de>2008-12-25 05:40:34 -0500
commit5ce442fe2c9423ec5451222aee6f9b2127bb8311 (patch)
tree9cb12cf2c4ab5a8af5de219c22eade3908b5cb59 /sound/core
parent60cda2b53a7826d273198f668cd124f0eeda0e4a (diff)
parent2af752936b311a846622668f8b0f1893d8eccade (diff)
Merge branch 'topic/udev-id-rename' into to-push
Diffstat (limited to 'sound/core')
-rw-r--r--sound/core/info.c17
-rw-r--r--sound/core/init.c71
2 files changed, 87 insertions, 1 deletions
diff --git a/sound/core/info.c b/sound/core/info.c
index 527b207462b0..70fa87189f36 100644
--- a/sound/core/info.c
+++ b/sound/core/info.c
@@ -653,6 +653,23 @@ int snd_info_card_register(struct snd_card *card)
653} 653}
654 654
655/* 655/*
656 * called on card->id change
657 */
658void snd_info_card_id_change(struct snd_card *card)
659{
660 mutex_lock(&info_mutex);
661 if (card->proc_root_link) {
662 snd_remove_proc_entry(snd_proc_root, card->proc_root_link);
663 card->proc_root_link = NULL;
664 }
665 if (strcmp(card->id, card->proc_root->name))
666 card->proc_root_link = proc_symlink(card->id,
667 snd_proc_root,
668 card->proc_root->name);
669 mutex_unlock(&info_mutex);
670}
671
672/*
656 * de-register the card proc file 673 * de-register the card proc file
657 * called from init.c 674 * called from init.c
658 */ 675 */
diff --git a/sound/core/init.c b/sound/core/init.c
index b47ff8b44be8..0d5520c415d3 100644
--- a/sound/core/init.c
+++ b/sound/core/init.c
@@ -533,6 +533,65 @@ static void choose_default_id(struct snd_card *card)
533 } 533 }
534} 534}
535 535
536#ifndef CONFIG_SYSFS_DEPRECATED
537static ssize_t
538card_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
545static ssize_t
546card_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 snd_info_card_id_change(card);
575 mutex_unlock(&snd_card_mutex);
576
577 return count;
578}
579
580static struct device_attribute card_id_attrs =
581 __ATTR(id, S_IRUGO | S_IWUSR, card_id_show_attr, card_id_store_attr);
582
583static ssize_t
584card_number_show_attr(struct device *dev,
585 struct device_attribute *attr, char *buf)
586{
587 struct snd_card *card = dev_get_drvdata(dev);
588 return snprintf(buf, PAGE_SIZE, "%i\n", card ? card->number : -1);
589}
590
591static struct device_attribute card_number_attrs =
592 __ATTR(number, S_IRUGO, card_number_show_attr, NULL);
593#endif /* CONFIG_SYSFS_DEPRECATED */
594
536/** 595/**
537 * snd_card_register - register the soundcard 596 * snd_card_register - register the soundcard
538 * @card: soundcard structure 597 * @card: soundcard structure
@@ -553,7 +612,7 @@ int snd_card_register(struct snd_card *card)
553#ifndef CONFIG_SYSFS_DEPRECATED 612#ifndef CONFIG_SYSFS_DEPRECATED
554 if (!card->card_dev) { 613 if (!card->card_dev) {
555 card->card_dev = device_create(sound_class, card->dev, 614 card->card_dev = device_create(sound_class, card->dev,
556 MKDEV(0, 0), NULL, 615 MKDEV(0, 0), card,
557 "card%i", card->number); 616 "card%i", card->number);
558 if (IS_ERR(card->card_dev)) 617 if (IS_ERR(card->card_dev))
559 card->card_dev = NULL; 618 card->card_dev = NULL;
@@ -576,6 +635,16 @@ int snd_card_register(struct snd_card *card)
576 if (snd_mixer_oss_notify_callback) 635 if (snd_mixer_oss_notify_callback)
577 snd_mixer_oss_notify_callback(card, SND_MIXER_OSS_NOTIFY_REGISTER); 636 snd_mixer_oss_notify_callback(card, SND_MIXER_OSS_NOTIFY_REGISTER);
578#endif 637#endif
638#ifndef CONFIG_SYSFS_DEPRECATED
639 if (card->card_dev) {
640 err = device_create_file(card->card_dev, &card_id_attrs);
641 if (err < 0)
642 return err;
643 err = device_create_file(card->card_dev, &card_number_attrs);
644 if (err < 0)
645 return err;
646 }
647#endif
579 return 0; 648 return 0;
580} 649}
581 650