Comment 30 for bug 8050

Revision history for this message
Thomas Hood (jdthood) wrote :

The current semantics of the "index" option are:

   >= SNDRV_CARDS invalid
   0..(SNDRV_CARDS-1) Assign that index
   -1 Assign the first available index between 0 and
(SNDRV_CARDS-1)

A natural way to extend this to meet our needs is to regard -1, i.e.,
0xffffffff, as a bitmask of permissible indices. Then TV cards and
modems can be loaded with index=-2, i.e. 0xfffffffe. The patch to
implement this is straightforward:

--- alsa-kernel/core/init.c_ORIG 2005-01-07 12:29:53.000000000 +0100
+++ alsa-kernel/core/init.c 2005-01-07 13:43:54.000000000 +0100
@@ -84,16 +84,13 @@
        write_lock(&snd_card_rwlock);
        if (idx < 0) {
                int idx2;
- for (idx2 = 0; idx2 < snd_ecards_limit; idx2++)
- if (!(snd_cards_lock & (1 << idx2))) {
+ for (idx2 = 0; idx2 < SNDRV_CARDS; idx2++)
+ if (~snd_cards_lock & idx & 1<<idx2) {
                                idx = idx2;
+ if (idx >= snd_ecards_limit)
+ snd_ecards_limit = idx + 1;
                                break;
                        }
- if (idx < 0 && snd_ecards_limit < SNDRV_CARDS)
- /* for dynamically additional devices like hotplug:
- * increment the limit if still free slot exists.
- */
- idx = snd_ecards_limit++;
        } else if (idx < snd_ecards_limit) {
                if (snd_cards_lock & (1 << idx))
                        err = -ENODEV; /* invalid */

A short console log shows that this works:

root@thanatos:~# cat /proc/asound/cards
--- no soundcards ---
root@thanatos:~# modprobe snd-dummy
root@thanatos:~# cat /proc/asound/cards
0 [Dummy ]: Dummy - Dummy
                     Dummy 1
root@thanatos:~# rmmod snd-dummy
root@thanatos:~# cat /proc/asound/cards
--- no soundcards ---
root@thanatos:~# echo "options snd-dummy index=-16" > /etc/modprobe.d/s
root@thanatos:~# # N.B., -16=0xfffffff0
root@thanatos:~# modprobe snd-dummy
root@thanatos:~# cat /proc/asound/cards
4 [Dummy ]: Dummy - Dummy
                     Dummy 1
root@thanatos:~# echo "options snd-cs46xx index=-16" >> /etc/modprobe.d/s
root@thanatos:~# modprobe snd-cs46xx
root@thanatos:~# cat /proc/asound/cards
4 [Dummy ]: Dummy - Dummy
                     Dummy 1
5 [CS46xx ]: CS46xx - Sound Fusion CS46xx
                     Sound Fusion CS46xx at 0x50100000/0x50000000, irq 11