]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - drivers/usb/host/xhci-mem.c
xhci: fix null-pointer dereference when destroying half-built segment rings
[karo-tx-linux.git] / drivers / usb / host / xhci-mem.c
index 487bc083dead0ac0385c81abf81f52917872ac38..fb51c7085ad0d19c7159afd9a069c82846afd405 100644 (file)
@@ -205,7 +205,12 @@ static int xhci_alloc_segments_for_ring(struct xhci_hcd *xhci,
 
                next = xhci_segment_alloc(xhci, cycle_state, flags);
                if (!next) {
-                       xhci_free_segments_for_ring(xhci, *first);
+                       prev = *first;
+                       while (prev) {
+                               next = prev->next;
+                               xhci_segment_free(xhci, prev);
+                               prev = next;
+                       }
                        return -ENOMEM;
                }
                xhci_link_segments(xhci, prev, next, type);
@@ -258,7 +263,7 @@ static struct xhci_ring *xhci_ring_alloc(struct xhci_hcd *xhci,
        return ring;
 
 fail:
-       xhci_ring_free(xhci, ring);
+       kfree(ring);
        return NULL;
 }