From: Guangshuo Li <liguangshuo@mail.sdu.edu.cn>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] usb: host: max3421: Fix potential resource leak on IRQ request failure
Date: Mon, 16 Nov 2026 22:25:55 +0800 [thread overview]
Message-ID: <20261116-c29ba55625-usb-host@mail.sdu.edu.cn> (raw)
If request_irq() fails after usb_add_hcd(), probe drops the HCD reference
without removing the registered root hub. The root hub and its HCD
reference are left behind.
Remove the HCD before unwinding the SPI thread. Keep the transfer buffers
and platform data alive until the thread has stopped.
This issue was found by our static analysis tool under development.
Fixes: 2d53139f3162 ("Add support for using a MAX3421E chip as a host driver.")
Signed-off-by: Guangshuo Li <liguangshuo@mail.sdu.edu.cn>
---
drivers/usb/host/max3421-hcd.c | 17 +++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)
diff --git a/drivers/usb/host/max3421-hcd.c b/drivers/usb/host/max3421-hcd.c
index 73e76d0e6973..09ba92c41a0d 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);
+ kfree(max3421_hcd->tx);
+ kfree(max3421_hcd->rx);
usb_put_hcd(hcd);
}
+ if (IS_ENABLED(CONFIG_OF) && dev->of_node && pdata) {
+ devm_kfree(&spi->dev, pdata);
+ spi->dev.platform_data = NULL;
+ }
return retval;
}
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
--
2.43.0
reply other threads:[~2026-11-16 14:26 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261116-c29ba55625-usb-host@mail.sdu.edu.cn \
--to=liguangshuo@mail.sdu.edu.cn \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
/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
all inboxes | Powered by JetHome®