Skip to content

Commit 3eb27d3

Browse files
tiwaigregkh
authored andcommitted
usb: gadget: midi2: Fix incorrect default MIDI2 protocol setup
The MIDI2 gadget driver handled the default MIDI protocol version incorrectly due to the confusion of the protocol version passed via configfs (either 1 or 2) and UMP protocol bits (0x100 / 0x200). As a consequence, the default protocol always resulted in MIDI1. This patch addresses the misunderstanding of the protocol handling. Fixes: 29ee7a4 ("usb: gadget: midi2: Add configfs support") Cc: stable <[email protected]> Signed-off-by: Takashi Iwai <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 1792641 commit 3eb27d3

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

drivers/usb/gadget/function/f_midi2.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ struct f_midi2 {
150150

151151
#define func_to_midi2(f) container_of(f, struct f_midi2, func)
152152

153+
/* convert from MIDI protocol number (1 or 2) to SNDRV_UMP_EP_INFO_PROTO_* */
154+
#define to_ump_protocol(v) (((v) & 3) << 8)
155+
153156
/* get EP name string */
154157
static const char *ump_ep_name(const struct f_midi2_ep *ep)
155158
{
@@ -564,8 +567,7 @@ static void reply_ump_stream_ep_config(struct f_midi2_ep *ep)
564567
.status = UMP_STREAM_MSG_STATUS_STREAM_CFG,
565568
};
566569

567-
if ((ep->info.protocol & SNDRV_UMP_EP_INFO_PROTO_MIDI_MASK) ==
568-
SNDRV_UMP_EP_INFO_PROTO_MIDI2)
570+
if (ep->info.protocol == 2)
569571
rep.protocol = UMP_STREAM_MSG_EP_INFO_CAP_MIDI2 >> 8;
570572
else
571573
rep.protocol = UMP_STREAM_MSG_EP_INFO_CAP_MIDI1 >> 8;
@@ -627,13 +629,13 @@ static void process_ump_stream_msg(struct f_midi2_ep *ep, const u32 *data)
627629
return;
628630
case UMP_STREAM_MSG_STATUS_STREAM_CFG_REQUEST:
629631
if (*data & UMP_STREAM_MSG_EP_INFO_CAP_MIDI2) {
630-
ep->info.protocol = SNDRV_UMP_EP_INFO_PROTO_MIDI2;
632+
ep->info.protocol = 2;
631633
DBG(midi2, "Switching Protocol to MIDI2\n");
632634
} else {
633-
ep->info.protocol = SNDRV_UMP_EP_INFO_PROTO_MIDI1;
635+
ep->info.protocol = 1;
634636
DBG(midi2, "Switching Protocol to MIDI1\n");
635637
}
636-
snd_ump_switch_protocol(ep->ump, ep->info.protocol);
638+
snd_ump_switch_protocol(ep->ump, to_ump_protocol(ep->info.protocol));
637639
reply_ump_stream_ep_config(ep);
638640
return;
639641
case UMP_STREAM_MSG_STATUS_FB_DISCOVERY:
@@ -1065,7 +1067,8 @@ static void f_midi2_midi1_ep_out_complete(struct usb_ep *usb_ep,
10651067
group = midi2->out_cable_mapping[cable].group;
10661068
bytes = midi1_packet_bytes[*buf & 0x0f];
10671069
for (c = 0; c < bytes; c++) {
1068-
snd_ump_convert_to_ump(cvt, group, ep->info.protocol,
1070+
snd_ump_convert_to_ump(cvt, group,
1071+
to_ump_protocol(ep->info.protocol),
10691072
buf[c + 1]);
10701073
if (cvt->ump_bytes) {
10711074
snd_ump_receive(ep->ump, cvt->ump,
@@ -1375,7 +1378,7 @@ static void assign_block_descriptors(struct f_midi2 *midi2,
13751378
desc->nNumGroupTrm = b->num_groups;
13761379
desc->iBlockItem = ep->blks[blk].string_id;
13771380

1378-
if (ep->info.protocol & SNDRV_UMP_EP_INFO_PROTO_MIDI2)
1381+
if (ep->info.protocol == 2)
13791382
desc->bMIDIProtocol = USB_MS_MIDI_PROTO_2_0;
13801383
else
13811384
desc->bMIDIProtocol = USB_MS_MIDI_PROTO_1_0_128;
@@ -1552,7 +1555,7 @@ static int f_midi2_create_card(struct f_midi2 *midi2)
15521555
if (midi2->info.static_block)
15531556
ump->info.flags |= SNDRV_UMP_EP_INFO_STATIC_BLOCKS;
15541557
ump->info.protocol_caps = (ep->info.protocol_caps & 3) << 8;
1555-
ump->info.protocol = (ep->info.protocol & 3) << 8;
1558+
ump->info.protocol = to_ump_protocol(ep->info.protocol);
15561559
ump->info.version = 0x0101;
15571560
ump->info.family_id = ep->info.family;
15581561
ump->info.model_id = ep->info.model;

0 commit comments

Comments
 (0)