From: sashiko-bot@kernel.org
To: shitao <shitao@kylinos.cn>, linux-usb@vger.kernel.org
Subject: Re: [PATCH v2] usb: host: max3421: fix the SPI thread teardown on remove
Date: Thu, 26 Nov 2026 14:07:38 +0000 [thread overview]
Message-ID: <sashiko-outbox-235671@kernel.org> (raw)
In-Reply-To: <20261126135222.1428623-1-shitao@kylinos.cn>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] usb: host: max3421: free_irq() races with enable_irq() in
max3421_remove()
--
commit 58f589c27256d9aa92eb5a12720e9958ee5eba27
Author: Shi Tao <shitao@kylinos.cn>
usb: host: max3421: fix the SPI thread teardown on remove
This commit updates max3421_remove() to free the interrupt before stopping
the SPI thread and drops the HCD spinlock around kthread_stop().
> diff --git a/drivers/usb/host/max3421-hcd.c b/drivers/usb/host/max3421-hcd.c
> index 11c0d0e1f48d3..e6a447b0992de 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);
> }
[Severity: Medium]
Can max3421_spi_thread() call enable_irq(spi->irq) after free_irq() has
already deactivated the IRQ, or exit leaving disable_irq_nosync(spi->irq)
unbalanced?
max3421_irq_handler() sets ENABLE_IRQ in max3421_hcd->todo and calls
disable_irq_nosync(spi->irq), delegating the matching enable_irq(spi->irq)
to max3421_spi_thread(). Because kthread_stop() is only called after
free_irq(), kthread_should_stop() is still false while free_irq() runs,
and max3421_spi_thread() also sleeps in spi_wr8() after checking
kthread_should_stop():
CPU0 CPU1 (max3421_spi_thread)
max3421_irq_handler()
test_and_set_bit(ENABLE_IRQ, ...)
disable_irq_nosync(spi->irq)
while (!kthread_should_stop())
if (!i_worked)
spi_wr8(..., MAX3421_REG_HIEN, ...)
max3421_remove()
free_irq(spi->irq, hcd)
if (test_and_clear_bit(ENABLE_IRQ, ...))
enable_irq(spi->irq) <-- on freed IRQ
kthread_stop(max3421_hcd->spi_thread)
Conversely, if max3421_irq_handler() sets ENABLE_IRQ and calls
disable_irq_nosync(spi->irq) just before free_irq(), and
max3421_spi_thread() then sees kthread_should_stop() at the top of its
loop and exits, the disable depth on spi->irq is never balanced by
enable_irq().
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261126135222.1428623-1-shitao@kylinos.cn?part=1
prev parent reply other threads:[~2026-11-26 14:07 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
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 message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-235671@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=shitao@kylinos.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox