Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp398319pxj; Tue, 18 May 2021 06:02:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzRccyG+0ii/uWuQAiyXJcuLpko15snITM6/+e6SCX08S2dYvHv9w/wT6CUGtHdO9Q2z4BY X-Received: by 2002:aa7:d58b:: with SMTP id r11mr6989436edq.231.1621342938336; Tue, 18 May 2021 06:02:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621342938; cv=none; d=google.com; s=arc-20160816; b=KBHmLT2b9qX/y8SUZz2/op62f4VJQ0JRU6IVOs0QwWKmnHg2eH7gi8rXVZvhZEgFSe nJs2Hzz+SC84OuLlkWlEbHfP6nPsUMmBDBwcDYTU1Q2Is1Snx30xucCz8DPnRQWQ9xax WYPLsZeNnGsi3ilAM9n6LUUVXeKyr7PFfXQZ4g9ByYHQ2Q/XyQ5eVk3r7Whb/9xAOeFE DMqZJ2Nx8eqfeDq3mrIuGEi7v4zNL8Fn8zds3jL2V7kS0rgvg+8mpH4dpHwA9JsxfiJk P0VtUrhciPKasROo7PyKuoTQ9K5JS+whxRs6mUxtKV+p4SssDErkbJYQfFzR6SpmRQWy ucAA== 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=XuG0COIiSbped7fUp6VlHSGSrZde1JrbJDqZRMpMy+4=; b=bLJyeTpn8NFzMvDw4P/mi3OC0xG6FBp4CYHw/jUKD7a8y9/DYbFlAe/0YumQuvDmcd dV5ORKaT4t+VxUnzuDXVTrWXJwKvrTzAWUFdGvk+rpxZ/8ab46KpQ8aqt4uQ/4pYA4qk atVCiADjxvlqVaTd5uy3jhmJqb0P3Puc3rVXvhddXuWx/K6okQ40cvcHAHrjpg9jqfsj 6k22Z8au28IbfbRcy52tdox99glAlD+1NYxk8GA8Tq7ZaPVhn23zgJtHznxt2SCZ+yMt 4Kle4h7jV2Mj7yLBzwogI5lKwFZx3H3eeF2PbK3nDFKHO8Q3EfYXAddhOgwHADI6OHfM JTDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=fWdK6Kwj; 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 m26si18915218edp.58.2021.05.18.06.01.54; Tue, 18 May 2021 06:02:18 -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=fWdK6Kwj; 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 S243664AbhEQPf1 (ORCPT + 99 others); Mon, 17 May 2021 11:35:27 -0400 Received: from mail.kernel.org ([198.145.29.99]:55932 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244427AbhEQPUj (ORCPT ); Mon, 17 May 2021 11:20:39 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id BD5FC61C88; Mon, 17 May 2021 14:34:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621262061; bh=sVFnVSZ/6fdfB41yv0+eSarSSZo9WQXQoHoeZlTjde8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fWdK6Kwj2M1S2dJpKPhe1t7jV9X8CdBM/2T0lQ4IWrBKaJ1PiI5c07yMW7mJWURie 7f8TTyCNUHxTsmgnJNSDGzWHQjE1xN6oRxBSu36GoUKf9k+z24lsV5c8h9PLrw6xhS BJjNnuV+fTQ0hrITVuNm1hcULc6CJ4G9Tt7lNBfQ= 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.4 116/141] usb: dwc2: Fix gadget DMA unmap direction Date: Mon, 17 May 2021 16:02:48 +0200 Message-Id: <20210517140246.702936517@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140242.729269392@linuxfoundation.org> References: <20210517140242.729269392@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 @@ -421,7 +421,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;