diff mbox series

[2/2] ALSA: ump: Set default protocol when not given explicitly

Message ID 20240529094515.12666-2-tiwai@suse.de (mailing list archive)
State Superseded
Headers show
Series [1/2] ALSA: ump: Don't accept an invalid UMP protocol number | expand

Commit Message

Takashi Iwai May 29, 2024, 9:45 a.m. UTC
When an inquiry of the current protocol via UMP Stream Configuration
message fails by some reason, we may leave the current protocol
undefined, which may lead to unexpected behavior.  Better to assume a
valid protocol found in the protocol capability bits instead.

For a device that doesn't support the UMP v1.2 feature, it won't reach
to this code path, and USB MIDI GTB descriptor would be used for
determining the protocol, instead.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 sound/core/ump.c | 8 ++++++++
 1 file changed, 8 insertions(+)
diff mbox series

Patch

diff --git a/sound/core/ump.c b/sound/core/ump.c
index 5bd7b77acb95..fb612559f8f0 100644
--- a/sound/core/ump.c
+++ b/sound/core/ump.c
@@ -966,6 +966,14 @@  int snd_ump_parse_endpoint(struct snd_ump_endpoint *ump)
 	if (err < 0)
 		ump_dbg(ump, "Unable to get UMP EP stream config\n");
 
+	/* If no protocol is set by some reason, assume the valid one */
+	if (!(ump->info.protocol & SNDRV_UMP_EP_INFO_PROTO_MIDI_MASK)) {
+		if (ump->info.protocol_caps & SNDRV_UMP_EP_INFO_PROTO_MIDI2)
+			ump->info.protocol |= SNDRV_UMP_EP_INFO_PROTO_MIDI2;
+		else if (ump->info.protocol_caps & SNDRV_UMP_EP_INFO_PROTO_MIDI1)
+			ump->info.protocol |= SNDRV_UMP_EP_INFO_PROTO_MIDI1;
+	}
+
 	/* Query and create blocks from Function Blocks */
 	for (blk = 0; blk < ump->info.num_blocks; blk++) {
 		err = create_block_from_fb_info(ump, blk);