diff mbox series

usb: cdnsp: Fix wrong transmission direction of EP0

Message ID 20220926075902.7390-1-3090101217@zju.edu.cn (mailing list archive)
State Superseded
Headers show
Series usb: cdnsp: Fix wrong transmission direction of EP0 | expand

Commit Message

Jing Leng Sept. 26, 2022, 7:59 a.m. UTC
From: Jing Leng <jleng@ambarella.com>

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 <jleng@ambarella.com>
---
 drivers/usb/cdns3/cdnsp-gadget.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

Comments

Greg Kroah-Hartman Oct. 8, 2022, 3:40 p.m. UTC | #1
On Mon, Sep 26, 2022 at 03:59:02PM +0800, 3090101217@zju.edu.cn wrote:
> From: Jing Leng <jleng@ambarella.com>
> 
> 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 <jleng@ambarella.com>

Your email does not match your From: line and the signature of it shows
that it is invalid and does not pass authentication :(

Please work with your university to get an email address that works
properly.

thanks,

greg k-h
diff mbox series

Patch

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);