diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c index 74fb524..2170dd4 100644 --- a/drivers/usb/gadget/f_fastboot.c +++ b/drivers/usb/gadget/f_fastboot.c @@ -614,6 +614,16 @@ fastboot_tx_print(f_fb, "OKAY"); } +static int rx_bytes_expected(struct f_fastboot *f_fb) +{ + int remaining = f_fb->download_size - f_fb->download_bytes; + + if (remaining >= EP_BUFFER_SIZE) + return EP_BUFFER_SIZE; + + return ALIGN(remaining, f_fb->out_ep->maxpacket); +} + static void rx_handler_dl_image(struct usb_ep *ep, struct usb_request *req) { struct f_fastboot *f_fb = req->context; @@ -637,9 +647,7 @@ f_fb->download_bytes += req->actual; - req->length = f_fb->download_size - f_fb->download_bytes; - if (req->length > EP_BUFFER_SIZE) - req->length = EP_BUFFER_SIZE; + req->length = rx_bytes_expected(f_fb); show_progress(f_fb->download_bytes); @@ -692,9 +700,7 @@ struct usb_ep *ep = f_fb->out_ep; fastboot_tx_print(f_fb, "DATA%08x", f_fb->download_size); req->complete = rx_handler_dl_image; - req->length = EP_BUFFER_SIZE; - if (req->length < ep->maxpacket) - req->length = ep->maxpacket; + req->length = rx_bytes_expected(f_fb); } }