Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: "Jiri Slaby (SUSE)" <jirislaby@kernel.org>
To: gregkh@linuxfoundation.org
Cc: linux-serial@vger.kernel.org,
	"Jiri Slaby (SUSE)" <jirislaby@kernel.org>,
	"Claude Opus 5.5" <noreply@anthropic.com>,
	Kevin Cernekee <cernekee@gmail.com>,
	stable@vger.kernel.org
Subject: [PATCH] serial: rp2: remove ports on IRQ request failure in probe
Date: Wed, 25 Nov 2026 09:40:59 +0100	[thread overview]
Message-ID: <20261125084059.84951-1-jirislaby@kernel.org> (raw)

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.

Fixes: 016002848c82 ("serial: rp2: use 'request_firmware' instead of 'request_firmware_nowait'")
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
Cc: Kevin Cernekee <cernekee@gmail.com>
Cc: <stable@vger.kernel.org>
---
 drivers/tty/serial/rp2.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/tty/serial/rp2.c b/drivers/tty/serial/rp2.c
index 158b06424b56..f82270bf7060 100644
--- a/drivers/tty/serial/rp2.c
+++ b/drivers/tty/serial/rp2.c
@@ -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)
-- 
2.56.1


                 reply	other threads:[~2026-11-25  8:41 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=20261125084059.84951-1-jirislaby@kernel.org \
    --to=jirislaby@kernel.org \
    --cc=cernekee@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=noreply@anthropic.com \
    --cc=stable@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