Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756922AbcLTGAN (ORCPT ); Tue, 20 Dec 2016 01:00:13 -0500 Received: from mail-pf0-f173.google.com ([209.85.192.173]:35800 "EHLO mail-pf0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755716AbcLTGAL (ORCPT ); Tue, 20 Dec 2016 01:00:11 -0500 From: Baolin Wang To: mathias.nyman@intel.com, gregkh@linuxfoundation.org Cc: baolu.lu@linux.intel.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, broonie@kernel.org, baolin.wang@linaro.org, linaro-kernel@lists.linaro.org Subject: [PATCH v2 2/2] usb: host: xhci: Handle the right timeout command Date: Tue, 20 Dec 2016 13:59:51 +0800 Message-Id: <99414f74354db54aa4637ef82b0f491762219b98.1482212656.git.baolin.wang@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1576 Lines: 38 If a command event is found on the event ring during an interrupt, we need to stop the command timer with del_timer(). Since del_timer() can fail if the timer is running and waiting on the xHCI lock, then it maybe get the wrong timeout command in xhci_handle_command_timeout() if host fetched a new command and updated the xhci->current_cmd in handle_cmd_completion(). For this situation, we need a way to signal to the command timer that everything is fine and it should exit. We should check if the command timer is pending in xhci_handle_command_timeout() function, if the command timer is pending, which means current timeout command has been handled by host and host has fetched new command and re-added the command timer, then just return and wait for new current command. If not, it means current command is timeout and need to be handled. Signed-off-by: Baolin Wang --- Changes since v1: - Remove the counter and just check if the command timer is pending. --- drivers/usb/host/xhci-ring.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index 9965a4c..3947344 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -1269,7 +1269,7 @@ void xhci_handle_command_timeout(unsigned long data) xhci = (struct xhci_hcd *) data; spin_lock_irqsave(&xhci->lock, flags); - if (!xhci->current_cmd) { + if (!xhci->current_cmd || timer_pending(&xhci->cmd_timer)) { spin_unlock_irqrestore(&xhci->lock, flags); return; } -- 1.7.9.5