return xhci_td_cleanup(xhci, td, ep_ring, td->status);
 }
 
-/* sum trb lengths from ring dequeue up to stop_trb, _excluding_ stop_trb */
-static int sum_trb_lengths(struct xhci_hcd *xhci, struct xhci_ring *ring,
-                          union xhci_trb *stop_trb)
+/* sum trb lengths from the first trb up to stop_trb, _excluding_ stop_trb */
+static u32 sum_trb_lengths(struct xhci_td *td, union xhci_trb *stop_trb)
 {
        u32 sum;
-       union xhci_trb *trb = ring->dequeue;
-       struct xhci_segment *seg = ring->deq_seg;
+       union xhci_trb *trb = td->first_trb;
+       struct xhci_segment *seg = td->start_seg;
 
        for (sum = 0; trb != stop_trb; next_trb(&seg, &trb)) {
                if (!trb_is_noop(trb) && !trb_is_link(trb))
                goto finish_td;
 
        if (sum_trbs_for_length)
-               frame->actual_length = sum_trb_lengths(xhci, ep->ring, ep_trb) +
+               frame->actual_length = sum_trb_lengths(td, ep_trb) +
                        ep_trb_len - remaining;
        else
                frame->actual_length = requested;
                goto finish_td;
        case COMP_STOPPED_LENGTH_INVALID:
                /* stopped on ep trb with invalid length, exclude it */
-               td->urb->actual_length = sum_trb_lengths(xhci, ep_ring, ep_trb);
+               td->urb->actual_length = sum_trb_lengths(td, ep_trb);
                goto finish_td;
        case COMP_USB_TRANSACTION_ERROR:
                if (xhci->quirks & XHCI_NO_SOFT_RETRY ||
                td->urb->actual_length = requested - remaining;
        else
                td->urb->actual_length =
-                       sum_trb_lengths(xhci, ep_ring, ep_trb) +
+                       sum_trb_lengths(td, ep_trb) +
                        ep_trb_len - remaining;
 finish_td:
        if (remaining > requested) {