From: sashiko-bot@kernel.org
To: "Guangshuo Li" <liguangshuo@mail.sdu.edu.cn>
Cc: linux-usb@vger.kernel.org
Subject: Re: [PATCH] usb: host: max3421: Fix potential resource leak on IRQ request failure
Date: Mon, 16 Nov 2026 14:36:21 +0000 [thread overview]
Message-ID: <sashiko-outbox-217180@kernel.org> (raw)
In-Reply-To: <20261116-c29ba55625-usb-host@mail.sdu.edu.cn>
Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [Critical] usb: host: max3421-hcd: use-after-free in
max3421_irq_handler() [1]
--
commit bf9ea93a3f4c8766b32b8f1ff53f8a0863775270
Author: Guangshuo Li <liguangshuo@mail.sdu.edu.cn>
usb: host: max3421: Fix potential resource leak on IRQ request failure
This commit calls usb_remove_hcd() when request_irq() fails in
max3421_probe() and reorders the error cleanup so the SPI thread is
stopped before freeing the transfer buffers and platform data.
> diff --git a/drivers/usb/host/max3421-hcd.c b/drivers/usb/host/max3421-hcd.c
> index 73e76d0e69738..09ba92c41a0d5 100644
> --- a/drivers/usb/host/max3421-hcd.c
> +++ b/drivers/usb/host/max3421-hcd.c
> @@ -1911,23 +1911,24 @@ max3421_probe(struct spi_device *spi)
> IRQF_TRIGGER_LOW, "max3421", hcd);
> if (retval < 0) {
> dev_err(&spi->dev, "failed to request irq %d\n", spi->irq);
> - goto error;
> + goto remove_hcd;
> }
> return 0;
>
> +remove_hcd:
> + usb_remove_hcd(hcd);
> error:
> - if (IS_ENABLED(CONFIG_OF) && dev->of_node && pdata) {
> - devm_kfree(&spi->dev, pdata);
> - spi->dev.platform_data = NULL;
> - }
> -
> if (hcd) {
> - kfree(max3421_hcd->tx);
> - kfree(max3421_hcd->rx);
> if (!IS_ERR_OR_NULL(max3421_hcd->spi_thread))
> kthread_stop(max3421_hcd->spi_thread);
[Severity: Critical]
This problem wasn't introduced by this patch, but can max3421_remove()
trigger a use-after-free on max3421_hcd->spi_thread in
max3421_irq_handler() [1]?
CPU0 CPU1
max3421_remove()
kthread_stop(max3421_hcd->spi_thread)
max3421_irq_handler()
if (max3421_hcd->spi_thread)
wake_up_process(...)
<-- use-after-free
free_irq(spi->irq, hcd)
max3421_remove() stops max3421_hcd->spi_thread (which drops the
task_struct reference) without clearing the pointer, before calling
free_irq(). An interrupt firing in that window wakes the freed
task_struct. Calling free_irq() before kthread_stop() in max3421_remove()
would avoid this race.
[1] https://sashiko.dev/#/bug/linux-1a37fb82-5226-4771-845f-e2e6c320c91c
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261116-c29ba55625-usb-host@mail.sdu.edu.cn?part=1
prev parent reply other threads:[~2026-11-16 14:36 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-16 14:25 [PATCH] usb: host: max3421: Fix potential resource leak on IRQ request failure Guangshuo Li
2026-11-16 14:36 ` 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-217180@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=liguangshuo@mail.sdu.edu.cn \
--cc=linux-usb@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.