Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp105079ybi; Tue, 16 Jul 2019 17:08:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqwIBGZPS/mLeqS1R1XifMafcubGKMHMtdUU87w/VsDS+ZYxueCysnnZQG14n5matXz4wpgE X-Received: by 2002:a65:6114:: with SMTP id z20mr37827897pgu.141.1563322090667; Tue, 16 Jul 2019 17:08:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563322090; cv=none; d=google.com; s=arc-20160816; b=dIa/xhlc78LEQMmNvw19jpsn0IqLtPLV1qT70q4E5Msn8USVZiGiyEn2BCHnfOU1cz xPuWi/9Ka/qf/K+wGR1Yh8kOQeSJGatrZnpoQ30ndQI8HjFe/D3BclOpVNWodTXTwPWz hOMp/xfex9cnQpnvpTR4ZOKu8yr2rQeCVPQa+8Zch87iPGrqrbCM0kH4rvL9z9swZFZ/ cbuZaQkTklDN+RvMAKvQjIrjEJYiTrJRCeL2vM1wyuN7g9X6muVAbiyuaDMucqoMS7gX 8kM9U2FBiz8E2eCVX03AyV1mhvEnb5tJCCLD1JnDn4zUvu+eu4jbpqPEqd/3s2YBeuYN Ruxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:to:from; bh=Qfd0UVt8nvG22mAgXbn7BgAMArFSVHpDZT6BR06TVuM=; b=c9eszcqNL44xkTz+kwSxC2Mkb7zVzPQRH8nG04omLhHKwJGHLBHOXa2pkGzMT3MKKn hnsNn4QDweV8jQjMRSfCyLd6YtE7MUH5w0rL4D6+9ltMqw+4XrdawRdzPE1CNMF5oHVt iI0Cc6MCmTSNLIB2V++j+ETPLkkHdvkauO4TGZhruxccERN/MmoCYE9p569p1c2Ron8u 4pyn6zi3mBkEqG7660gPjOggjaPHRl9gD2tIux3BPTxY5L/HZP6IKn5Rs+AadaJhWN5F WHbbuwHwFbC4dQ0SdRhs9aNHMqeXI11NYeo5ulvkJVtHQwt1ur6COGgNQDSOe2IGX2LN Im3w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c70si23227449pfc.270.2019.07.16.17.07.53; Tue, 16 Jul 2019 17:08:10 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388749AbfGQAHe (ORCPT + 99 others); Tue, 16 Jul 2019 20:07:34 -0400 Received: from mga09.intel.com ([134.134.136.24]:42048 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728597AbfGQAHd (ORCPT ); Tue, 16 Jul 2019 20:07:33 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Jul 2019 17:07:33 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,272,1559545200"; d="scan'208";a="172698735" Received: from fei-dev-host.jf.intel.com ([10.7.198.158]) by orsmga006.jf.intel.com with ESMTP; 16 Jul 2019 17:07:33 -0700 From: fei.yang@intel.com To: felipe.balbi@linux.intel.com, john.stultz@linaro.org, andrzej.p@samsung.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org, stable@vger.kernel.org Subject: [PATCH] usb: dwc3: gadget: trb_dequeue is not updated properly Date: Tue, 16 Jul 2019 17:07:25 -0700 Message-Id: <1563322045-49515-1-git-send-email-fei.yang@intel.com> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Fei Yang If scatter-gather operation is allowed, a large USB request is split into multiple TRBs. These TRBs are chained up by setting DWC3_TRB_CTRL_CHN bit except the last one which has DWC3_TRB_CTRL_IOC bit set instead. Since only the last TRB has IOC set for the whole USB request, the dwc3_gadget_ep_reclaim_completed_trb() gets called only once for the request and all TRBs are supposed to be reclaimed. However that is not what happens with the current code. This patch addresses the issue by checking req->num_pending_sgs. In case the pending sgs is not zero, update trb_dequeue and req->num_trbs accordingly. Signed-off-by: Fei Yang Cc: stable --- drivers/usb/dwc3/gadget.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 173f532..4d5b4eb 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -2394,8 +2394,14 @@ static int dwc3_gadget_ep_reclaim_completed_trb(struct dwc3_ep *dep, if (event->status & DEPEVT_STATUS_SHORT && !chain) return 1; - if (event->status & DEPEVT_STATUS_IOC) + if (event->status & DEPEVT_STATUS_IOC) { + for (count = 0; count < req->num_pending_sgs; count++) { + dwc3_ep_inc_deq(dep); + req->num_trbs--; + } + req->num_pending_sgs = 0; return 1; + } return 0; } @@ -2404,7 +2410,7 @@ static int dwc3_gadget_ep_reclaim_trb_sg(struct dwc3_ep *dep, struct dwc3_request *req, const struct dwc3_event_depevt *event, int status) { - struct dwc3_trb *trb = &dep->trb_pool[dep->trb_dequeue]; + struct dwc3_trb *trb; struct scatterlist *sg = req->sg; struct scatterlist *s; unsigned int pending = req->num_pending_sgs; -- 2.7.4