[PATCH 5/6] usb: gadget: Add full ep_matches() check past .match_ep() callback

Marek Vasut marek.vasut+renesas at mailbox.org
Sun Jun 9 23:32:18 CEST 2024


If .match_ep() callback returns non-NULL endpoint, immediately check
its usability and if the returned endpoint is usable, stop search and
return the endpoint. Otherwise, continue with best effort search for
usable endpoint.

Currently the code would attempt the best effort search in any case,
which may find another unexpected endpoint. It is likely that the
intention of the original code was to stop the search early.

Fixes: 77dcbdf3c1ce ("usb: gadget: Add match_ep() op to usb_gadget_ops")
Signed-off-by: Marek Vasut <marek.vasut+renesas at mailbox.org>
---
Cc: Alexander Sverdlin <alexander.sverdlin at siemens.com>
Cc: Felipe Balbi <felipe.balbi at linux.intel.com>
Cc: Lukasz Majewski <lukma at denx.de>
Cc: Mattijs Korpershoek <mkorpershoek at baylibre.com>
Cc: Nishanth Menon <nm at ti.com>
Cc: Simon Glass <sjg at chromium.org>
Cc: Thinh Nguyen <Thinh.Nguyen at synopsys.com>
Cc: Tom Rini <trini at konsulko.com>
Cc: u-boot at lists.denx.de
---
 drivers/usb/gadget/epautoconf.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/epautoconf.c b/drivers/usb/gadget/epautoconf.c
index 09950ceeaed..66599ce8efa 100644
--- a/drivers/usb/gadget/epautoconf.c
+++ b/drivers/usb/gadget/epautoconf.c
@@ -247,8 +247,11 @@ struct usb_ep *usb_ep_autoconfig(
 			return ep;
 	}
 
-	if (gadget->ops->match_ep)
+	if (gadget->ops->match_ep) {
 		ep = gadget->ops->match_ep(gadget, desc, NULL);
+		if (ep && ep_matches(gadget, ep, desc))
+			return ep;
+	}
 
 	/* Second, look at endpoints until an unclaimed one looks usable */
 	list_for_each_entry(ep, &gadget->ep_list, ep_list) {
-- 
2.43.0



More information about the U-Boot mailing list