[PATCH v2 1/6] usb: dwc3: gadget: avoid while (1) loop on completion

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



We know that we have to iterate over the list of
started requests. Instead of looping forever, we can
rely on list_for_each_entry(). Likewise, instead of
a do {} while loop over all, maybe available,
scatterlist entries, we can detect if $this request
uses scatterlist and rely on for_each_sg().

This makes the code easier to follow while making
sure that we will *always* break out of the loop.

Signed-off-by: Felipe Balbi <felipe.balbi@xxxxxxxxxxxxxxx>
---

Changes since v1:

	- switch to list_for_each_entry_safe() so we're safe against entry
          removal

 drivers/usb/dwc3/gadget.c | 32 +++++++++++++++++++-------------
 1 file changed, 19 insertions(+), 13 deletions(-)

diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 3cf4c9016b75..c776fb7f524a 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -1926,31 +1926,37 @@ static int __dwc3_cleanup_done_trbs(struct dwc3 *dwc, struct dwc3_ep *dep,
 static int dwc3_cleanup_done_reqs(struct dwc3 *dwc, struct dwc3_ep *dep,
 		const struct dwc3_event_depevt *event, int status)
 {
-	struct dwc3_request	*req;
+	struct dwc3_request	*req, *n;
 	struct dwc3_trb		*trb;
-	unsigned int		i;
 	int			count = 0;
 	int			ret;
 
-	do {
-		int chain;
+	list_for_each_entry_safe(req, n, &dep->started_list, list) {
 
-		req = next_request(&dep->started_list);
-		if (!req)
-			return 1;
+		int chain;
 
 		chain = req->request.num_mapped_sgs > 0;
-		i = 0;
-		do {
+		if (chain) {
+			struct scatterlist *sg = req->request.sg;
+			struct scatterlist *s;
+			unsigned int i;
+
+			for_each_sg(sg, s, req->request.num_mapped_sgs, i) {
+				trb = &dep->trb_pool[dep->trb_dequeue];
+				count += trb->size & DWC3_TRB_SIZE_MASK;
+				dwc3_ep_inc_deq(dep);
+
+				ret = __dwc3_cleanup_done_trbs(dwc, dep, req, trb,
+						event, status, chain);
+			}
+		} else {
 			trb = &dep->trb_pool[dep->trb_dequeue];
 			count += trb->size & DWC3_TRB_SIZE_MASK;
 			dwc3_ep_inc_deq(dep);
 
 			ret = __dwc3_cleanup_done_trbs(dwc, dep, req, trb,
 					event, status, chain);
-			if (ret)
-				break;
-		} while (++i < req->request.num_mapped_sgs);
+		}
 
 		/*
 		 * We assume here we will always receive the entire data block
@@ -1964,7 +1970,7 @@ static int dwc3_cleanup_done_reqs(struct dwc3 *dwc, struct dwc3_ep *dep,
 
 		if (ret)
 			break;
-	} while (1);
+	}
 
 	/*
 	 * Our endpoint might get disabled by another thread during
-- 
2.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux