[PATCH 23/24] serial: st-asc: don't report a wakeup to a closed tty

From: Greg Kroah-Hartman

Date: Tue Oct 27 2026 - 07:15:21 EST


From: Josef Bacik <josef@xxxxxxxxxxxxxx>

If its interrupt is a wakeup source, asc_receive_chars() reports the
characters which arrive as a wakeup event of tport->tty->dev. That
pointer is only set while the port is open. The port of a console is
not shut down by the last close, so its interrupt handler goes on
running without a tty. If the system is then woken up by a character on
the console, the handler dereferences a NULL pointer.

Take a reference to the tty, and leave the event out if there is none.

Fixes: c4b058560762 ("serial:st-asc: Add ST ASC driver.")
Cc: stable <stable@xxxxxxxxxx>
Cc: Patrice Chotard <patrice.chotard@xxxxxxxxxxx>
Cc: Jiri Slaby <jirislaby@xxxxxxxxxx>
Cc: Srinivas Kandagatla <srini@xxxxxxxxxx>
Signed-off-by: Josef Bacik <josef@xxxxxxxxxxxxxx>
Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
---
drivers/tty/serial/st-asc.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/tty/serial/st-asc.c b/drivers/tty/serial/st-asc.c
index 6ed9a327702b..006874598b6c 100644
--- a/drivers/tty/serial/st-asc.c
+++ b/drivers/tty/serial/st-asc.c
@@ -262,8 +262,15 @@ static void asc_receive_chars(struct uart_port *port)
if (mode == ASC_CTL_MODE_8BIT || mode == ASC_CTL_MODE_8BIT_PAR)
ignore_pe = true;

- if (irqd_is_wakeup_set(irq_get_irq_data(port->irq)))
- pm_wakeup_event(tport->tty->dev, 0);
+ if (irqd_is_wakeup_set(irq_get_irq_data(port->irq))) {
+ struct tty_struct *tty = tty_port_tty_get(tport);
+
+ /* A console goes on receiving after the last close */
+ if (tty) {
+ pm_wakeup_event(tty->dev, 0);
+ tty_kref_put(tty);
+ }
+ }

while ((status = asc_in(port, ASC_STA)) & ASC_STA_RBF) {
c = asc_in(port, ASC_RXBUF) | ASC_RXBUF_DUMMY_RX;

--
2.56.0