| From ca3df3468eec87f6374662f7de425bc44c3810c1 Mon Sep 17 00:00:00 2001 |
| From: Thinh Nguyen <Thinh.Nguyen@synopsys.com> |
| Date: Thu, 24 Sep 2020 01:21:18 -0700 |
| Subject: usb: dwc3: gadget: Check MPS of the request length |
| |
| From: Thinh Nguyen <Thinh.Nguyen@synopsys.com> |
| |
| commit ca3df3468eec87f6374662f7de425bc44c3810c1 upstream. |
| |
| When preparing for SG, not all the entries are prepared at once. When |
| resume, don't use the remaining request length to calculate for MPS |
| alignment. Use the entire request->length to do that. |
| |
| Cc: stable@vger.kernel.org |
| Fixes: 5d187c0454ef ("usb: dwc3: gadget: Don't setup more than requested") |
| Signed-off-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com> |
| Signed-off-by: Felipe Balbi <balbi@kernel.org> |
| Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> |
| |
| --- |
| drivers/usb/dwc3/gadget.c | 4 ++-- |
| 1 file changed, 2 insertions(+), 2 deletions(-) |
| |
| --- a/drivers/usb/dwc3/gadget.c |
| +++ b/drivers/usb/dwc3/gadget.c |
| @@ -1095,6 +1095,8 @@ static void dwc3_prepare_one_trb_sg(stru |
| struct scatterlist *s; |
| int i; |
| unsigned int length = req->request.length; |
| + unsigned int maxp = usb_endpoint_maxp(dep->endpoint.desc); |
| + unsigned int rem = length % maxp; |
| unsigned int remaining = req->request.num_mapped_sgs |
| - req->num_queued_sgs; |
| |
| @@ -1106,8 +1108,6 @@ static void dwc3_prepare_one_trb_sg(stru |
| length -= sg_dma_len(s); |
| |
| for_each_sg(sg, s, remaining, i) { |
| - unsigned int maxp = usb_endpoint_maxp(dep->endpoint.desc); |
| - unsigned int rem = length % maxp; |
| unsigned int trb_length; |
| unsigned chain = true; |
| |