Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp630699pxj; Tue, 18 May 2021 10:36:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx2XXaA4cjWdKbs63aTQS2wr+D6d5+E6VXq0zjUZsVUEjadyyeK6MG4wqiXCLxYhGNcuPhI X-Received: by 2002:a17:906:6ad0:: with SMTP id q16mr7387958ejs.286.1621359360303; Tue, 18 May 2021 10:36:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621359360; cv=none; d=google.com; s=arc-20160816; b=VEmrajsIsrqnCEDdozLmo00IoTtdJDjRgIWFcgwfkSj0iXjW557dBx7VP/26BxwMgT +ky2ber3nSPL6HJWETUEjdSAEl2ru+G3JfzbuWurks3IU4g5aLoMAW9xJ0j+RzGOqFA/ +497cAjZ3ad5M2R+1cu54DnozUgTTBNKtXxPNy2jL2BZAq1a+E2qaTjmT8UMOwvgfaRv xLDpFd6f3EyWhlZVsCHNr+NKQI4ZhtTSgSczF7V2j42LEs+DFLtw7HxwV74rl/cvrbyu 03bAl4zPuR8ugdw3BT7GG6xtv4LHaQBHXjbJPGQW0WMrxbP426yLulQ01KOtCQSRYYv/ V9mA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=F3yGL+UIm2L53BQQE+0Laf1TJe5L0xe5PECgVrA/a7w=; b=IlKLPkFPM+CDg9JOqoHyffDH1cLw+V1oYvtN7P1iXl2VBtt8it3drhQT+o2KTYHA3F npfebBE3qXCX3rSIytA5oGsHYd+b5Wo/6+iiSaEc9blNE7ufClx+AGUbvp1cHJ6dVHUa dJ/tETurT7hHrJdHff8NQfUajuBYQH9+j6zqwKTI32HqVLF7DmwAzKL6FjOOZPSizLeb poT1jduejvBkK/gQc3sSCab5CGncRDvtwNXUMhU0tyeRqXiUVW7u+N3SvRsPuD7o3P+F 5b3jJmiS/J0D0z3OjbtDIGjCTxJ0aC+Q2TwsPsGw2l9wI+q1GEa6si8tXPCmGnf3PIQ6 yeeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=mzRjI2YB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v20si17925375edc.437.2021.05.18.10.35.29; Tue, 18 May 2021 10:36:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=mzRjI2YB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344154AbhEQQJD (ORCPT + 99 others); Mon, 17 May 2021 12:09:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:33864 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344832AbhEQPpn (ORCPT ); Mon, 17 May 2021 11:45:43 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 32AB7613B5; Mon, 17 May 2021 14:44:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621262641; bh=QKOQY0rDLrRV2h/d3hQ+p73SyJPmWV9nPG9rkGfSOsc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mzRjI2YBuY5QbW6QQ4G0+Ez7fUr/Y6iedWikCLujTtQa+pKwFyRyBbLZJCcJdlf5j 3ncI7iWc6HhtVqi8FXm1Qs8ioenU3US/3W/EUk0SMVERPw2PmFi2LflT1miaylmn4e LcPa51GkF2wum82XZatedgWZAh2o5qnRc1rcYovg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Minas Harutyunyan , Phil Elwell Subject: [PATCH 5.10 243/289] usb: dwc2: Fix gadget DMA unmap direction Date: Mon, 17 May 2021 16:02:48 +0200 Message-Id: <20210517140313.339040098@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140305.140529752@linuxfoundation.org> References: <20210517140305.140529752@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Phil Elwell commit 75a41ce46bae6cbe7d3bb2584eb844291d642874 upstream. The dwc2 gadget support maps and unmaps DMA buffers as necessary. When mapping and unmapping it uses the direction of the endpoint to select the direction of the DMA transfer, but this fails for Control OUT transfers because the unmap occurs after the endpoint direction has been reversed for the status phase. A possible solution would be to unmap the buffer before the direction is changed, but a safer, less invasive fix is to remember the buffer direction independently of the endpoint direction. Fixes: fe0b94abcdf6 ("usb: dwc2: gadget: manage ep0 state in software") Acked-by: Minas Harutyunyan Cc: stable Signed-off-by: Phil Elwell Link: https://lore.kernel.org/r/20210506112200.2893922-1-phil@raspberrypi.com Signed-off-by: Greg Kroah-Hartman --- drivers/usb/dwc2/core.h | 2 ++ drivers/usb/dwc2/gadget.c | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) --- a/drivers/usb/dwc2/core.h +++ b/drivers/usb/dwc2/core.h @@ -112,6 +112,7 @@ struct dwc2_hsotg_req; * @debugfs: File entry for debugfs file for this endpoint. * @dir_in: Set to true if this endpoint is of the IN direction, which * means that it is sending data to the Host. + * @map_dir: Set to the value of dir_in when the DMA buffer is mapped. * @index: The index for the endpoint registers. * @mc: Multi Count - number of transactions per microframe * @interval: Interval for periodic endpoints, in frames or microframes. @@ -161,6 +162,7 @@ struct dwc2_hsotg_ep { unsigned short fifo_index; unsigned char dir_in; + unsigned char map_dir; unsigned char index; unsigned char mc; u16 interval; --- a/drivers/usb/dwc2/gadget.c +++ b/drivers/usb/dwc2/gadget.c @@ -422,7 +422,7 @@ static void dwc2_hsotg_unmap_dma(struct { struct usb_request *req = &hs_req->req; - usb_gadget_unmap_request(&hsotg->gadget, req, hs_ep->dir_in); + usb_gadget_unmap_request(&hsotg->gadget, req, hs_ep->map_dir); } /* @@ -1242,6 +1242,7 @@ static int dwc2_hsotg_map_dma(struct dwc { int ret; + hs_ep->map_dir = hs_ep->dir_in; ret = usb_gadget_map_request(&hsotg->gadget, req, hs_ep->dir_in); if (ret) goto dma_error;