Skip to content

Commit 9e8b214

Browse files
Selvarasu Ganesangregkh
Selvarasu Ganesan
authored andcommitted
usb: gadget: f_midi: Fixing wMaxPacketSize exceeded issue during MIDI bind retries
The current implementation sets the wMaxPacketSize of bulk in/out endpoints to 1024 bytes at the end of the f_midi_bind function. However, in cases where there is a failure in the first midi bind attempt, consider rebinding. This scenario may encounter an f_midi_bind issue due to the previous bind setting the bulk endpoint's wMaxPacketSize to 1024 bytes, which exceeds the ep->maxpacket_limit where configured dwc3 TX/RX FIFO's maxpacket size of 512 bytes for IN/OUT endpoints in support HS speed only. Here the term "rebind" in this context refers to attempting to bind the MIDI function a second time in certain scenarios. The situations where rebinding is considered include: * When there is a failure in the first UDC write attempt, which may be caused by other functions bind along with MIDI. * Runtime composition change : Example : MIDI,ADB to MIDI. Or MIDI to MIDI,ADB. This commit addresses this issue by resetting the wMaxPacketSize before endpoint claim. And here there is no need to reset all values in the usb endpoint descriptor structure, as all members except wMaxPacketSize and bEndpointAddress have predefined values. This ensures that restores the endpoint to its expected configuration, and preventing conflicts with value of ep->maxpacket_limit. It also aligns with the approach used in other function drivers, which treat endpoint descriptors as if they were full speed before endpoint claim. Fixes: 46decc8 ("usb: gadget: unconditionally allocate hs/ss descriptor in bind operation") Cc: [email protected] Signed-off-by: Selvarasu Ganesan <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 2014c95 commit 9e8b214

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

drivers/usb/gadget/function/f_midi.c

+9
Original file line numberDiff line numberDiff line change
@@ -907,6 +907,15 @@ static int f_midi_bind(struct usb_configuration *c, struct usb_function *f)
907907

908908
status = -ENODEV;
909909

910+
/*
911+
* Reset wMaxPacketSize with maximum packet size of FS bulk transfer before
912+
* endpoint claim. This ensures that the wMaxPacketSize does not exceed the
913+
* limit during bind retries where configured dwc3 TX/RX FIFO's maxpacket
914+
* size of 512 bytes for IN/OUT endpoints in support HS speed only.
915+
*/
916+
bulk_in_desc.wMaxPacketSize = cpu_to_le16(64);
917+
bulk_out_desc.wMaxPacketSize = cpu_to_le16(64);
918+
910919
/* allocate instance-specific endpoints */
911920
midi->in_ep = usb_ep_autoconfig(cdev->gadget, &bulk_in_desc);
912921
if (!midi->in_ep)

0 commit comments

Comments
 (0)