Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp1358029ybi; Wed, 17 Jul 2019 13:54:15 -0700 (PDT) X-Google-Smtp-Source: APXvYqwabHy5YZqI9RlQWxAVYYnzAtljwJY+pbD5TQW77LS3U5KcHXPaih33KKqvEuM9MqacSpQt X-Received: by 2002:a17:902:b68f:: with SMTP id c15mr46115922pls.104.1563396855493; Wed, 17 Jul 2019 13:54:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563396855; cv=none; d=google.com; s=arc-20160816; b=dDcYVSe2lAupx7IyZsTnaspFaalcJdbgrbSgt/5K44PUNrPd20l4TWq45OZW2Ubh3J 5OK+762MFNY7nrJhJq6DY/qRLrMDq4TrKSpb5N0K4iX9ORNB/pu9F2j87NJJGSaIQtoW 86G6fhcCcxvXCZkQ3Z/2/pUUHdvhGKLSWi7obzzbEmoxQvAHffd5g1pEugMsj0HzEzP/ NJCgEf3F7g3ZmJZY6trj3EPPxOYI0FHutFeaEPa2fWnHCNT+BAQfy+xDPbdNai1c2bpQ yFgZdXHg8IeK5IqxPvZ1Myo9lMR1jkcbdcwNoPbxU5TjVX8ZP3xOnWEbBisjvgeBTvLp PPOw== 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=YwMAGsdydF8e0/DxoMWpSr0uNj4VB7DbxhuYVsVrimw=; b=0MijAk0mpoOHBAReE350saD1nXtjhoXgm083+gpitk3uwHPF27D43lBMoLVNbGvtxk I6GNBu8q7p0KLXZgBQdLjuhpHDW/srH44ZHgIaasefjRJJzfmxEd8QQuCS5GJ0hIpeUV BzvovB8hIdgsxIaKHLrx8+7QOrmKvIzMx0/3wO0IstIISIUWUUCB6YOshozHfRnuiDmm 4P/tpDIRCitSgCxkO4PQR7qJrWgmtW+/Dgrer6G8VAJPKc3ya1M9kH7J9kbHS8hiHPne MMYlav6DSaazCVug3qt+JWaUMJg7E0HJlbswMQ+ujd9q6rQKLF2hZIhU9uimKG1Wj61G boFQ== 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 f9si19801pgc.510.2019.07.17.13.53.58; Wed, 17 Jul 2019 13:54:15 -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 S1727562AbfGQUxS (ORCPT + 99 others); Wed, 17 Jul 2019 16:53:18 -0400 Received: from mga09.intel.com ([134.134.136.24]:32450 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726063AbfGQUxS (ORCPT ); Wed, 17 Jul 2019 16:53:18 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 17 Jul 2019 13:53:17 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,275,1559545200"; d="scan'208";a="170366132" Received: from fei-dev-host.jf.intel.com ([10.7.198.158]) by orsmga003.jf.intel.com with ESMTP; 17 Jul 2019 13:53:17 -0700 From: fei.yang@intel.com To: felipe.balbi@linux.intel.com, john.stultz@linaro.org, andrzej.p@collabora.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org, stable@vger.kernel.org Subject: [PATCH V2] usb: dwc3: gadget: trb_dequeue is not updated properly Date: Wed, 17 Jul 2019 13:53:08 -0700 Message-Id: <1563396788-126034-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 would be 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, dwc3_gadget_ep_reclaim_completed_trb() would be called only once for the whole USB request, thus all the TRBs need to be reclaimed within this single call. However that is not what the current code does. This patch addresses the issue by checking each TRB in function dwc3_gadget_ep_reclaim_trb_sg() and reclaiming the chained ones right there. Only the last TRB gets passed to dwc3_gadget_ep_reclaim_completed_trb(). This would guarantee all TRBs are reclaimed and trb_dequeue/num_trbs are updated properly. Signed-off-by: Fei Yang Cc: stable --- V2: Better solution is to reclaim chained TRBs in dwc3_gadget_ep_reclaim_trb_sg() and leave the last TRB to the dwc3_gadget_ep_reclaim_completed_trb(). --- drivers/usb/dwc3/gadget.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 173f532..c0662c2 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -2404,7 +2404,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; @@ -2419,7 +2419,15 @@ static int dwc3_gadget_ep_reclaim_trb_sg(struct dwc3_ep *dep, req->sg = sg_next(s); req->num_pending_sgs--; + if (!(trb->ctrl & DWC3_TRB_CTRL_IOC)) { + /* reclaim the TRB without calling + * dwc3_gadget_ep_reclaim_completed_trb */ + dwc3_ep_inc_deq(dep); + req->num_trbs--; + continue; + } + /* Only the last TRB in the sg list would reach here */ ret = dwc3_gadget_ep_reclaim_completed_trb(dep, req, trb, event, status, true); if (ret) -- 2.7.4