Skip to contentSkip to conversation

usb: gadget: fix wrong endpoint desc

PATCH In review EJ Hsu 1 participant 2 messages Dec 4, 2019 – Dec 6, 2019 USB

lore
Share & tools
lore

EJ Hsu

author
#0 lore raw

PATCH v3 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.

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.

---
v2: fix the coding style
v3: fix the typo

---
 drivers/usb/gadget/function/f_ecm.c   | 6 +++++-
 drivers/usb/gadget/function/f_rndis.c | 1 +
 2 files changed, 6 insertions(+), 1 deletion(-)
drivers/usb/gadget/function/f_ecm.c +5 -1
index 6ce044008cf6..460d5d7c984f 100644
@@ -621,8 +621,12 @@ static void ecm_disable(struct usb_function *f)
 
 	DBG(cdev, "ecm deactivated\n");
 
-	if (ecm->port.in_ep->enabled)
+	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
author Reviewed-by Peter Chen on v3 1/1
#1 lore raw

Add a "Reviewed-by" from Peter since this patch has been reviewed in v2 and only typo fix in v3.

Thanks,
EJ
--nvpublic