xhci: Free streams when they are still allocated on a set_interface call
authorHans de Goede <hdegoede@redhat.com>
Thu, 3 Oct 2013 22:29:45 +0000 (00:29 +0200)
committerSarah Sharp <sarah.a.sharp@linux.intel.com>
Tue, 4 Mar 2014 23:38:00 +0000 (15:38 -0800)
And warn about this, as that would be a driver bug.

Like wise drivers should ensure that streams are properly free-ed before a
device is reset. So lets warn about that too. This already causes warnings
in the form of:

[   96.982398] xhci_hcd 0000:01:00.0: WARN Can't disable streams for endpoint 0x81
, streams are already disabled!
[   96.982400] xhci_hcd 0000:01:00.0: WARN xhci_free_streams() called with non-streams endpoint

But it is better to also warn about the actual cause of this later warnings.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
drivers/usb/host/xhci.c

index 6fe577d46fa2d392e586d608efc3805666ac452c..c3fa32a905ec8e2b525af3b94a95e16e4b6c8eaf 100644 (file)
@@ -2678,6 +2678,20 @@ static int xhci_configure_endpoint(struct xhci_hcd *xhci,
        return ret;
 }
 
+static void xhci_check_bw_drop_ep_streams(struct xhci_hcd *xhci,
+       struct xhci_virt_device *vdev, int i)
+{
+       struct xhci_virt_ep *ep = &vdev->eps[i];
+
+       if (ep->ep_state & EP_HAS_STREAMS) {
+               xhci_warn(xhci, "WARN: endpoint 0x%02x has streams on set_interface, freeing streams.\n",
+                               xhci_get_endpoint_address(i));
+               xhci_free_stream_info(xhci, ep->stream_info);
+               ep->stream_info = NULL;
+               ep->ep_state &= ~EP_HAS_STREAMS;
+       }
+}
+
 /* Called after one or more calls to xhci_add_endpoint() or
  * xhci_drop_endpoint().  If this call fails, the USB core is expected
  * to call xhci_reset_bandwidth().
@@ -2742,8 +2756,10 @@ int xhci_check_bandwidth(struct usb_hcd *hcd, struct usb_device *udev)
        /* Free any rings that were dropped, but not changed. */
        for (i = 1; i < 31; ++i) {
                if ((le32_to_cpu(ctrl_ctx->drop_flags) & (1 << (i + 1))) &&
-                   !(le32_to_cpu(ctrl_ctx->add_flags) & (1 << (i + 1))))
+                   !(le32_to_cpu(ctrl_ctx->add_flags) & (1 << (i + 1)))) {
                        xhci_free_or_cache_endpoint_ring(xhci, virt_dev, i);
+                       xhci_check_bw_drop_ep_streams(xhci, virt_dev, i);
+               }
        }
        xhci_zero_in_ctx(xhci, virt_dev);
        /*
@@ -2759,6 +2775,7 @@ int xhci_check_bandwidth(struct usb_hcd *hcd, struct usb_device *udev)
                if (virt_dev->eps[i].ring) {
                        xhci_free_or_cache_endpoint_ring(xhci, virt_dev, i);
                }
+               xhci_check_bw_drop_ep_streams(xhci, virt_dev, i);
                virt_dev->eps[i].ring = virt_dev->eps[i].new_ring;
                virt_dev->eps[i].new_ring = NULL;
        }
@@ -3519,6 +3536,8 @@ int xhci_discover_or_reset_device(struct usb_hcd *hcd, struct usb_device *udev)
                struct xhci_virt_ep *ep = &virt_dev->eps[i];
 
                if (ep->ep_state & EP_HAS_STREAMS) {
+                       xhci_warn(xhci, "WARN: endpoint 0x%02x has streams on device reset, freeing streams.\n",
+                                       xhci_get_endpoint_address(i));
                        xhci_free_stream_info(xhci, ep->stream_info);
                        ep->stream_info = NULL;
                        ep->ep_state &= ~EP_HAS_STREAMS;