[PATCH 05/20] usb: host: xhci: introduce xhci_num_tds_for_urb() helper

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxxx>
---
 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)
-- 
2.16.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux