Re: [PATCH 24/24] serial: stm32: don't report a wakeup to a closed tty
From: Ilpo Järvinen
Date: Thu Oct 29 2026 - 07:57:09 EST
On Thu, 29 Oct 2026, Jiri Slaby wrote:
> On 27. 10. 26, 14:02, Ilpo Järvinen wrote:
> > On Tue, 27 Oct 2026, Greg Kroah-Hartman wrote:
> >
> > > From: Josef Bacik <josef@xxxxxxxxxxxxxx>
> > >
> > > stm32_usart_interrupt() reports a wakeup interrupt 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: it stays
> > > initialized, so the wakeup interrupt is still enabled on suspend. If
> > > the system is then woken up by the console, the handler dereferences a
> > > NULL pointer.
> > >
> > > Take a reference to the tty, and leave the event out if there is none.
> > >
> > > Fixes: 48a6092fb41f ("serial: stm32-usart: Add STM32 USART Driver")
> > > Cc: stable <stable@xxxxxxxxxx>
> > > Cc: Jiri Slaby <jirislaby@xxxxxxxxxx>
> > > Cc: Maxime Coquelin <mcoquelin.stm32@xxxxxxxxx>
> > > Cc: Alexandre Torgue <alexandre.torgue@xxxxxxxxxxx>
> > > Cc: Andy Shevchenko <andy.shevchenko@xxxxxxxxx>
> > > Cc: Vladimir Zapolskiy <vladimir_zapolskiy@xxxxxxxxxx>
> > > Cc: Peter Hurley <peter@xxxxxxxxxxxxxxxxxx>
> > > Signed-off-by: Josef Bacik <josef@xxxxxxxxxxxxxx>
> > > Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
> > > ---
> > > drivers/tty/serial/stm32-usart.c | 11 +++++++++--
> > > 1 file changed, 9 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/drivers/tty/serial/stm32-usart.c
> > > b/drivers/tty/serial/stm32-usart.c
> > > index ad06b760cfca..3bc2ce877585 100644
> > > --- a/drivers/tty/serial/stm32-usart.c
> > > +++ b/drivers/tty/serial/stm32-usart.c
> > > @@ -872,8 +872,15 @@ static irqreturn_t stm32_usart_interrupt(int irq,
> > > void *ptr)
> > > writel_relaxed(USART_ICR_WUCF,
> > > port->membase + ofs->icr);
> > > stm32_usart_clr_bits(port, ofs->cr3, USART_CR3_WUFIE);
> > > - 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 stays set up after the last close */
> > > + if (tty) {
> > > + pm_wakeup_event(tty->dev, 0);
> > > + tty_kref_put(tty);
> > > + }
> > > + }
> >
> > Could we like add a helper into serial core to do this tty wakeup dance?
> > It is duplicated in quite many of these patches.
>
> Likely. Or use scoped_guard(tty_port_tty) at minimum.
Also the irqd_is_wakeup_set(irq_get_irq_data(xx)) part seemed duplicated
so it's not just about the reference dance what is duplicated in this
fragment.
--
i.