Similar to previous patch on process_ctrl_td(), we can also clean up
process_bulk_intr_td() and turn it into an easier to read and maintain
function.

This patch shuffles code around, defines each variable in one line,
removes unnecessary debugging messages and an unnecessary goto
statement.

Signed-off-by: Felipe Balbi <felipe.ba...@linux.intel.com>
---
 drivers/usb/host/xhci-ring.c | 52 +++++++++++++++++++-------------------------
 1 file changed, 22 insertions(+), 30 deletions(-)

diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index 607bd2d2ab11..49712beef328 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -2110,58 +2110,50 @@ static int process_bulk_intr_td(struct xhci_hcd *xhci, 
struct xhci_td *td,
        struct xhci_virt_ep *ep, int *status)
 {
        struct xhci_ring *ep_ring;
-       struct device *dev;
        u32 trb_comp_code;
-       u32 remaining, requested, ep_trb_len;
+       u32 ep_trb_len;
+       u32 remaining;
+       u32 requested;
 
        ep_ring = xhci_dma_to_transfer_ring(ep, le64_to_cpu(event->buffer));
        trb_comp_code = GET_COMP_CODE(le32_to_cpu(event->transfer_len));
        remaining = EVENT_TRB_LEN(le32_to_cpu(event->transfer_len));
        ep_trb_len = TRB_LEN(le32_to_cpu(ep_trb->generic.field[2]));
        requested = td->urb->transfer_buffer_length;
-       dev = xhci_to_hcd(xhci)->self.controller;
+
+       if (ep_trb == td->last_trb)
+               td->urb->actual_length = requested - remaining;
+       else
+               td->urb->actual_length =
+                       sum_trb_lengths(xhci, ep_ring, ep_trb) +
+                       ep_trb_len - remaining;
 
        switch (trb_comp_code) {
        case COMP_SUCCESS:
-               dev_WARN_ONCE(dev, (ep_trb != td->last_trb) || remaining,
-                               "ep%d%s: unexpected success! TRB %p/%p size 
%d/%d\n",
-                               usb_endpoint_num(&td->urb->ep->desc),
-                               usb_endpoint_dir_in(&td->urb->ep->desc) ?
-                               "in" : "out", ep_trb, td->last_trb, remaining,
-                               requested);
-               *status = 0;
-               break;
        case COMP_SHORT_PACKET:
-               xhci_dbg(xhci, "ep %#x - asked for %d bytes, %d bytes 
untransferred\n",
-                        td->urb->ep->desc.bEndpointAddress,
-                        requested, remaining);
                *status = 0;
                break;
        case COMP_STOPPED_SHORT_PACKET:
+               /*
+                * NOTICE: according to section 6.4.2 Table 91 of xHCI rev 1.1
+                * Specification, if completion code is Stopped - Short Packet,
+                * Transfer Length field (referred to as 'remaining' here)
+                * contain the value of EDTLA (see section 4.11.5.2 for
+                * details), which means that remaining contains actual_length,
+                * not the amount of bytes remaining to be transferred as usual.
+                */
                td->urb->actual_length = remaining;
-               goto finish_td;
+               *status = -ESHUTDOWN;
+               break;
        case COMP_STOPPED_LENGTH_INVALID:
-               /* stopped on ep trb with invalid length, exclude it */
-               ep_trb_len      = 0;
-               remaining       = 0;
+               td->urb->actual_length = 0;
+               *status = -ESHUTDOWN;
                break;
        default:
                /* do nothing */
                break;
        }
 
-       if (ep_trb == td->last_trb)
-               td->urb->actual_length = requested - remaining;
-       else
-               td->urb->actual_length =
-                       sum_trb_lengths(xhci, ep_ring, ep_trb) +
-                       ep_trb_len - remaining;
-finish_td:
-       if (remaining > requested) {
-               xhci_warn(xhci, "bad transfer trb length %d in event trb\n",
-                         remaining);
-               td->urb->actual_length = 0;
-       }
        return finish_td(xhci, td, ep_trb, event, ep, status, false);
 }
 
-- 
2.10.1

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

Reply via email to