Re: [PATCH] usb: host: max3421: fix the SPI thread teardown on remove
From: Greg KH
Date: Thu Nov 26 2026 - 07:52:08 EST
On Thu, Nov 26, 2026 at 08:11:48PM +0800, shitao wrote:
> 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@xxxxxxxxxx>
Real / full name please.
And how did you test this?
thanks,
greg k-h