[alsa-devel] [patch] ALSA: bits vs bytes bug in snd_card_create()
Takashi Iwai
tiwai at suse.de
Thu Jan 23 11:48:43 CET 2014
At Thu, 23 Jan 2014 09:36:24 +0100,
Takashi Iwai wrote:
>
> At Thu, 23 Jan 2014 11:21:28 +0300,
> Dan Carpenter wrote:
> >
> > 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.
> >
> > Fixes: 7bb2491b35a2 ('ALSA: Add kconfig to specify the max card numbers')
> > Signed-off-by: Dan Carpenter <dan.carpenter at oracle.com>
> > ---
> > WARNING: Please check this one carefully because I might be wrong.
>
> You're correct. I obviously didn't test more than 4.
> Applied (with Cc to stable) now, thanks.
I found there is another place doing it wrongly (a few lines above
there), so fixed similarly in the same patch.
(And, yes, the code should be refactored; the patch will be sent soon
later.)
Takashi
-- 8< --
From: Dan Carpenter <dan.carpenter at oracle.com>
Subject: [PATCH] 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: 7bb2491b35a2 ('ALSA: Add kconfig to specify the max card numbers')
Signed-off-by: Dan Carpenter <dan.carpenter at oracle.com>
Cc: <stable at vger.kernel.org>
Signed-off-by: Takashi Iwai <tiwai at suse.de>
---
sound/core/init.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/sound/core/init.c b/sound/core/init.c
index 1351f22f651c..e3c93cd77ee7 100644
--- a/sound/core/init.c
+++ b/sound/core/init.c
@@ -170,7 +170,7 @@ int snd_card_create(int idx, const char *xid,
if (idx < 0) {
for (idx2 = 0; idx2 < SNDRV_CARDS; idx2++) {
/* idx == -1 == 0xffff means: take any free slot */
- if (idx2 < sizeof(int) && !(idx & (1U << idx2)))
+ if (idx2 < 32 && !(idx & (1U << idx2)))
continue;
if (!test_bit(idx2, snd_cards_lock)) {
if (module_slot_match(module, idx2)) {
@@ -183,7 +183,7 @@ int snd_card_create(int idx, const char *xid,
if (idx < 0) {
for (idx2 = 0; idx2 < SNDRV_CARDS; idx2++) {
/* idx == -1 == 0xffff means: take any free slot */
- if (idx2 < sizeof(int) && !(idx & (1U << idx2)))
+ if (idx2 < 32 && !(idx & (1U << idx2)))
continue;
if (!test_bit(idx2, snd_cards_lock)) {
if (!slots[idx2] || !*slots[idx2]) {
--
1.8.5.2
More information about the Alsa-devel
mailing list