Skip to content

Commit 3e7e04b

Browse files
committed
ALSA: seq: Fix data-race at module auto-loading
It's been reported that there is a possible data-race accessing to the global card_requested[] array at ALSA sequencer core, which is used for determining whether to call request_module() for the card or not. This data race itself is almost harmless, as it might end up with one extra request_module() call for the already loaded module at most. But it's still better to fix. This patch addresses the possible data race of card_requested[] and client_requested[] arrays by replacing them with bitmask. It's an atomic operation and can work without locks. Reported-by: Abhishek Shah <[email protected]> Cc: <[email protected]> Link: https://lore.kernel.org/r/CAEHB24_ay6YzARpA1zgCsE7=H9CSJJzux618E=Ka4h0YdKn=qA@mail.gmail.com Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Takashi Iwai <[email protected]>
1 parent 22dec13 commit 3e7e04b

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

sound/core/seq/seq_clientmgr.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,13 @@ struct snd_seq_client *snd_seq_client_use_ptr(int clientid)
121121
spin_unlock_irqrestore(&clients_lock, flags);
122122
#ifdef CONFIG_MODULES
123123
if (!in_interrupt()) {
124-
static char client_requested[SNDRV_SEQ_GLOBAL_CLIENTS];
125-
static char card_requested[SNDRV_CARDS];
124+
static DECLARE_BITMAP(client_requested, SNDRV_SEQ_GLOBAL_CLIENTS);
125+
static DECLARE_BITMAP(card_requested, SNDRV_CARDS);
126+
126127
if (clientid < SNDRV_SEQ_GLOBAL_CLIENTS) {
127128
int idx;
128129

129-
if (!client_requested[clientid]) {
130-
client_requested[clientid] = 1;
130+
if (!test_and_set_bit(clientid, client_requested)) {
131131
for (idx = 0; idx < 15; idx++) {
132132
if (seq_client_load[idx] < 0)
133133
break;
@@ -142,10 +142,8 @@ struct snd_seq_client *snd_seq_client_use_ptr(int clientid)
142142
int card = (clientid - SNDRV_SEQ_GLOBAL_CLIENTS) /
143143
SNDRV_SEQ_CLIENTS_PER_CARD;
144144
if (card < snd_ecards_limit) {
145-
if (! card_requested[card]) {
146-
card_requested[card] = 1;
145+
if (!test_and_set_bit(card, card_requested))
147146
snd_request_card(card);
148-
}
149147
snd_seq_device_load_drivers();
150148
}
151149
}

0 commit comments

Comments
 (0)