Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp382900pxj; Thu, 20 May 2021 11:30:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzLlxdp3Ku3A1ygY+YqHILhNROI3oYvr0zWHhrlCnnpWwKnSWAUqh/B8S1HQNGVC2tMzFIT X-Received: by 2002:a17:906:3181:: with SMTP id 1mr6121853ejy.36.1621535459010; Thu, 20 May 2021 11:30:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621535459; cv=none; d=google.com; s=arc-20160816; b=mZbwdBzOQe014PfWOVvsYWk/KZgdgoHOKpwrrNmweHPcGci2/54J+sUCfJAWeUGPz8 MO2kJVpwD7b9JN1UdvnTKT7oTjWq0N8uc5RpkRbdykJn9IJLFzdJmrLbUvnOm0lpXYFq MrNjk1TYwvPCX+jzsNVg/tmtevEtnBLkq4A7w67FksoEMHrLTfnmPV4/vJ1R9Yxnjlve IHUPdwkI8n22JYV61H8AZPbt7lGctPk+Yd0LNbsqUlqqgN08YU346ImwED2Vxz78eT84 ZK6uZIRRuuHQ5VolIro0pNvixu2XYMYXbMAOZsVwo5lcO82R78XO8wP96yP989LDGrk4 VJ6g== 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=EzEr4rvF+XqzwK0HVadvHrQdtmJ3r4A8Hip4ayRUkPQ=; b=L0H3qKZj8Ftq58t7CZqYsLf0bgrQrHkKuEtTPpz3C4BhP2y6AgyozOESFl/DEbmv8+ IY46/WQXuEqiHczwZCRkypIfcPsoHYiqPKO+vb2LM/nzqjTzN2MP3fDoIPeSCuMU3R4i kpLoti0xsDuj9M2sp139OJ28YAjBTpol3CyP0Pk3T3m3+p3jgD3+azVjHklFP7fiwv6h rdxvEkPstsIempVG3p4J+320G8jo/d2YMNlTCmqjsPE7Ofn0rWVVy6YvfYUnr7YZ0Vtv FAVjzyi1X2ydqzepEErPIe09kz0ISNQvKNvFI6h4FGXykQw+F8QsS52rTqdIXlo/ggG6 XQlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Xwdk3jRF; 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 g9si2749854edq.588.2021.05.20.11.30.33; Thu, 20 May 2021 11:30:58 -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=Xwdk3jRF; 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 S236412AbhETKTe (ORCPT + 99 others); Thu, 20 May 2021 06:19:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:43768 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236012AbhETKKF (ORCPT ); Thu, 20 May 2021 06:10:05 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id CCC576195D; Thu, 20 May 2021 09:42:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621503778; bh=lIz8Nf3lLmW0pcCSsUe+wdheObD3U1x2/N9RemF0Okc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Xwdk3jRFJNFMsFYYdnI3Ci5MP0MionJ3BBEI0zN2eSdp3kJUCVnhxapQNKUUre5fG Sq4DfmgPHUT/W6qGMUTv/TPhetcpuqgT1rwPVwsTL11LtJ3vlTtMoKQPnSw/5xsSm3 MIgk7X3TkoOV8hmgZe0OvKIU/VuQCfYGg64c4rGY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Minas Harutyunyan , Phil Elwell Subject: [PATCH 4.19 376/425] usb: dwc2: Fix gadget DMA unmap direction Date: Thu, 20 May 2021 11:22:25 +0200 Message-Id: <20210520092143.750637861@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092131.308959589@linuxfoundation.org> References: <20210520092131.308959589@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 @@ -380,7 +380,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); } /* @@ -1163,6 +1163,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;