kfree(seg);
 }
 
-static void xhci_free_segments_for_ring(struct xhci_hcd *xhci,
-                               struct xhci_segment *first)
+static void xhci_ring_segments_free(struct xhci_hcd *xhci, struct xhci_ring *ring)
 {
-       struct xhci_segment *seg;
+       struct xhci_segment *seg, *next;
+
+       ring->last_seg->next = NULL;
+       seg = ring->first_seg;
 
-       seg = first->next;
-       while (seg && seg != first) {
-               struct xhci_segment *next = seg->next;
+       while (seg) {
+               next = seg->next;
                xhci_segment_free(xhci, seg);
                seg = next;
        }
-       xhci_segment_free(xhci, first);
 }
 
 /*
        if (ring->first_seg) {
                if (ring->type == TYPE_STREAM)
                        xhci_remove_stream_mapping(ring);
-               xhci_free_segments_for_ring(xhci, ring->first_seg);
+               xhci_ring_segments_free(xhci, ring);
        }
 
        kfree(ring);
        return 0;
 
 free_segments:
-       xhci_free_segments_for_ring(xhci, ring->first_seg);
+       ring->last_seg = prev;
+       xhci_ring_segments_free(xhci, ring);
        return -ENOMEM;
 }
 
        return 0;
 
 free_segments:
-       xhci_free_segments_for_ring(xhci, new_ring.first_seg);
+       xhci_ring_segments_free(xhci, &new_ring);
        return ret;
 }