[alsa-devel] RFC: add possibility to change text identification string
Hi all,
based on discussion today, I prepared a patch to handle udev-style card renaming. Comments are welcome.
Jaroslav
At Tue, 11 Nov 2008 17:00:41 +0100 (CET), Jaroslav Kysela wrote:
Hi all,
based on discussion today, I prepared a patch to handle udev-style card renaming. Comments are welcome.
Looks good to me. The sanity check of the id string should be used for the assignment from the module option, too.
I first thought of making id module parameter writable. But, this would require more works, and needs to patch allover places.
One another solution regarding udev thingy is to accept a path as a card number/index in alsa-lib. When the card begins with '/', it's handled as a path, for example. Then, you can simply open that file instead of parsing the whole snd_card_get_index(), etc.
This is a bit hacikish, so I'm not fully convinced, though. Just an idea make the things without changing the kernel infrastructure.
thanks,
Takashi
Jaroslav
From b0dca2c114f465a11f1595854090a85f58870b35 Mon Sep 17 00:00:00 2001
From: Jaroslav Kysela perex@perex.cz Date: Tue, 11 Nov 2008 16:51:02 +0100 Subject: [PATCH] ALSA: add /sys/class/sound/card#/id (r/w) and card#/number (r/o) files
For udev, we need a way to rename soundcard names. The soundcard numbers (indexes) are hardwired but we have a text identification which can be changed at run-time. The ALSA user space tools already allow using of this text identification.
Signed-off-by: Jaroslav Kysela perex@perex.cz
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 b47ff8b..1426abd 100644 --- a/sound/core/init.c +++ b/sound/core/init.c @@ -533,6 +533,64 @@ static void choose_default_id(struct snd_card *card) } }
+#ifndef CONFIG_SYSFS_DEPRECATED +static ssize_t +card_id_show_attr(struct device *dev,
struct device_attribute *attr, char *buf)
+{
- struct snd_card *card = dev_get_drvdata(dev);
- return snprintf(buf, PAGE_SIZE, "%s\n", card ? card->id : "(null)");
+}
+static ssize_t +card_id_store_attr(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
+{
- struct snd_card *card = dev_get_drvdata(dev);
- char buf1[sizeof(card->id)];
- size_t copy = count > sizeof(card->id) - 1 ?
sizeof(card->id) - 1 : count;
- size_t idx;
- int c;
- for (idx = 0; idx < copy; idx++) {
c = buf[idx];
if (!isalnum(c) && c != '_' && c != '-')
return -EINVAL;
- }
- memcpy(buf1, buf, copy);
- buf1[copy] = '\0';
- mutex_lock(&snd_card_mutex);
- if (!snd_info_check_reserved_words(buf1)) {
__exist:
mutex_unlock(&snd_card_mutex);
return -EEXIST;
- }
- for (idx = 0; idx < snd_ecards_limit; idx++) {
if (snd_cards[idx] && !strcmp(snd_cards[idx]->id, buf1))
goto __exist;
- }
- strcpy(card->id, buf1);
- mutex_unlock(&snd_card_mutex);
- return count;
+}
+static struct device_attribute card_id_attrs =
- __ATTR(id, S_IRUGO | S_IWUSR, card_id_show_attr, card_id_store_attr);
+static ssize_t +card_number_show_attr(struct device *dev,
struct device_attribute *attr, char *buf)
+{
- struct snd_card *card = dev_get_drvdata(dev);
- return snprintf(buf, PAGE_SIZE, "%i\n", card ? card->number : -1);
+}
+static struct device_attribute card_number_attrs =
- __ATTR(number, S_IRUGO, card_number_show_attr, NULL);
+#endif /* CONFIG_SYSFS_DEPRECATED */
/**
- snd_card_register - register the soundcard
- @card: soundcard structure
@@ -553,7 +611,7 @@ int snd_card_register(struct snd_card *card) #ifndef CONFIG_SYSFS_DEPRECATED if (!card->card_dev) { card->card_dev = device_create(sound_class, card->dev,
MKDEV(0, 0), NULL,
if (IS_ERR(card->card_dev)) card->card_dev = NULL;MKDEV(0, 0), card, "card%i", card->number);
@@ -576,6 +634,12 @@ int snd_card_register(struct snd_card *card) if (snd_mixer_oss_notify_callback) snd_mixer_oss_notify_callback(card, SND_MIXER_OSS_NOTIFY_REGISTER); #endif +#ifndef CONFIG_SYSFS_DEPRECATED
- if (card->card_dev) {
device_create_file(card->card_dev, &card_id_attrs);
device_create_file(card->card_dev, &card_number_attrs);
- }
+#endif return 0; }
-- 1.6.0.1.217.gb4928
Jaroslav Kysela perex@perex.cz Linux Kernel Sound Maintainer ALSA Project, Red Hat, Inc.
Alsa-devel mailing list Alsa-devel@alsa-project.org http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
At Tue, 11 Nov 2008 17:33:42 +0100, I wrote:
At Tue, 11 Nov 2008 17:00:41 +0100 (CET), Jaroslav Kysela wrote:
Hi all,
based on discussion today, I prepared a patch to handle udev-style card renaming. Comments are welcome.
Looks good to me. The sanity check of the id string should be used for the assignment from the module option, too.
One remaining problem I found is a symlink of id in /proc/asound. This won't be changed even if you change the id string via sysfs. A minor issue, though.
Takashi
On Wed, 12 Nov 2008, Takashi Iwai wrote:
At Tue, 11 Nov 2008 17:33:42 +0100, I wrote:
At Tue, 11 Nov 2008 17:00:41 +0100 (CET), Jaroslav Kysela wrote:
Hi all,
based on discussion today, I prepared a patch to handle udev-style card renaming. Comments are welcome.
Looks good to me. The sanity check of the id string should be used for the assignment from the module option, too.
One remaining problem I found is a symlink of id in /proc/asound. This won't be changed even if you change the id string via sysfs. A minor issue, though.
Thanks for this note. The patch bellow should fix this issue. Also, I'm going to remove card->id from hdsp.c and hdspm.c where this string is used for rawmidi device name - it might be confusing when changed, too.
Jaroslav
diff --git a/include/sound/info.h b/include/sound/info.h index 8ae72e7..baf09d8 100644 --- a/include/sound/info.h +++ b/include/sound/info.h @@ -126,6 +126,7 @@ int snd_info_card_create(struct snd_card * card); int snd_info_card_register(struct snd_card * card); int snd_info_card_free(struct snd_card * card); void snd_info_card_disconnect(struct snd_card * card); +void snd_info_card_id_change(struct snd_card * card); int snd_info_register(struct snd_info_entry * entry);
/* for card drivers */ diff --git a/sound/core/info.c b/sound/core/info.c index 527b207..e91da07 100644 --- a/sound/core/info.c +++ b/sound/core/info.c @@ -653,6 +653,21 @@ int snd_info_card_register(struct snd_card *card) }
/* + * called on card->id change + */ +void snd_info_card_id_change(struct snd_card *card) +{ + mutex_lock(&info_mutex); + if (card->proc_root_link) { + snd_remove_proc_entry(snd_proc_root, card->proc_root_link); + card->proc_root_link = NULL; + } + if (strcmp(card->id, card->proc_root->name)) + card->proc_root_link = proc_symlink(card->id, snd_proc_root, card->proc_root->name); + mutex_unlock(&info_mutex); +} + +/* * de-register the card proc file * called from init.c */ diff --git a/sound/core/init.c b/sound/core/init.c index 5ff297d..af1e407 100644 --- a/sound/core/init.c +++ b/sound/core/init.c @@ -571,6 +571,7 @@ card_id_store_attr(struct device *dev, struct device_attribute *attr, goto __exist; } strcpy(card->id, buf1); + snd_info_card_id_change(card); mutex_unlock(&snd_card_mutex);
return count;
Jaroslav
----- Jaroslav Kysela perex@perex.cz Linux Kernel Sound Maintainer ALSA Project, Red Hat, Inc.
At Wed, 12 Nov 2008 16:29:22 +0100 (CET), Jaroslav Kysela wrote:
On Wed, 12 Nov 2008, Takashi Iwai wrote:
At Tue, 11 Nov 2008 17:33:42 +0100, I wrote:
At Tue, 11 Nov 2008 17:00:41 +0100 (CET), Jaroslav Kysela wrote:
Hi all,
based on discussion today, I prepared a patch to handle udev-style card renaming. Comments are welcome.
Looks good to me. The sanity check of the id string should be used for the assignment from the module option, too.
One remaining problem I found is a symlink of id in /proc/asound. This won't be changed even if you change the id string via sysfs. A minor issue, though.
Thanks for this note. The patch bellow should fix this issue. Also, I'm going to remove card->id from hdsp.c and hdspm.c where this string is used for rawmidi device name - it might be confusing when changed, too.
Jaroslav
diff --git a/include/sound/info.h b/include/sound/info.h index 8ae72e7..baf09d8 100644 --- a/include/sound/info.h +++ b/include/sound/info.h @@ -126,6 +126,7 @@ int snd_info_card_create(struct snd_card * card); int snd_info_card_register(struct snd_card * card); int snd_info_card_free(struct snd_card * card); void snd_info_card_disconnect(struct snd_card * card); +void snd_info_card_id_change(struct snd_card * card); int snd_info_register(struct snd_info_entry * entry);
Don't forget for the case CONFIG_PROC_FS=n.
/* for card drivers */ diff --git a/sound/core/info.c b/sound/core/info.c index 527b207..e91da07 100644 --- a/sound/core/info.c +++ b/sound/core/info.c @@ -653,6 +653,21 @@ int snd_info_card_register(struct snd_card *card) }
/*
- called on card->id change
- */
+void snd_info_card_id_change(struct snd_card *card) +{
- mutex_lock(&info_mutex);
- if (card->proc_root_link) {
snd_remove_proc_entry(snd_proc_root, card->proc_root_link);
card->proc_root_link = NULL;
- }
- if (strcmp(card->id, card->proc_root->name))
card->proc_root_link = proc_symlink(card->id, snd_proc_root, card->proc_root->name);
checkpatch.pl is your friend ;)
thanks,
Takashi
participants (2)
-
Jaroslav Kysela
-
Takashi Iwai