[PATCH 18/24] serial: fsl_lpuart: fix tty ref of wakeup event

From: Greg Kroah-Hartman

Date: Tue Oct 27 2026 - 07:20:05 EST


From: Josef Bacik <josef@xxxxxxxxxxxxxx>

To report a wakeup event, lpuart_resume_noirq() gets the tty with
tty_port_tty_get() and never puts it: each wakeup by the UART leaks a
reference, and the tty is not freed when it is closed.

With no_console_suspend, the function also gets there for a console
which is not open. Then tty_port_tty_get() returns NULL, which is
dereferenced.

Fixes: 18bdfccf3c30 ("tty: serial: fsl_lpuart: Add missing wakeup event reporting")
Cc: stable <stable@xxxxxxxxxx>
Cc: Jiri Slaby <jirislaby@xxxxxxxxxx>
Cc: Frank Li <Frank.Li@xxxxxxx>
Cc: Peng Fan <peng.fan@xxxxxxx>
Cc: Shitalkumar Gandhi <shital.gandhi45@xxxxxxxxx>
Cc: Sherry Sun <sherry.sun@xxxxxxx>
Signed-off-by: Josef Bacik <josef@xxxxxxxxxxxxxx>
Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
---
drivers/tty/serial/fsl_lpuart.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/tty/serial/fsl_lpuart.c b/drivers/tty/serial/fsl_lpuart.c
index c8575c965203..e54b4c44db42 100644
--- a/drivers/tty/serial/fsl_lpuart.c
+++ b/drivers/tty/serial/fsl_lpuart.c
@@ -3113,8 +3113,14 @@ static int lpuart_resume_noirq(struct device *dev)
/* check whether lpuart wakeup was triggered */
wake_active = stat & (UARTSTAT_RDRF | UARTSTAT_RXEDGIF);

- if (wake_active && irqd_is_wakeup_set(irq_get_irq_data(sport->port.irq)))
- pm_wakeup_event(tty_port_tty_get(port)->dev, 0);
+ if (wake_active && irqd_is_wakeup_set(irq_get_irq_data(sport->port.irq))) {
+ struct tty_struct *tty = tty_port_tty_get(port);
+
+ if (tty) {
+ pm_wakeup_event(tty->dev, 0);
+ tty_kref_put(tty);
+ }
+ }
}
}


--
2.56.0