Re: [PATCH v2] serial: core: Shut down a running console port before removing it

From: Phil Rosenthal

Date: Tue Oct 13 2026 - 13:18:28 EST


On Tue, Oct 13, 2026 at 06:12:52PM +0200, Greg Kroah-Hartman wrote:
> Is this the same as:
> https://patch.msgid.link/20261003163337.45577-1-igorpetindev@xxxxxxxxx
> ?

Yes, it's the same bug and the same fix. I hadn't seen Igor's patch when I
sent mine, sorry for the noise. His is in tty-testing already, so
please drop mine.

> Why does that commit set a field and this change does not? Which is
> correct?

Both work. Clearing port->console isn't needed for the fix, and it does
no harm. uart_shutdown() doesn't look at that flag. It is only read in
tty_port_shutdown_locked() and tty_port_close(), on the last close of a
tty, and by this point any open tty has been hung up, so
tty_port_close_start() returns before either is reached.
serial_core_add_one_port() sets the flag again when the line is reused.

The other difference is that Igor's patch calls uart_shutdown() only if
tty_port_initialized(), as my v1 did. Sashiko's review of my v1 pointed
out that a console port removed while suspended is not initialized but
still has its suspended flag set and its transmit buffer allocated, and
uart_shutdown() would clear both. That needs the device to go away
between system suspend and resume, and I haven't found a way to test
it. If you want it covered I can send a patch on top of Igor's commit
that drops the tty_port_initialized() check.

I ran my reproducers on tty-next 36844ea19656 plus 810d467c11f0, in a
QEMU guest with KASAN. Both cases that fail without it are fixed: the
8250_pci port with INTx (IRQ freed on unbind, reading /proc/interrupts
is clean, rebinding restores the console), and the polled MMIO port,
where serial8250_timeout() no longer runs after removal. A port held
open across removal and a console that was never opened still work.
I'll send a Tested-by on Igor's thread.

Thanks,
Phil