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

From: Andy Shevchenko

Date: Tue Oct 27 2026 - 12:18:00 EST


On Tue, Oct 27, 2026 at 12:06:49PM +0100, Greg Kroah-Hartman wrote:
>
> 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.

...

> - 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);
> + }
> + }

I believe I saw already something like this. Taking into consideration that can
be a helper for all who wants the same functionality.

--
With Best Regards,
Andy Shevchenko