Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7e2c1b0f authored by Johan Carlsson's avatar Johan Carlsson Committed by Sasha Levin
Browse files

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: default avatarJohan Carlsson <johan.carlsson@teenage.engineering>
Fixes: 04324ccc ("ALSA: usb-audio: add channel map support")
Message-ID: <20240313081509.9801-1-johan.carlsson@teenage.engineering>
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
parent 6bf3c350
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -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 */