mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] usb: gadget: core: Check for unset descriptor
@ 2024-07-21 19:20 crwulff
  2024-07-22  1:07 ` Alan Stern
  0 siblings, 1 reply; 6+ messages in thread
From: crwulff @ 2024-07-21 19:20 UTC (permalink / raw)
  To: linux-usb
  Cc: Greg Kroah-Hartman, Alan Stern, Roy Luo, Krishna Kurapati,
	Michael Grzeschik, yuan linyu, Paul Cercueil, Felipe Balbi,
	linux-kernel, Chris Wulff, stable

From: Chris Wulff <crwulff@gmail.com>

Make sure the descriptor has been set before looking at maxpacket.
This fixes a null pointer panic in this case.

This may happen if the gadget doesn't properly set up the endpoint
for the current speed, or the gadget descriptors are malformed and
the descriptor for the speed/endpoint are not found.

Fixes: 54f83b8c8ea9 ("USB: gadget: Reject endpoints with 0 maxpacket value")
Cc: stable@vger.kernel.org
Signed-off-by: Chris Wulff <crwulff@gmail.com>
---
 drivers/usb/gadget/udc/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/udc/core.c b/drivers/usb/gadget/udc/core.c
index 2dfae7a17b3f..36a5d5935889 100644
--- a/drivers/usb/gadget/udc/core.c
+++ b/drivers/usb/gadget/udc/core.c
@@ -118,7 +118,7 @@ int usb_ep_enable(struct usb_ep *ep)
 		goto out;
 
 	/* UDC drivers can't handle endpoints with maxpacket size 0 */
-	if (usb_endpoint_maxp(ep->desc) == 0) {
+	if (!ep->desc || usb_endpoint_maxp(ep->desc) == 0) {
 		/*
 		 * We should log an error message here, but we can't call
 		 * dev_err() because there's no way to find the gadget
-- 
2.43.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-07-22 17:42 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-07-21 19:20 [PATCH] usb: gadget: core: Check for unset descriptor crwulff
2024-07-22  1:07 ` Alan Stern
2024-07-22 13:00   ` Chris Wulff
2024-07-22 13:38     ` Alan Stern
2024-07-22 17:11       ` Chris Wulff
2024-07-22 17:42         ` Alan Stern

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®