Commit 0049d493 authored by Niklas Neronin's avatar Niklas Neronin Committed by Greg Kroah-Hartman
Browse files

usb: xhci: rework xhci_free_segments_for_ring()



The segment list is only relevant within the context of the ring.
Thus, it is more logical to pass the ring itself when freeing all segments
from a ring, rather than passing the ring list.

Rename the function to "xhci_ring_segments_free" to align with the naming
convention of xhci_segment_free().

To make the freeing process more intuitive, free segments sequentially
from start to end (i.e., 0, 1, 2, 3, ...) instead of freeing the first
segment last (i.e., 1, 2, 3, ... 0).

Signed-off-by: default avatarNiklas Neronin <niklas.neronin@linux.intel.com>
Signed-off-by: default avatarMathias Nyman <mathias.nyman@linux.intel.com>
Link: https://lore.kernel.org/r/20241106101459.775897-14-mathias.nyman@linux.intel.com


Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 401406a4
Loading
Loading
Loading
Loading
+11 −10
Original line number Diff line number Diff line
@@ -71,18 +71,18 @@ static void xhci_segment_free(struct xhci_hcd *xhci, struct xhci_segment *seg)
	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);
}

/*
@@ -282,7 +282,7 @@ void xhci_ring_free(struct xhci_hcd *xhci, struct xhci_ring *ring)
	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);
@@ -344,7 +344,8 @@ static int xhci_alloc_segments_for_ring(struct xhci_hcd *xhci, struct xhci_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;
}

@@ -433,7 +434,7 @@ int xhci_ring_expansion(struct xhci_hcd *xhci, struct xhci_ring *ring,
	return 0;

free_segments:
	xhci_free_segments_for_ring(xhci, new_ring.first_seg);
	xhci_ring_segments_free(xhci, &new_ring);
	return ret;
}