Skip to content

Commit a39d51f

Browse files
Johan Carlssontiwai
authored andcommitted
ALSA: usb-audio: Stop parsing channels bits when all channels are found.
If a usb audio device sets more bits than the amount of channels it could write outside of the map array. Signed-off-by: Johan Carlsson <johan.carlsson@teenage.engineering> Fixes: 04324cc ("ALSA: usb-audio: add channel map support") Message-ID: <20240313081509.9801-1-johan.carlsson@teenage.engineering> Signed-off-by: Takashi Iwai <tiwai@suse.de>
1 parent 526d028 commit a39d51f

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

sound/usb/stream.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,12 @@ static struct snd_pcm_chmap_elem *convert_chmap(int channels, unsigned int bits,
300300
c = 0;
301301

302302
if (bits) {
303-
for (; bits && *maps; maps++, bits >>= 1)
303+
for (; bits && *maps; maps++, bits >>= 1) {
304304
if (bits & 1)
305305
chmap->map[c++] = *maps;
306+
if (c == chmap->channels)
307+
break;
308+
}
306309
} else {
307310
/* If we're missing wChannelConfig, then guess something
308311
to make sure the channel map is not skipped entirely */

0 commit comments

Comments
 (0)