Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit b7fc65f

Browse files
Thinh Nguyengregkh
authored andcommitted
usb: dwc3: gadget: Fix looping of queued SG entries
The dwc3_request->num_queued_sgs is decremented on completion. If a partially completed request is handled, then the dwc3_request->num_queued_sgs no longer reflects the total number of num_queued_sgs (it would be cleared). Correctly check the number of request SG entries remained to be prepare and queued. Failure to do this may cause null pointer dereference when accessing non-existent SG entry. Cc: [email protected] Fixes: c96e672 ("usb: dwc3: gadget: Correct the logic for queuing sgs") Signed-off-by: Thinh Nguyen <[email protected]> Link: https://lore.kernel.org/r/d07a7c4aa0fcf746cdca0515150dbe5c52000af7.1731545781.git.Thinh.Nguyen@synopsys.com Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 02a6982 commit b7fc65f

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

drivers/usb/dwc3/gadget.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1470,16 +1470,16 @@ static int dwc3_prepare_trbs_sg(struct dwc3_ep *dep,
14701470
struct scatterlist *s;
14711471
int i;
14721472
unsigned int length = req->request.length;
1473-
unsigned int remaining = req->request.num_mapped_sgs
1474-
- req->num_queued_sgs;
1473+
unsigned int remaining = req->num_pending_sgs;
1474+
unsigned int num_queued_sgs = req->request.num_mapped_sgs - remaining;
14751475
unsigned int num_trbs = req->num_trbs;
14761476
bool needs_extra_trb = dwc3_needs_extra_trb(dep, req);
14771477

14781478
/*
14791479
* If we resume preparing the request, then get the remaining length of
14801480
* the request and resume where we left off.
14811481
*/
1482-
for_each_sg(req->request.sg, s, req->num_queued_sgs, i)
1482+
for_each_sg(req->request.sg, s, num_queued_sgs, i)
14831483
length -= sg_dma_len(s);
14841484

14851485
for_each_sg(sg, s, remaining, i) {

0 commit comments

Comments
 (0)