Make the skipping of the link TRBS build-in to the increment and decrement operations. This simplifies the code wherever we increment and decrement and ensures that we never end up pointing to a link trb. Signed-off-by: John Youn <johnyoun@xxxxxxxxxxxx> --- drivers/usb/dwc3/gadget.c | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 8629b60..3eaef22 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -145,21 +145,23 @@ int dwc3_gadget_set_link_state(struct dwc3 *dwc, enum dwc3_link_state state) return -ETIMEDOUT; } +static bool dwc3_ep_is_last_trb(unsigned int index) +{ + return index == (DWC3_TRB_NUM - 1); +} + static void dwc3_ep_inc_enq(struct dwc3_ep *dep) { dep->trb_enqueue++; - dep->trb_enqueue %= DWC3_TRB_NUM; + if (dwc3_ep_is_last_trb(dep->trb_enqueue)) + dep->trb_enqueue = 0; } static void dwc3_ep_inc_deq(struct dwc3_ep *dep) { dep->trb_dequeue++; - dep->trb_dequeue %= DWC3_TRB_NUM; -} - -static int dwc3_ep_is_last_trb(unsigned int index) -{ - return index == DWC3_TRB_NUM - 1; + if (dwc3_ep_is_last_trb(dep->trb_dequeue)) + dep->trb_dequeue = 0; } void dwc3_gadget_giveback(struct dwc3_ep *dep, struct dwc3_request *req, @@ -172,13 +174,6 @@ void dwc3_gadget_giveback(struct dwc3_ep *dep, struct dwc3_request *req, i = 0; do { dwc3_ep_inc_deq(dep); - /* - * Skip LINK TRB. We can't use req->trb and check for - * DWC3_TRBCTL_LINK_TRB because it points the TRB we - * just completed (not the LINK TRB). - */ - if (dwc3_ep_is_last_trb(dep->trb_dequeue)) - dwc3_ep_inc_deq(dep); } while(++i < req->request.num_mapped_sgs); req->started = false; } @@ -799,9 +794,6 @@ static void dwc3_prepare_one_trb(struct dwc3_ep *dep, } dwc3_ep_inc_enq(dep); - /* Skip the LINK-TRB */ - if (dwc3_ep_is_last_trb(dep->trb_enqueue)) - dwc3_ep_inc_enq(dep); trb->size = DWC3_TRB_SIZE_LENGTH(length); trb->bpl = lower_32_bits(dma); -- 2.8.2 -- 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