All of lore.kernel.org
 help / color / mirror / Atom feed
* [05/20] usb: host: xhci: introduce xhci_num_tds_for_urb() helper
@ 2018-04-16 12:29 Felipe Balbi
  0 siblings, 0 replies; only message in thread
From: Felipe Balbi @ 2018-04-16 12:29 UTC (permalink / raw)
  To: Mathias Nyman; +Cc: Linux USB, Felipe Balbi

This helper computes the number of TDs for a given urb. Cleanup only,
no functional changes.

Note that while at that we've replaced an alignment check with the
IS_ALIGNED() macro which makes the code slightly clearer about its
intention.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
---
 drivers/usb/host/xhci.c | 26 ++++++++++++++++----------
 1 file changed, 16 insertions(+), 10 deletions(-)

diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index dba4c61f5cf6..f2733f717568 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -1281,6 +1281,21 @@ static int xhci_check_maxpacket(struct xhci_hcd *xhci, unsigned int slot_id,
 	return ret;
 }
 
+static int xhci_num_tds_for_urb(struct urb *urb)
+{
+	if (usb_endpoint_xfer_isoc(&urb->ep->desc))
+		return urb->number_of_packets;
+
+	if (usb_endpoint_is_bulk_out(&urb->ep->desc) &&
+	    urb->transfer_buffer_length > 0 &&
+	    urb->transfer_flags & URB_ZERO_PACKET &&
+	    IS_ALIGNED(urb->transfer_buffer_length,
+			usb_endpoint_maxp(&urb->ep->desc)))
+		return 2;
+
+	return 1;
+}
+
 /*
  * non-error returns are a promise to giveback() the urb later
  * we drop ownership so next owner (or urb unlink) can get it
@@ -1327,16 +1342,7 @@ static int xhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flag
 		}
 	}
 
-	if (usb_endpoint_xfer_isoc(&urb->ep->desc))
-		num_tds = urb->number_of_packets;
-	else if (usb_endpoint_is_bulk_out(&urb->ep->desc) &&
-	    urb->transfer_buffer_length > 0 &&
-	    urb->transfer_flags & URB_ZERO_PACKET &&
-	    !(urb->transfer_buffer_length % usb_endpoint_maxp(&urb->ep->desc)))
-		num_tds = 2;
-	else
-		num_tds = 1;
-
+	num_tds = xhci_num_tds_for_urb(urb);
 	urb_priv = kzalloc(sizeof(struct urb_priv) +
 			   num_tds * sizeof(struct xhci_td), mem_flags);
 	if (!urb_priv)

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2018-04-16 12:29 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-16 12:29 [05/20] usb: host: xhci: introduce xhci_num_tds_for_urb() helper Felipe Balbi

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.