Return-Path: Received: from mga11.intel.com ([192.55.52.93]:27468 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728002AbeKJA7U (ORCPT ); Fri, 9 Nov 2018 19:59:20 -0500 From: Mathias Nyman To: Cc: usb-linus@vger.kernel.org, Mathias Nyman , stable@vger.kernel.org Subject: [PATCH 2/6] xhci: handle port status events for removed USB3 hcd Date: Fri, 9 Nov 2018 17:21:18 +0200 Message-Id: <1541776882-26417-3-git-send-email-mathias.nyman@linux.intel.com> In-Reply-To: <1541776882-26417-1-git-send-email-mathias.nyman@linux.intel.com> References: <1541776882-26417-1-git-send-email-mathias.nyman@linux.intel.com> Sender: stable-owner@vger.kernel.org List-ID: 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 the shared_hcd is freed, causing NULL pointer dereference. Check if xhci->shared_hcd is still valid before handing USB3 port events Cc: Reported-by: Peter Chen Tested-by: Jack Pham Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci-ring.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index a8d92c9..80d464e 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -1556,6 +1556,13 @@ static void handle_port_status(struct xhci_hcd *xhci, goto cleanup; } + /* 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; -- 2.7.4