@@ -359,10 +359,14 @@ static int f_midi_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
/* allocate a bunch of read buffers and queue them all at once. */
for (i = 0; i < midi->qlen && err == 0; i++) {
- struct usb_request *req =
- midi_alloc_ep_req(midi->out_ep,
- max_t(unsigned, midi->buflen,
- bulk_out_desc.wMaxPacketSize));
+ struct usb_request *req;
+ unsigned length;
+
+ length = midi->buflen < bulk_out_desc.wMaxPacketSize
+ ? bulk_out_desc.wMaxPacketSize
+ : usb_ep_align_maybe(midi->gadget, midi->out_ep,
+ midi->buflen);
+ req = midi_alloc_ep_req(midi->out_ep, length);
if (req == NULL)
return -ENOMEM;