Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp475115rwb; Mon, 26 Sep 2022 01:17:06 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5TRa7OrpJMIqoHILp/pokoj5XTp0gxS+dLVmVaNtvwJEiIEu8qkzCG8jyVAwFbuRpEp9xd X-Received: by 2002:a17:90b:78e:b0:205:c9ae:21f9 with SMTP id l14-20020a17090b078e00b00205c9ae21f9mr207326pjz.112.1664180226279; Mon, 26 Sep 2022 01:17:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664180226; cv=none; d=google.com; s=arc-20160816; b=NAMJs89XjEoXhHNPC/YEhw4o3DeeRhLsCvK+JeRKt/BDpkmlhA9C8w/cV6BZfXyCxb fVWZfuS/6+XmBu9s1/mIUGE7zFI/nlfsjCZrLqPa6I1mDHSRbD+gbqCZ/8V07KW006la 6f0/eWlO2qXhAbteiBBo+aVMk+lbVC2QduU9XUiimcApdOYgJAQgF0k5sMy8SNmTMu7c 58/3X3s9VVTlgJD7M/1o6LEu3S2VNFe94686Eztvm0kWAhnymfyd4jz6UThPDZPDAt/X cHrFT3ChZDVZbkybkNL3rGX5ni34pPo1Vj0BgKkCGPeaddXa0YFytjtt4xol6xrrRrjZ qZeA== 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 :message-id:date:subject:cc:to:from; bh=mF07PLy4NG67OPemADvYKNwgC7o+YDlUASjEPzT6GQM=; b=GwPhfmyTFYJhdtSYCA2iSItBR9D3xgWk1f+LKKQYDutfT++XiOgLZ3MQcH0CEzQLM4 Skt1yytonnKl+prHIh3Vfe445n6TPtSBfUtZusUkPKkIOgWLxt+8hF6VmrYonypXHMUQ 5Ih1ivu7DOYssjHSTv6Lkp9aSN9/85VeCTiF2fCNpUL4d1etTxLkYuJGcYFJ9MHfsZOb HUOztSw6dIleL5ymWsSaN4rlePG8v4TEnJbP8smKbPogL29SqrDf63Q8MKUAiaHVV7Op NBaugqXwQYFd/t2lH0XqNmHNlcpb6SiARXIGKM/Hg6P1aSgHN2a3ITeWKWQqfLczUn/F 4bRw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j5-20020a637a45000000b0043a56cc100dsi16885097pgn.593.2022.09.26.01.16.55; Mon, 26 Sep 2022 01:17:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233151AbiIZICy (ORCPT + 99 others); Mon, 26 Sep 2022 04:02:54 -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 Content-Transfer-Encoding: 8bit X-CM-TRANSID: cC_KCgBHv6rKWzFj7OYYBw--.61426S2 X-Coremail-Antispam: 1UD129KBjvJXoW7uryrAFWfJw1DXr1xWFyUZFb_yoW8ury8pr 4UCFZIkrs3Jr43Ar92gF4DZa1akFs7CF17Jr1vk3ZxZrs3uw4vyFn8KFyjgF47CFWrAr4j ga1DGFs7XF4jvFDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUBIb7Iv0xC_Cr1lb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I2 0VC2zVCF04k26cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rw A2F7IY1VAKz4vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xII jxv20xvEc7CjxVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv67AKxVW0oVCq3wA2z4x0Y4vEx4 A2jsIEc7CjxVAFwI0_GcCE3s1lnxkEFVAIw20F6cxK64vIFxWlnxkEFVCFx7IYxxCEVcI2 5VAKI4IrM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMc Ij6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_ Jr0_Gr1lF7xvr2IYc2Ij64vIr41lw4CEc2x0rVAKj4xxMxkIecxEwVAFwVW8CwCF04k20x vY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I 3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_JF0_Jw1lIxkGc2Ij64vIr41lIx AIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Jr0_Gr1lIxAI cVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2js IEc7CjxVAFwI0_Jr0_GrUvcSsGvfC2KfnxnUUI43ZEXa7IU8MrW5UUUUU== X-CM-SenderInfo: qtqziiyqrsilo62m3hxhgxhubq/1tbiAwQPBVNG3GzSjQAJs+ X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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); -- 2.34.1