Linux USB
 help / color / mirror / Atom feed
* [PATCH] usb: gadget: max3420: Fix potential thread leak on probe failure
@ 2026-11-20 17:35 Guangshuo Li
  2026-11-20 17:48 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Guangshuo Li @ 2026-11-20 17:35 UTC (permalink / raw)
  To: Neill Kapron, Greg Kroah-Hartman; +Cc: linux-usb, linux-kernel

If requesting the VBUS interrupt fails, probe unregisters the gadget
but leaves the already created thread behind. Managed cleanup then
releases the state referenced by the thread.

Unregister the gadget, disable and synchronize the UDC interrupt, then
stop the thread before returning the probe error.

This issue was found by our static analysis tool under development.

Fixes: 48ba02b2e2b1 ("usb: gadget: add udc driver for max3420")
Signed-off-by: Guangshuo Li <liguangshuo@mail.sdu.edu.cn>
---
 drivers/usb/gadget/udc/max3420_udc.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/gadget/udc/max3420_udc.c b/drivers/usb/gadget/udc/max3420_udc.c
index 11fd61cba5af..84309229216b 100644
--- a/drivers/usb/gadget/udc/max3420_udc.c
+++ b/drivers/usb/gadget/udc/max3420_udc.c
@@ -1198,7 +1198,7 @@ static void max3420_eps_init(struct max3420_udc *udc)
 static int max3420_probe(struct spi_device *spi)
 {
 	struct max3420_udc *udc;
-	int err, irq;
+	int err, irq, udc_irq;
 	u8 reg[8];
 
 	if (spi->controller->flags & SPI_CONTROLLER_HALF_DUPLEX) {
@@ -1252,8 +1252,8 @@ static int max3420_probe(struct spi_device *spi)
 
 	spi_set_drvdata(spi, udc);
 
-	irq = of_irq_get_byname(spi->dev.of_node, "udc");
-	err = devm_request_irq(&spi->dev, irq, max3420_irq_handler, 0,
+	udc_irq = of_irq_get_byname(spi->dev.of_node, "udc");
+	err = devm_request_irq(&spi->dev, udc_irq, max3420_irq_handler, 0,
 			       "max3420", udc);
 	if (err < 0)
 		goto del_gadget;
@@ -1283,11 +1283,17 @@ static int max3420_probe(struct spi_device *spi)
 		err = devm_request_irq(&spi->dev, irq,
 				       max3420_vbus_handler, 0, "vbus", udc);
 		if (err < 0)
-			goto del_gadget;
+			goto stop_thread;
 	}
 
 	return 0;
 
+stop_thread:
+	usb_del_gadget_udc(&udc->gadget);
+	disable_irq(udc_irq);
+	kthread_stop(udc->thread_task);
+	return err;
+
 del_gadget:
 	usb_del_gadget_udc(&udc->gadget);
 	return err;

base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4

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

end of thread, other threads:[~2026-11-20 17:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-20 17:35 [PATCH] usb: gadget: max3420: Fix potential thread leak on probe failure Guangshuo Li
2026-11-20 17:48 ` sashiko-bot

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