All of lore.kernel.org
 help / color / mirror / Atom feed
From: Felipe Balbi <felipe.balbi@linux.intel.com>
To: Mathias Nyman <mathias.nyman@linux.intel.com>
Cc: Linux USB <linux-usb@vger.kernel.org>,
	Felipe Balbi <felipe.balbi@linux.intel.com>
Subject: [05/20] usb: host: xhci: introduce xhci_num_tds_for_urb() helper
Date: Mon, 16 Apr 2018 15:29:15 +0300	[thread overview]
Message-ID: <20180416122930.15697-5-felipe.balbi@linux.intel.com> (raw)

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)

                 reply	other threads:[~2018-04-16 12:29 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20180416122930.15697-5-felipe.balbi@linux.intel.com \
    --to=felipe.balbi@linux.intel.com \
    --cc=linux-usb@vger.kernel.org \
    --cc=mathias.nyman@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.