Linux USB
 help / color / mirror / Atom feed
* [PATCH] usb: host: max3421: fix the SPI thread teardown on remove
@ 2026-11-26 12:11 shitao
  2026-11-26 12:26 ` sashiko-bot
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: shitao @ 2026-11-26 12:11 UTC (permalink / raw)
  To: gregkh, linux-usb; +Cc: davidm, eeodqql09, linux-kernel, shitao

max3421_remove() stops the SPI thread with the HCD spinlock held:

	spin_lock_irqsave(&max3421_hcd->lock, flags);
	kthread_stop(max3421_hcd->spi_thread);
	spin_unlock_irqrestore(&max3421_hcd->lock, flags);

kthread_stop() waits for the thread to exit, so it must not be called
under a spinlock.  Worse, the thread takes the same lock in its main
loop (in max3421_urb_done() and friends), so it can never finish its
current iteration while remove() holds the lock, and remove() ends up
waiting forever.

The interrupt is freed after the thread is stopped, but its handler
wakes up that very thread, so an interrupt arriving after the thread
has exited calls wake_up_process() on a task_struct that may already
have been freed.

Free the interrupt first and stop the thread without the spinlock.
The thread checks kthread_should_stop() at the top of its loop, so it
exits without re-enabling the freed interrupt.

Fixes: 2d53139f31626 ("Add support for using a MAX3421E chip as a host driver.")
Signed-off-by: shitao <shitao@kylinos.cn>
---
 drivers/usb/host/max3421-hcd.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/drivers/usb/host/max3421-hcd.c b/drivers/usb/host/max3421-hcd.c
index 73e76d0e6973..20e458809ac6 100644
--- a/drivers/usb/host/max3421-hcd.c
+++ b/drivers/usb/host/max3421-hcd.c
@@ -1936,21 +1936,16 @@ max3421_remove(struct spi_device *spi)
 {
 	struct max3421_hcd *max3421_hcd;
 	struct usb_hcd *hcd;
-	unsigned long flags;
 
 	max3421_hcd = spi_get_drvdata(spi);
 	hcd = max3421_to_hcd(max3421_hcd);
 
 	usb_remove_hcd(hcd);
 
-	spin_lock_irqsave(&max3421_hcd->lock, flags);
+	free_irq(spi->irq, hcd);
 
 	kthread_stop(max3421_hcd->spi_thread);
 
-	spin_unlock_irqrestore(&max3421_hcd->lock, flags);
-
-	free_irq(spi->irq, hcd);
-
 	usb_put_hcd(hcd);
 }
 
-- 
2.25.1


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

end of thread, other threads:[~2026-11-26 14:07 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26 12:11 [PATCH] usb: host: max3421: fix the SPI thread teardown on remove shitao
2026-11-26 12:26 ` sashiko-bot
2026-11-26 12:52 ` Greg KH
2026-11-26 13:52 ` [PATCH v2] " shitao
2026-11-26 14:07   ` sashiko-bot

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