xhci: handle port status events for removed USB3 hcd
Subsystems (3)
PATCH 2/2 xhci: handle port status events for removed USB3 hcd
Quoted 22 lines · Mathias Nyman
At xhci removal the USB3 hcd (
shared_hcd) is removed before the primary USB2 hcd. Interrupts for port status changes may still occur for USB3 ports after theshared_hcdis freed, causing NULL pointer dereference.Check if
xhci->shared_hcdis still valid before handing USB3 port eventsCc <[email protected]>Reported-by Peter Chen <[email protected]>Signed-off-by Mathias Nyman <[email protected]>--- drivers/usb/host/xhci-ring.c | 7 +++++++ 1 file changed, 7 insertions(+)drivers/usb/host/xhci-ring.c +0
-0@@ -1552,6 +1552,13 @@ static void handle_port_status(struct xhci_hcd *xhci, goto cleanup; }
drivers/usb/host/xhci-ring.c static void handle_port_status(struct xhci_hcd *xhci, · line 1564
Quoted 10 lines
drivers/usb/host/xhci-ring.c +7
-0+/* We might get interrupts after shared_hcd is removed */ +if (port->rhub == &xhci->usb3_rhub && xhci->shared_hcd ==NULL ) { +xhci_dbg (xhci,"ignore port event for removed USB3 hcd\n" ); + bogus_port_status = true; + goto cleanup; + } + hcd = port->rhub->hcd; bus_state = &xhci->bus_state[hcd_index (hcd)]; hcd_portnum = port->hcd_portnum;
This probably only applies from 4.18 onwards, to test on older kernel try something like this instead:
Jack, Peter, do these patches solve the remove issues you are seeing?
Thanks
-Mathias
drivers/usb/host/xhci-ring.c +4 -1
@@ -1606,7 +1606,11 @@ static void handle_port_status(struct xhci_hcd *xhci, hcd =xhci_to_hcd (xhci);if ((major_revision ==0x03 ) != (hcd->speed >=HCD_USB3 )) hcd = xhci->shared_hcd; - +if (!hcd) { + bogus_port_status = true; + goto cleanup; + }if (major_revision ==0 ) { xhci_warn(xhci, "Event for port %u not in " "Extended Capabilities, ignoring.\n",