Skip to content

Commit 697ec8f

Browse files
Kautuk Consulgregkh
authored andcommitted
xhci-mem.c: Check for ring->first_seg != NULL
commit 0e6c7f7 upstream. There are 2 situations wherein the xhci_ring* might not get freed: - When xhci_ring_alloc() -> xhci_segment_alloc() returns NULL and we goto the fail: label in xhci_ring_alloc. In this case, the ring will not get kfreed. - When the num_segs argument to xhci_ring_alloc is passed as 0 and we try to free the rung after that. ( This doesn't really happen as of now in the code but we seem to be entertaining num_segs=0 in xhci_ring_alloc ) This should be backported to kernels as old as 2.6.31. Signed-off-by: Kautuk Consul <consul.kautuk@gmail.com> Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
1 parent dc7623d commit 697ec8f

1 file changed

Lines changed: 12 additions & 10 deletions

File tree

‎drivers/usb/host/xhci-mem.c‎

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -112,18 +112,20 @@ void xhci_ring_free(struct xhci_hcd *xhci, struct xhci_ring *ring)
112112
struct xhci_segment *seg;
113113
struct xhci_segment *first_seg;
114114

115-
if (!ring || !ring->first_seg)
115+
if (!ring)
116116
return;
117-
first_seg = ring->first_seg;
118-
seg = first_seg->next;
119-
xhci_dbg(xhci, "Freeing ring at %p\n", ring);
120-
while (seg != first_seg) {
121-
struct xhci_segment *next = seg->next;
122-
xhci_segment_free(xhci, seg);
123-
seg = next;
117+
if (ring->first_seg) {
118+
first_seg = ring->first_seg;
119+
seg = first_seg->next;
120+
xhci_dbg(xhci, "Freeing ring at %p\n", ring);
121+
while (seg != first_seg) {
122+
struct xhci_segment *next = seg->next;
123+
xhci_segment_free(xhci, seg);
124+
seg = next;
125+
}
126+
xhci_segment_free(xhci, first_seg);
127+
ring->first_seg = NULL;
124128
}
125-
xhci_segment_free(xhci, first_seg);
126-
ring->first_seg = NULL;
127129
kfree(ring);
128130
}
129131

0 commit comments

Comments
 (0)