serial: rp2: remove ports on IRQ request failure in probe
Jiri Slaby (SUSE)
maintainerPATCH 1/1 serial: rp2: remove ports on IRQ request failure in probe
Since commit 016002848c82 ("serial: rp2: use 'request_firmware' instead of 'request_firmware_nowait'"), rp2_probe() loads the firmware and registers all the UART ports (via rp2_load_firmware()) before requesting the IRQ. But if devm_request_irq() fails, probe just returns the error and leaves the ports registered with the serial core.
rp2_remove() is not called for a failed probe, so the ports stay registered, pointing to a card whose devm-managed memory (card->ports included) and iomaps are freed. Any later access to the tty devices then results in a use-after-free.
Call rp2_remove_ports() when the IRQ request fails.
--- drivers/tty/serial/rp2.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/tty/serial/rp2.c +2 -2
@@ -755,9 +755,9 @@ static int rp2_probe(struct pci_dev *pdev, rc =devm_request_irq (&pdev->dev, pdev->irq, rp2_uart_interrupt,IRQF_SHARED ,DRV_NAME , card);if (rc) -return rc; +rp2_remove_ports (card); -return 0 ; +return rc; }static void rp2_remove (struct pci_dev *pdev)
Signature · 1 line
2.56.1
[email protected]
AI reviewSashiko has reviewed this patch and found no issues.
Quoted 11 lines
Since commit
016002848c82("serial: rp2: use 'request_firmware' instead of 'request_firmware_nowait'"),rp2_probe()loads the firmware and registers all the UART ports (viarp2_load_firmware()) before requesting the IRQ. But ifdevm_request_irq()fails, probe just returns the error and leaves the ports registered with the serial core.
rp2_remove()is not called for a failed probe, so the ports stay registered, pointing to a card whose devm-managed memory (card->portsincluded) and iomaps are freed. Any later access to the tty devices then results in a use-after-free.
Quoted 5 lines
Call
rp2_remove_ports()when the IRQ request fails.Fixes 016002848c82 ("serial: rp2: use 'request_firmware' instead of 'request_firmware_nowait'")Co-Authored-By Claude Opus 5.5 <[email protected]>Signed-off-by Jiri Slaby (SUSE) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1