Skip to content

Commit 7bb2491

Browse files
committed
ALSA: Add kconfig to specify the max card numbers
Currently ALSA supports up to 32 card instances when the dynamic minor is used. While 32 cards are usually big enough for normal use cases, there are sometimes weird requirements with more card support. Actually, this limitation, 32, comes from the index option, where you can pass the bit mask to assign the card. Other than that, we can actually give more cards up to the minor number limits (currently 256, which can be extended more, too). This patch adds a new Kconfig to specify the max card numbers, and changes a few places to accept more than 32 cards. The only incompatibility with high card numbers would be the handling of index option. The index option can be still used to pass the bitmask for card assignments, but this works only up to 32 slots. More than 32, no bitmask style option is available but only a single slot can be specified via index option. Signed-off-by: Takashi Iwai <tiwai@suse.de>
1 parent 8edbb19 commit 7bb2491

3 files changed

Lines changed: 26 additions & 10 deletions

File tree

‎include/sound/core.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
/* number of supported soundcards */
3232
#ifdef CONFIG_SND_DYNAMIC_MINORS
33-
#define SNDRV_CARDS 32
33+
#define SNDRV_CARDS CONFIG_SND_MAX_CARDS
3434
#else
3535
#define SNDRV_CARDS 8 /* don't change - minor numbers */
3636
#endif

‎sound/core/Kconfig‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,15 @@ config SND_DYNAMIC_MINORS
157157

158158
If you are unsure about this, say N here.
159159

160+
config SND_MAX_CARDS
161+
int "Max number of sound cards"
162+
range 4 256
163+
default 32
164+
depends on SND_DYNAMIC_MINORS
165+
help
166+
Specify the max number of sound cards that can be assigned
167+
on a single machine.
168+
160169
config SND_SUPPORT_OLD_API
161170
bool "Support old ALSA API"
162171
default y

‎sound/core/init.c‎

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ static LIST_HEAD(shutdown_files);
4646

4747
static const struct file_operations snd_shutdown_f_ops;
4848

49-
static unsigned int snd_cards_lock; /* locked for registering/using */
49+
/* locked for registering/using */
50+
static DECLARE_BITMAP(snd_cards_lock, SNDRV_CARDS);
5051
struct snd_card *snd_cards[SNDRV_CARDS];
5152
EXPORT_SYMBOL(snd_cards);
5253

@@ -167,29 +168,35 @@ int snd_card_create(int idx, const char *xid,
167168
err = 0;
168169
mutex_lock(&snd_card_mutex);
169170
if (idx < 0) {
170-
for (idx2 = 0; idx2 < SNDRV_CARDS; idx2++)
171+
for (idx2 = 0; idx2 < SNDRV_CARDS; idx2++) {
171172
/* idx == -1 == 0xffff means: take any free slot */
172-
if (~snd_cards_lock & idx & 1<<idx2) {
173+
if (idx2 < sizeof(int) && !(idx & (1U << idx2)))
174+
continue;
175+
if (!test_bit(idx2, snd_cards_lock)) {
173176
if (module_slot_match(module, idx2)) {
174177
idx = idx2;
175178
break;
176179
}
177180
}
181+
}
178182
}
179183
if (idx < 0) {
180-
for (idx2 = 0; idx2 < SNDRV_CARDS; idx2++)
184+
for (idx2 = 0; idx2 < SNDRV_CARDS; idx2++) {
181185
/* idx == -1 == 0xffff means: take any free slot */
182-
if (~snd_cards_lock & idx & 1<<idx2) {
186+
if (idx2 < sizeof(int) && !(idx & (1U << idx2)))
187+
continue;
188+
if (!test_bit(idx2, snd_cards_lock)) {
183189
if (!slots[idx2] || !*slots[idx2]) {
184190
idx = idx2;
185191
break;
186192
}
187193
}
194+
}
188195
}
189196
if (idx < 0)
190197
err = -ENODEV;
191198
else if (idx < snd_ecards_limit) {
192-
if (snd_cards_lock & (1 << idx))
199+
if (test_bit(idx, snd_cards_lock))
193200
err = -EBUSY; /* invalid */
194201
} else if (idx >= SNDRV_CARDS)
195202
err = -ENODEV;
@@ -199,7 +206,7 @@ int snd_card_create(int idx, const char *xid,
199206
idx, snd_ecards_limit - 1, err);
200207
goto __error;
201208
}
202-
snd_cards_lock |= 1 << idx; /* lock it */
209+
set_bit(idx, snd_cards_lock); /* lock it */
203210
if (idx >= snd_ecards_limit)
204211
snd_ecards_limit = idx + 1; /* increase the limit */
205212
mutex_unlock(&snd_card_mutex);
@@ -249,7 +256,7 @@ int snd_card_locked(int card)
249256
int locked;
250257

251258
mutex_lock(&snd_card_mutex);
252-
locked = snd_cards_lock & (1 << card);
259+
locked = test_bit(card, snd_cards_lock);
253260
mutex_unlock(&snd_card_mutex);
254261
return locked;
255262
}
@@ -361,7 +368,7 @@ int snd_card_disconnect(struct snd_card *card)
361368
/* phase 1: disable fops (user space) operations for ALSA API */
362369
mutex_lock(&snd_card_mutex);
363370
snd_cards[card->number] = NULL;
364-
snd_cards_lock &= ~(1 << card->number);
371+
clear_bit(card->number, snd_cards_lock);
365372
mutex_unlock(&snd_card_mutex);
366373

367374
/* phase 2: replace file->f_op with special dummy operations */

0 commit comments

Comments
 (0)