Linux Sound subsystem development
 help / color / mirror / Atom feed
* [PATCH] ALSA: usb-audio: Stop parsing channels bits when all channels are found.
@ 2024-03-12 13:34 Johan Carlsson
  2024-03-12 13:49 ` Takashi Iwai
  0 siblings, 1 reply; 2+ messages in thread
From: Johan Carlsson @ 2024-03-12 13:34 UTC (permalink / raw)
  To: tiwai; +Cc: linux-sound, Johan Carlsson

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(-)

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 */
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] ALSA: usb-audio: Stop parsing channels bits when all channels are found.
  2024-03-12 13:34 [PATCH] ALSA: usb-audio: Stop parsing channels bits when all channels are found Johan Carlsson
@ 2024-03-12 13:49 ` Takashi Iwai
  0 siblings, 0 replies; 2+ messages in thread
From: Takashi Iwai @ 2024-03-12 13:49 UTC (permalink / raw)
  To: Johan Carlsson; +Cc: tiwai, linux-sound

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-03-12 13:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-12 13:34 [PATCH] ALSA: usb-audio: Stop parsing channels bits when all channels are found Johan Carlsson
2024-03-12 13:49 ` Takashi Iwai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox