All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mathias Nyman <mathias.nyman@linux.intel.com>
To: <gregkh@linuxfoundation.org>
Cc: <linux-usb@vger.kernel.org>,
	Niklas Neronin <niklas.neronin@linux.intel.com>,
	Mathias Nyman <mathias.nyman@linux.intel.com>
Subject: [PATCH 12/33] usb: xhci: adjust xhci_alloc_segments_for_ring() arguments
Date: Wed,  6 Nov 2024 12:14:38 +0200	[thread overview]
Message-ID: <20241106101459.775897-13-mathias.nyman@linux.intel.com> (raw)
In-Reply-To: <20241106101459.775897-1-mathias.nyman@linux.intel.com>

From: Niklas Neronin <niklas.neronin@linux.intel.com>

The function xhci_alloc_segments_for_ring() currently takes 7 arguments,
5 of which are components of the 'xhci_ring' struct. Refactor the function
to accept a pointer to the 'xhci_ring' struct instead of passing these
components separately.

The change reduces the number of arguments, making the function signature
cleaner and easier to understand.

Signed-off-by: Niklas Neronin <niklas.neronin@linux.intel.com>
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
---
 drivers/usb/host/xhci-mem.c | 48 ++++++++++++++++---------------------
 1 file changed, 21 insertions(+), 27 deletions(-)

diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index 164b22d0b475..fa77a15dfde6 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -313,44 +313,38 @@ void xhci_initialize_ring_info(struct xhci_ring *ring)
 EXPORT_SYMBOL_GPL(xhci_initialize_ring_info);
 
 /* Allocate segments and link them for a ring */
-static int xhci_alloc_segments_for_ring(struct xhci_hcd *xhci,
-					struct xhci_segment **first,
-					struct xhci_segment **last,
-					unsigned int num_segs,
-					enum xhci_ring_type type,
-					unsigned int max_packet,
-					gfp_t flags)
+static int xhci_alloc_segments_for_ring(struct xhci_hcd *xhci, struct xhci_ring *ring, gfp_t flags)
 {
 	struct xhci_segment *prev;
 	unsigned int num = 0;
 	bool chain_links;
 
-	chain_links = xhci_link_chain_quirk(xhci, type);
+	chain_links = xhci_link_chain_quirk(xhci, ring->type);
 
-	prev = xhci_segment_alloc(xhci, max_packet, num, flags);
+	prev = xhci_segment_alloc(xhci, ring->bounce_buf_len, num, flags);
 	if (!prev)
 		return -ENOMEM;
 	num++;
 
-	*first = prev;
-	while (num < num_segs) {
+	ring->first_seg = prev;
+	while (num < ring->num_segs) {
 		struct xhci_segment	*next;
 
-		next = xhci_segment_alloc(xhci, max_packet, num, flags);
+		next = xhci_segment_alloc(xhci, ring->bounce_buf_len, num, flags);
 		if (!next)
 			goto free_segments;
 
-		xhci_link_segments(prev, next, type, chain_links);
+		xhci_link_segments(prev, next, ring->type, chain_links);
 		prev = next;
 		num++;
 	}
-	xhci_link_segments(prev, *first, type, chain_links);
-	*last = prev;
+	xhci_link_segments(prev, ring->first_seg, ring->type, chain_links);
+	ring->last_seg = prev;
 
 	return 0;
 
 free_segments:
-	xhci_free_segments_for_ring(xhci, *first);
+	xhci_free_segments_for_ring(xhci, ring->first_seg);
 	return -ENOMEM;
 }
 
@@ -379,8 +373,7 @@ struct xhci_ring *xhci_ring_alloc(struct xhci_hcd *xhci, unsigned int num_segs,
 	if (num_segs == 0)
 		return ring;
 
-	ret = xhci_alloc_segments_for_ring(xhci, &ring->first_seg, &ring->last_seg, num_segs,
-					   type, max_packet, flags);
+	ret = xhci_alloc_segments_for_ring(xhci, ring, flags);
 	if (ret)
 		goto fail;
 
@@ -414,23 +407,24 @@ void xhci_free_endpoint_ring(struct xhci_hcd *xhci,
 int xhci_ring_expansion(struct xhci_hcd *xhci, struct xhci_ring *ring,
 				unsigned int num_new_segs, gfp_t flags)
 {
-	struct xhci_segment	*first;
-	struct xhci_segment	*last;
-	int			ret;
+	struct xhci_ring new_ring;
+	int ret;
 
-	ret = xhci_alloc_segments_for_ring(xhci, &first, &last, num_new_segs, ring->type,
-					   ring->bounce_buf_len, flags);
+	new_ring.num_segs = num_new_segs;
+	new_ring.bounce_buf_len = ring->bounce_buf_len;
+	new_ring.type = ring->type;
+	ret = xhci_alloc_segments_for_ring(xhci, &new_ring, flags);
 	if (ret)
 		return -ENOMEM;
 
 	if (ring->type == TYPE_STREAM) {
-		ret = xhci_update_stream_segment_mapping(ring->trb_address_map,
-						ring, first, flags);
+		ret = xhci_update_stream_segment_mapping(ring->trb_address_map, ring,
+							 new_ring.first_seg, flags);
 		if (ret)
 			goto free_segments;
 	}
 
-	xhci_link_rings(xhci, ring, first, last, num_new_segs);
+	xhci_link_rings(xhci, ring, new_ring.first_seg, new_ring.last_seg, num_new_segs);
 	trace_xhci_ring_expansion(ring);
 	xhci_dbg_trace(xhci, trace_xhci_dbg_ring_expansion,
 			"ring expansion succeed, now has %d segments",
@@ -439,7 +433,7 @@ int xhci_ring_expansion(struct xhci_hcd *xhci, struct xhci_ring *ring,
 	return 0;
 
 free_segments:
-	xhci_free_segments_for_ring(xhci, first);
+	xhci_free_segments_for_ring(xhci, new_ring.first_seg);
 	return ret;
 }
 
-- 
2.25.1


  parent reply	other threads:[~2024-11-06 10:13 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-06 10:14 [PATCH 00/33] xhci features and fixes for usb-next Mathias Nyman
2024-11-06 10:14 ` [PATCH 01/33] xhci: Add Isochronous TRB fields to TRB tracer Mathias Nyman
2024-11-06 10:14 ` [PATCH 02/33] usb: xhci: Remove unused parameters of next_trb() Mathias Nyman
2024-11-06 10:14 ` [PATCH 03/33] usb: xhci: Fix sum_trb_lengths() Mathias Nyman
2024-11-06 10:14 ` [PATCH 04/33] xhci: Cleanup Candence controller PCI device and vendor ID usage Mathias Nyman
2024-11-06 10:14 ` [PATCH 05/33] xhci: show DMA address of TRB when tracing TRBs Mathias Nyman
2024-11-06 10:14 ` [PATCH 06/33] xhci: Don't trace ring at every enqueue or dequeue increase Mathias Nyman
2024-11-06 10:14 ` [PATCH 07/33] xhci: add stream context tracing Mathias Nyman
2024-11-06 10:14 ` [PATCH 08/33] xhci: trace stream context at Set TR Deq command completion Mathias Nyman
2024-11-06 10:14 ` [PATCH 09/33] xhci: debugfs: Add virt endpoint state to xhci debugfs Mathias Nyman
2024-11-06 10:14 ` [PATCH 10/33] usb: xhci: introduce macro for ring segment list iteration Mathias Nyman
2024-11-06 10:14 ` [PATCH 11/33] usb: xhci: remove option to change a default ring's TRB cycle bit Mathias Nyman
2024-11-06 10:14 ` Mathias Nyman [this message]
2024-11-06 10:14 ` [PATCH 13/33] usb: xhci: rework xhci_free_segments_for_ring() Mathias Nyman
2024-11-06 10:14 ` [PATCH 14/33] usb: xhci: refactor xhci_link_rings() to use source and destination rings Mathias Nyman
2024-11-06 10:14 ` [PATCH 15/33] usb: xhci: rework xhci_link_segments() Mathias Nyman
2024-11-06 10:14 ` [PATCH 16/33] usb: xhci: add xhci_initialize_ring_segments() Mathias Nyman
2024-11-06 10:14 ` [PATCH 17/33] xhci: Combine two if statements for Etron xHCI host Mathias Nyman
2024-11-06 10:14 ` [PATCH 18/33] xhci: Don't issue Reset Device command to " Mathias Nyman
2024-11-06 10:14 ` [PATCH 19/33] xhci: Fix control transfer error on " Mathias Nyman
2024-11-06 10:14 ` [PATCH 20/33] xhci: Don't perform Soft Retry for " Mathias Nyman
2024-11-06 10:14 ` [PATCH 21/33] xhci: pci: Use standard pattern for device IDs Mathias Nyman
2024-11-06 10:14 ` [PATCH 22/33] xhci: pci: Fix indentation in the PCI device ID definitions Mathias Nyman
2024-11-06 10:14 ` [PATCH 23/33] usb: xhci: simplify TDs start and end naming scheme in struct 'xhci_td' Mathias Nyman
2024-11-06 10:14 ` [PATCH 24/33] usb: xhci: move link TRB quirk to xhci_gen_setup() Mathias Nyman
2024-11-06 10:14 ` [PATCH 25/33] usb: xhci: request MSI/-X according to requested amount Mathias Nyman
2024-11-06 10:14 ` [PATCH 26/33] usb: xhci: improve xhci_clear_command_ring() Mathias Nyman
2024-11-06 10:14 ` [PATCH 27/33] usb: xhci: remove unused arguments from td_to_noop() Mathias Nyman
2024-11-06 10:14 ` [PATCH 28/33] usb: xhci: refactor xhci_td_cleanup() to return void Mathias Nyman
2024-11-06 10:14 ` [PATCH 29/33] usb: xhci: add help function xhci_dequeue_td() Mathias Nyman
2024-11-06 10:14 ` [PATCH 30/33] usb: xhci: remove irrelevant comment Mathias Nyman
2024-11-06 10:14 ` [PATCH 31/33] usb: xhci: Limit Stop Endpoint retries Mathias Nyman
2024-11-06 10:14 ` [PATCH 32/33] usb: xhci: Fix TD invalidation under pending Set TR Dequeue Mathias Nyman
2024-11-06 10:14 ` [PATCH 33/33] usb: xhci: Avoid queuing redundant Stop Endpoint commands Mathias Nyman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241106101459.775897-13-mathias.nyman@linux.intel.com \
    --to=mathias.nyman@linux.intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=niklas.neronin@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.