From: Daniel Mack <daniel@caiaq.de>
To: Takashi Iwai <tiwai@suse.de>
Cc: alsa-devel@alsa-project.org
Subject: Re: [PATCH 2/5] ALSA: snd_usb_caiaq: give better shortname
Date: Tue, 2 Jun 2009 11:31:04 +0200 [thread overview]
Message-ID: <20090602093104.GC26160@buzzloop.caiaq.de> (raw)
In-Reply-To: <s5hfxejrs6k.wl%tiwai@suse.de>
On Tue, Jun 02, 2009 at 09:49:39AM +0200, Takashi Iwai wrote:
> > So what's your suggestion to fix the behaviour I was describing? Maybe a
> > combination of Jaroslav's collision detection together with a logic that
> > does not touch the id in case it was passed as module option?
>
> Sounds reasonable. We may need just a number suffix if any collision
> occurs.
What about that patch below? Works well in my tests here.
Daniel
>From 7f7544af491f6073da3aea72c64f5725c50246c8 Mon Sep 17 00:00:00 2001
From: Daniel Mack <daniel@caiaq.de>
Date: Tue, 2 Jun 2009 11:23:41 +0200
Subject: [PATCH] ALSA: introduce snd_card_make_id_unique()
Sound card drivers may choose their own way to provide a nice sound card
ID, especially when the default behaviour taken by choose_default_name()
is not appropriate. ALSA's IDs must be unique, so there is need for some
core logic to ensure that.
This patch adds the function snd_card_make_id_unique() to the ALSA core
which lowlevel drivers can call to make sure the computed string isn't
already taken.
Signed-off-by: Daniel Mack <daniel@caiaq.de>
Cc: Takashi Iwai <tiwai@suse.de>
Cc: Jaroslav Kysela <perex@perex.cz>
---
include/sound/core.h | 1 +
sound/core/init.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 46 insertions(+), 0 deletions(-)
diff --git a/include/sound/core.h b/include/sound/core.h
index 3dea798..01ea816 100644
--- a/include/sound/core.h
+++ b/include/sound/core.h
@@ -319,6 +319,7 @@ int snd_card_info_done(void);
int snd_component_add(struct snd_card *card, const char *component);
int snd_card_file_add(struct snd_card *card, struct file *file);
int snd_card_file_remove(struct snd_card *card, struct file *file);
+void snd_card_make_id_unique(struct snd_card *card);
#ifndef snd_card_set_dev
#define snd_card_set_dev(card, devptr) ((card)->dev = (devptr))
diff --git a/sound/core/init.c b/sound/core/init.c
index fd56afe..8503a01 100644
--- a/sound/core/init.c
+++ b/sound/core/init.c
@@ -547,6 +547,51 @@ static void choose_default_id(struct snd_card *card)
}
}
+static int
+card_id_is_ambiguous(struct snd_card *card, const char *id)
+{
+ int i;
+
+ for (i = 0; i < snd_ecards_limit; i++) {
+ /* only run for exisiting cards but not for the
+ * one in question */
+ if (i == card->number || !snd_cards[i])
+ continue;
+
+ if (strcmp(snd_cards[i]->id, id) == 0)
+ return 1;
+ }
+
+ return 0;
+}
+
+void
+snd_card_make_id_unique(struct snd_card *card)
+{
+ int count = 1;
+ char id[sizeof(card->id)];
+
+ if (*card->id == '\0')
+ return;
+
+ strlcpy(id, card->id, sizeof(id));
+
+ while (card_id_is_ambiguous(card, id)) {
+ /* As we need to add some characters to the id, make
+ * sure there's enough room for it */
+ int maxlen = sizeof(card->id) - (2 + (count / 10));
+
+ if (strlen(card->id) > maxlen)
+ card->id[maxlen] = '\0';
+
+ snprintf(id, sizeof(id), "%s_%d", card->id, count);
+ count++;
+ }
+
+ strlcpy(card->id, id, sizeof(id));
+}
+EXPORT_SYMBOL_GPL(snd_card_make_id_unique);
+
#ifndef CONFIG_SYSFS_DEPRECATED
static ssize_t
card_id_show_attr(struct device *dev,
--
1.6.3.1
next prev parent reply other threads:[~2009-06-02 9:31 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-05-30 21:44 [PATCH 1/5] ALSA: snd_usb_caiaq: clean whitespaces Daniel Mack
2009-05-30 21:44 ` [PATCH 2/5] ALSA: snd_usb_caiaq: give better shortname Daniel Mack
2009-05-30 21:44 ` [PATCH 3/5] ALSA: snd_usb_caiaq: use strncpy Daniel Mack
2009-05-30 21:44 ` [PATCH 4/5] ALSA: snd_usb_caiaq: give better longname Daniel Mack
2009-05-30 21:44 ` [PATCH 5/5] ALSA: snd_usb_caiaq: bump version number Daniel Mack
2009-06-01 8:32 ` [PATCH 3/5] ALSA: snd_usb_caiaq: use strncpy Takashi Iwai
2009-06-01 9:23 ` Daniel Mack
2009-06-01 16:55 ` Takashi Iwai
2009-06-01 19:36 ` [PATCH 1/5] ALSA: snd_usb_caiaq: clean whitespaces Daniel Mack
2009-06-01 19:36 ` [PATCH 2/5] ALSA: snd_usb_caiaq: give better shortname Daniel Mack
2009-06-01 19:36 ` [PATCH 3/5] ALSA: snd_usb_caiaq: use strlcpy Daniel Mack
2009-06-01 19:36 ` [PATCH 4/5] ALSA: snd_usb_caiaq: give better longname Daniel Mack
2009-06-01 19:36 ` [PATCH 5/5] ALSA: snd_usb_caiaq: bump version number Daniel Mack
2009-06-01 21:09 ` [PATCH 2/5] ALSA: snd_usb_caiaq: give better shortname Jaroslav Kysela
2009-06-01 23:46 ` Takashi Iwai
2009-06-02 7:29 ` Daniel Mack
2009-06-02 7:49 ` Takashi Iwai
2009-06-02 9:31 ` Daniel Mack [this message]
2009-06-02 9:50 ` Takashi Iwai
2009-06-02 9:55 ` Daniel Mack
2009-06-02 10:10 ` [PATCH] ALSA: introduce snd_card_make_id_unique() (was: ALSA: snd_usb_caiaq: give better shortname) Daniel Mack
2009-06-02 10:11 ` [PATCH 2/5] ALSA: snd_usb_caiaq: give better shortname Jaroslav Kysela
2009-06-02 10:28 ` Daniel Mack
2009-06-02 10:54 ` Takashi Iwai
-- strict thread matches above, loose matches on Subject: below --
2009-05-30 20:25 [PATCH 1/5] ALSA: snd_usb_caiaq: clean whitespaces Daniel Mack
2009-05-30 20:25 ` [PATCH 2/5] ALSA: snd_usb_caiaq: give better shortname Daniel Mack
2009-05-30 21:17 ` Jaroslav Kysela
2009-05-30 21:36 ` Daniel Mack
2009-05-30 20:06 [PATCH 1/5] ALSA: snd_usb_caiaq: clean whitespaces Daniel Mack
2009-05-30 20:06 ` [PATCH 2/5] ALSA: snd_usb_caiaq: give better shortname Daniel Mack
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20090602093104.GC26160@buzzloop.caiaq.de \
--to=daniel@caiaq.de \
--cc=alsa-devel@alsa-project.org \
--cc=tiwai@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox