Skip to contentSkip to conversation

usb: gadget: fix wrong endpoint desc

PATCH Superseded EJ Hsu 2 participants 4 messages Dec 3, 2019 – Dec 4, 2019 USB

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

EJ Hsu

author
#0 lore raw

PATCH 1/1 usb: gadget: fix wrong endpoint desc

Gadget driver should always use config_ep_by_speed() to initialize usb_ep struct according to usb device's operating speed. Otherwise, usb_ep struct may be wrong if usb devcie's operating speed is changed.

---
 drivers/usb/gadget/function/f_ecm.c   | 4 ++++
 drivers/usb/gadget/function/f_rndis.c | 1 +
 2 files changed, 5 insertions(+)
drivers/usb/gadget/function/f_ecm.c +4 -0
index 6ce044008cf6..494fe4e38a65 100644
@@ -623,6 +623,10 @@ static void ecm_disable(struct usb_function *f)
 
 	if (ecm->port.in_ep->enabled)
 		gether_disconnect(&ecm->port);
+	else {
+		ecm->port.in_ep->desc = NULL;
+		ecm->port.out_ep->desc = NULL;
+	}
 
 	usb_ep_disable(ecm->notify);
 	ecm->notify->desc = NULL;
drivers/usb/gadget/function/f_rndis.c +1 -0
index d48df36622b7..0d8e4a364ca6 100644
@@ -618,6 +618,7 @@ static void rndis_disable(struct usb_function *f)
 	gether_disconnect(&rndis->port);
 
 	usb_ep_disable(rndis->notify);
+	rndis->notify->desc = NULL;
 }
 
 /*-------------------------------------------------------------------------*/
Signature · 1 line
2.17.1
#1 lore raw

Hi,

Quoted 3 lines · EJ Hsu

Gadget driver should always use config_ep_by_speed() to initialize usb_ep struct according to usb device's operating speed. Otherwise, usb_ep struct may be wrong if usb devcie's operating speed is changed.

your commit log doesn't match the patch body. What gives?

Quoted 11 lines
---
 drivers/usb/gadget/function/f_ecm.c   | 4 ++++
 drivers/usb/gadget/function/f_rndis.c | 1 +
 2 files changed, 5 insertions(+)
drivers/usb/gadget/function/f_ecm.c +0 -0
index 6ce044008cf6..494fe4e38a65 100644

drivers/usb/gadget/function/f_ecm.c static void ecm_disable(struct usb_function *f) · line 626

Quoted 4 lines
drivers/usb/gadget/function/f_ecm.c +1 -0
@@ -623,6 +623,10 @@ static void ecm_disable(struct usb_function *f)
 
 	if (ecm->port.in_ep->enabled)
 		gether_disconnect(&ecm->port);
+	else {

coding style. If one branch has {}, both branches should have {} ;-)

Signature · 1 line
balbi
author
#2 lore raw

Hi,

Quoted 6 lines · Felipe Balb
Quoted 3 lines · EJ Hsu

Gadget driver should always use config_ep_by_speed() to initialize usb_ep struct according to usb device's operating speed. Otherwise, usb_ep struct may be wrong if usb devcie's operating speed is changed.

your commit log doesn't match the patch body. What gives?

The key point in this patch is that we want to make sure the desc pointer in usb_ep struct will be set to NULL when gadget is disconnected. This will force it to call config_ep_by_speed() to correctly initialize usb_ep struct based on the new operating speed when gadget is re-connected later.

Quoted 13 lines
Quoted 13 lines
---
 drivers/usb/gadget/function/f_ecm.c   | 4 ++++
 drivers/usb/gadget/function/f_rndis.c | 1 +
 2 files changed, 5 insertions(+)
drivers/usb/gadget/function/f_ecm.c +0 -0
index 6ce044008cf6..494fe4e38a65 100644
@@ -623,6 +623,10 @@ static void ecm_disable(struct usb_function *f)
 
Quoted 5 lines

drivers/usb/gadget/function/f_ecm.c static void ecm_disable(struct usb_function *f) · line 626

Quoted 3 lines
drivers/usb/gadget/function/f_ecm.c +1 -0
 	if (ecm->port.in_ep->enabled)
 		gether_disconnect(&ecm->port);
+	else {

coding style. If one branch has {}, both branches should have {} ;-)

Thanks. Will correct it.

EJ
--nvpublic

#3 lore raw

Hi,

Quoted 6 lines · EJ Hsu
Quoted 5 lines · Felipe Balb
Quoted 3 lines · EJ Hsu

Gadget driver should always use config_ep_by_speed() to initialize usb_ep struct according to usb device's operating speed. Otherwise, usb_ep struct may be wrong if usb devcie's operating speed is changed.

Quoted 6 lines
Quoted 1 line

your commit log doesn't match the patch body. What gives?

The key point in this patch is that we want to make sure the desc pointer in usb_ep struct will be set to NULL when gadget is disconnected. This will force it to call config_ep_by_speed() to correctly initialize usb_ep struct based on the new operating speed when gadget is re-connected later.

this would be a commit log that matches the implementation ;-)

Signature · 1 line
balbi