From patchwork Mon Sep 26 07:59:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jing Leng <3090101217@zju.edu.cn> X-Patchwork-Id: 12988362 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B3964C32771 for ; Mon, 26 Sep 2022 08:02:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234278AbiIZICo (ORCPT ); Mon, 26 Sep 2022 04:02:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50346 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231218AbiIZICI (ORCPT ); Mon, 26 Sep 2022 04:02:08 -0400 Received: from zg8tmtyylji0my4xnjqunzqa.icoremail.net (zg8tmtyylji0my4xnjqunzqa.icoremail.net [162.243.164.74]) by lindbergh.monkeyblade.net (Postfix) with SMTP id 763FA15A17; Mon, 26 Sep 2022 00:59:29 -0700 (PDT) Received: from jleng.ambarella.net (unknown [180.169.129.130]) by mail-app3 (Coremail) with SMTP id cC_KCgBHv6rKWzFj7OYYBw--.61426S2; Mon, 26 Sep 2022 15:59:15 +0800 (CST) From: 3090101217@zju.edu.cn To: pawell@cadence.com, gregkh@linuxfoundation.org Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Jing Leng Subject: [PATCH] usb: cdnsp: Fix wrong transmission direction of EP0 Date: Mon, 26 Sep 2022 15:59:02 +0800 Message-Id: <20220926075902.7390-1-3090101217@zju.edu.cn> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-CM-TRANSID: cC_KCgBHv6rKWzFj7OYYBw--.61426S2 X-Coremail-Antispam: 1UD129KBjvJXoW7uryrAFWfJw1DXr1xWFyUZFb_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rsilo62m3hxhgxhubq/1tbiAwQPBVNG3GzSjQAJs+ Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: Jing Leng EP0 transfer is bi-directional, but in the cdnsp gadget, the transmission direction of EP0 is not changed after it is initialized to IN, so the OUT data from EP0 received by the host is invalid. The value of ep0_expect_in will change according to the value of bRequestType in the SETUP transaction of control transfer, so we can use it as the transmission direction of EP0. Signed-off-by: Jing Leng --- drivers/usb/cdns3/cdnsp-gadget.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/usb/cdns3/cdnsp-gadget.c b/drivers/usb/cdns3/cdnsp-gadget.c index c67715f6f756..526f80651d35 100644 --- a/drivers/usb/cdns3/cdnsp-gadget.c +++ b/drivers/usb/cdns3/cdnsp-gadget.c @@ -345,6 +345,7 @@ int cdnsp_ep_enqueue(struct cdnsp_ep *pep, struct cdnsp_request *preq) { struct cdnsp_device *pdev = pep->pdev; struct usb_request *request; + u8 direction; int ret; if (preq->epnum == 0 && !list_empty(&pep->pending_list)) { @@ -355,11 +356,14 @@ int cdnsp_ep_enqueue(struct cdnsp_ep *pep, struct cdnsp_request *preq) request = &preq->request; request->actual = 0; request->status = -EINPROGRESS; - preq->direction = pep->direction; + + direction = usb_endpoint_xfer_control(pep->endpoint.desc) ? + pdev->ep0_expect_in : pep->direction; + preq->direction = direction; preq->epnum = pep->number; preq->td.drbl = 0; - ret = usb_gadget_map_request_by_dev(pdev->dev, request, pep->direction); + ret = usb_gadget_map_request_by_dev(pdev->dev, request, direction); if (ret) { trace_cdnsp_request_enqueue_error(preq); return ret; @@ -387,8 +391,7 @@ int cdnsp_ep_enqueue(struct cdnsp_ep *pep, struct cdnsp_request *preq) return 0; unmap: - usb_gadget_unmap_request_by_dev(pdev->dev, &preq->request, - pep->direction); + usb_gadget_unmap_request_by_dev(pdev->dev, &preq->request, direction); list_del(&preq->list); trace_cdnsp_request_enqueue_error(preq);