mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Guangshuo Li <liguangshuo@mail.sdu.edu.cn>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Jiri Slaby <jirislaby@kernel.org>
Cc: linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org,
	stable@vger.kernel.org
Subject: [PATCH] serial: sccnxp: Fix potential stale ports after IRQ request failure
Date: Mon,  9 Nov 2026 21:09:43 +0800	[thread overview]
Message-ID: <20261109-21df1234b2-serial-sccnxp@mail.sdu.edu.cn> (raw)

The ports are registered before the interrupt is requested. If that
request fails, unregistering the UART driver frees its state array
while the registered ports still refer to it.

Check each port registration and remove the ports already registered
before unwinding the UART driver on either failure path.

This issue was found by our static analysis tool under development.

Fixes: 1d65c0b12656 ("serial: New serial driver SCCNXP")
Cc: stable@vger.kernel.org
Signed-off-by: Guangshuo Li <liguangshuo@mail.sdu.edu.cn>
---
 drivers/tty/serial/sccnxp.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/tty/serial/sccnxp.c b/drivers/tty/serial/sccnxp.c
index cb31e3aceb62..502f8ebe265b 100644
--- a/drivers/tty/serial/sccnxp.c
+++ b/drivers/tty/serial/sccnxp.c
@@ -989,7 +989,9 @@ static int sccnxp_probe(struct platform_device *pdev)
 		s->port[i].uartclk	= uartclk;
 		s->port[i].ops		= &sccnxp_ops;
 		s->port[i].has_sysrq = IS_ENABLED(CONFIG_SERIAL_SCCNXP_CONSOLE);
-		uart_add_one_port(&s->uart, &s->port[i]);
+		ret = uart_add_one_port(&s->uart, &s->port[i]);
+		if (ret)
+			goto err_remove_ports;
 		/* Set direction to input */
 		if (s->chip->flags & SCCNXP_HAVE_IO)
 			sccnxp_set_bit(&s->port[i], DIR_OP, 0);
@@ -1016,6 +1018,10 @@ static int sccnxp_probe(struct platform_device *pdev)
 		return 0;
 	}
 
+err_remove_ports:
+	while (i--)
+		uart_remove_one_port(&s->uart, &s->port[i]);
+
 	uart_unregister_driver(&s->uart);
 err_out:
 	if (!IS_ERR(s->regulator))
-- 
2.43.0


                 reply	other threads:[~2026-11-09 13:09 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=20261109-21df1234b2-serial-sccnxp@mail.sdu.edu.cn \
    --to=liguangshuo@mail.sdu.edu.cn \
    --cc=gregkh@linuxfoundation.org \
    --cc=jirislaby@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --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

all inboxes | Powered by JetHome®