ALSA: Fix the default suffix string with high card number
ALSA core tries to add a suffix as "_1" automatically when the given id string conflicts. The current code assumes implicitly that the max card number is 16 so that the single hex "_X" suffix can be put. However, with the dynamic device management, the card can be at most 32, so it can put even a non-hex character there. Also, when the max card number is increased in future, this would result in worse. This patch rewrites the code to add the suffix string in a simpler (thus cleaner) way. It can support up to three digits, so it should suffice for most requirements. Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
parent
e6c2e7eb27
commit
8edbb198a6
1 changed files with 13 additions and 17 deletions
|
@ -549,7 +549,6 @@ static void snd_card_set_id_no_lock(struct snd_card *card, const char *src,
|
||||||
const char *nid)
|
const char *nid)
|
||||||
{
|
{
|
||||||
int len, loops;
|
int len, loops;
|
||||||
bool with_suffix;
|
|
||||||
bool is_default = false;
|
bool is_default = false;
|
||||||
char *id;
|
char *id;
|
||||||
|
|
||||||
|
@ -565,26 +564,23 @@ static void snd_card_set_id_no_lock(struct snd_card *card, const char *src,
|
||||||
is_default = true;
|
is_default = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
with_suffix = false;
|
len = strlen(id);
|
||||||
for (loops = 0; loops < SNDRV_CARDS; loops++) {
|
for (loops = 0; loops < SNDRV_CARDS; loops++) {
|
||||||
|
char *spos;
|
||||||
|
char sfxstr[5]; /* "_012" */
|
||||||
|
int sfxlen;
|
||||||
|
|
||||||
if (card_id_ok(card, id))
|
if (card_id_ok(card, id))
|
||||||
return; /* OK */
|
return; /* OK */
|
||||||
|
|
||||||
len = strlen(id);
|
/* Add _XYZ suffix */
|
||||||
if (!with_suffix) {
|
sprintf(sfxstr, "_%X", loops + 1);
|
||||||
/* add the "_X" suffix */
|
sfxlen = strlen(sfxstr);
|
||||||
char *spos = id + len;
|
if (len + sfxlen >= sizeof(card->id))
|
||||||
if (len > sizeof(card->id) - 3)
|
spos = id + sizeof(card->id) - sfxlen - 1;
|
||||||
spos = id + sizeof(card->id) - 3;
|
else
|
||||||
strcpy(spos, "_1");
|
spos = id + len;
|
||||||
with_suffix = true;
|
strcpy(spos, sfxstr);
|
||||||
} else {
|
|
||||||
/* modify the existing suffix */
|
|
||||||
if (id[len - 1] != '9')
|
|
||||||
id[len - 1]++;
|
|
||||||
else
|
|
||||||
id[len - 1] = 'A';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/* fallback to the default id */
|
/* fallback to the default id */
|
||||||
if (!is_default) {
|
if (!is_default) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue