diff options
author | Johan Carlsson <johan.carlsson@teenage.engineering> | 2024-03-13 09:15:09 +0100 |
---|---|---|
committer | Sasha Levin <sashal@kernel.org> | 2024-03-26 18:22:41 -0400 |
commit | 7e2c1b0f6dd9abde9e60f0f9730026714468770f (patch) | |
tree | 9fb0fcb8d15d2a5dced8d1cbd77a06fc95717a3c | |
parent | 6bf3c3508c839c4457058686fbd59d9c55e5e598 (diff) | |
download | linux-stable-7e2c1b0f6dd9abde9e60f0f9730026714468770f.tar.gz linux-stable-7e2c1b0f6dd9abde9e60f0f9730026714468770f.tar.bz2 linux-stable-7e2c1b0f6dd9abde9e60f0f9730026714468770f.zip |
ALSA: usb-audio: Stop parsing channels bits when all channels are found.
[ Upstream commit a39d51ff1f52cd0b6fe7d379ac93bd8b4237d1b7 ]
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: 04324ccc75f9 ("ALSA: usb-audio: add channel map support")
Message-ID: <20240313081509.9801-1-johan.carlsson@teenage.engineering>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
-rw-r--r-- | sound/usb/stream.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/sound/usb/stream.c b/sound/usb/stream.c index 1cfb30465df7..3f20438a1b56 100644 --- a/sound/usb/stream.c +++ b/sound/usb/stream.c @@ -306,9 +306,12 @@ static struct snd_pcm_chmap_elem *convert_chmap(int channels, unsigned int bits, c = 0; if (bits) { - for (; bits && *maps; maps++, bits >>= 1) + for (; bits && *maps; maps++, bits >>= 1) { if (bits & 1) chmap->map[c++] = *maps; + if (c == chmap->channels) + break; + } } else { /* If we're missing wChannelConfig, then guess something to make sure the channel map is not skipped entirely */ |