Commit 4c3773ed authored by Dan Carpenter's avatar Dan Carpenter Committed by Takashi Iwai

ALSA: bits vs bytes bug in snd_card_create()

The test here is intended intended to prevent shift wrapping bugs when
we do "1U << idx2".  We should consider the number of bits in a u32
instead of the number of bytes.

[fix another chunk similarly by tiwai]

Fixes: 7bb2491b ('ALSA: Add kconfig to specify the max card numbers')
Signed-off-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 23870831
...@@ -170,7 +170,7 @@ int snd_card_create(int idx, const char *xid, ...@@ -170,7 +170,7 @@ int snd_card_create(int idx, const char *xid,
if (idx < 0) { if (idx < 0) {
for (idx2 = 0; idx2 < SNDRV_CARDS; idx2++) { for (idx2 = 0; idx2 < SNDRV_CARDS; idx2++) {
/* idx == -1 == 0xffff means: take any free slot */ /* idx == -1 == 0xffff means: take any free slot */
if (idx2 < sizeof(int) && !(idx & (1U << idx2))) if (idx2 < 32 && !(idx & (1U << idx2)))
continue; continue;
if (!test_bit(idx2, snd_cards_lock)) { if (!test_bit(idx2, snd_cards_lock)) {
if (module_slot_match(module, idx2)) { if (module_slot_match(module, idx2)) {
...@@ -183,7 +183,7 @@ int snd_card_create(int idx, const char *xid, ...@@ -183,7 +183,7 @@ int snd_card_create(int idx, const char *xid,
if (idx < 0) { if (idx < 0) {
for (idx2 = 0; idx2 < SNDRV_CARDS; idx2++) { for (idx2 = 0; idx2 < SNDRV_CARDS; idx2++) {
/* idx == -1 == 0xffff means: take any free slot */ /* idx == -1 == 0xffff means: take any free slot */
if (idx2 < sizeof(int) && !(idx & (1U << idx2))) if (idx2 < 32 && !(idx & (1U << idx2)))
continue; continue;
if (!test_bit(idx2, snd_cards_lock)) { if (!test_bit(idx2, snd_cards_lock)) {
if (!slots[idx2] || !*slots[idx2]) { if (!slots[idx2] || !*slots[idx2]) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment