From e336888c91188c870220899b19f85cd3daafe6ec Mon Sep 17 00:00:00 2001 From: Jack Pham Date: Tue, 28 Jul 2020 22:13:32 -0700 Subject: [PATCH] usb: xhci: Replace HCD_RH_RUNNING() check in xhci_stop_endpoint This function can be called to stop an endpoint handled by the secondary execution environment just after the HCD is removed (e.g. Type-C cable removal), after which the QMI sound driver proceeds to unmap transfer ring buffers from DMA. However, although the RH state indicates it is not running, the controller may not yet be fully halted and may continue to access now unmapped memory. Replace the HCD_RH_RUNNING(hcd) check with xhci_check_args() which includes a check for XHCI_STATE_HALTED, so that a Stop command can still be issued. Change-Id: Ie17882cdcfeea13fbdf7b1cd1353296d5966c798 Signed-off-by: Jack Pham --- drivers/usb/host/xhci.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index e08bb42f5c780..462b2a5f4720f 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -5399,8 +5399,9 @@ int xhci_stop_endpoint(struct usb_device *udev, struct usb_host_endpoint *ep) unsigned long flags; int ret = 0; - if (!HCD_RH_RUNNING(hcd)) - return 0; + ret = xhci_check_args(hcd, udev, ep, 1, true, __func__); + if (ret <= 0) + return ret; cmd = xhci_alloc_command(xhci, true, GFP_NOIO); if (!cmd)