Message ID | 20240312133420.11289-1-johan.carlsson@teenage.engineering (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | ALSA: usb-audio: Stop parsing channels bits when all channels are found. | expand |
On Tue, 12 Mar 2024 14:34:20 +0100, Johan Carlsson wrote: > > 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> Thanks, applied with Cc-to-stable and Fixes tag. Takashi
diff --git a/sound/usb/stream.c b/sound/usb/stream.c index 3d4add94e367..d591a526cca1 100644 --- a/sound/usb/stream.c +++ b/sound/usb/stream.c @@ -300,9 +300,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 == chmaps->channels) + break; + } } else { /* If we're missing wChannelConfig, then guess something to make sure the channel map is not skipped entirely */
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> --- sound/usb/stream.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)