From 0353b51965883cf70dad162908e07395f242000f Mon Sep 17 00:00:00 2001 From: "Jiri Slaby (SUSE)" Date: Tue, 3 Nov 2026 12:16:37 +0100 Subject: [PATCH 01/12] serial: 8250_exar: check priv->gpio properly priv->gpio is set by platform_device_register_full(), which returns error-encoded pointers on failure, not NULL. Sashiko reported: > Does __xr17v35x_register_gpio() return an ERR_PTR if > platform_device_register_full() fails? > > If it does, we might be storing an error pointer directly into > priv->gpio in xr17v35x_register_gpio() without validating it with > IS_ERR(). Because the error is ignored, the device probe > successfully continues. Before commit 1145d1a0703f ("serial: 8250_exar: use platform_device_register_full()"), __xr17v35x_register_gpio() returned NULL on any failure (platform_device_alloc(), device_add_software_node() or platform_device_add() failing were all turned into a NULL return). The plain truthy check in xr17v35x_unregister_gpio() matched that convention. That commit switched registration to platform_device_register_full(), which reports failure as an ERR_PTR() instead of NULL, but the unregister check was never updated to match. As a result, a failed registration left an error pointer in priv->gpio, and unbind would tear it down as if it were a real platform_device, dereferencing the encoded error value in device_remove_software_node() and platform_device_unregister(). Use IS_ERR_OR_NULL() instead, so both the unset (non-EXAR vendor, priv->gpio never assigned) and failed-registration (ERR_PTR) cases are skipped. Fixes: 1145d1a0703f ("serial: 8250_exar: use platform_device_register_full()") Signed-off-by: Jiri Slaby (SUSE) Cc: stable@vger.kernel.org Assisted-by: LLM Link: https://lore.kernel.org/all/sashiko-outbox-170895@kernel.org/ Link: https://patch.msgid.link/28c09cf858795491f66667781bf79fb6a603f159.1793704520.git.jirislaby@kernel.org Signed-off-by: Greg Kroah-Hartman --- drivers/tty/serial/8250/8250_exar.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/tty/serial/8250/8250_exar.c b/drivers/tty/serial/8250/8250_exar.c index 57847c5bd2fc..b1e20fd4cfd2 100644 --- a/drivers/tty/serial/8250/8250_exar.c +++ b/drivers/tty/serial/8250/8250_exar.c @@ -1181,7 +1181,7 @@ static int xr17v35x_register_gpio(struct exar8250 *priv, struct pci_dev *pcidev, static void xr17v35x_unregister_gpio(struct exar8250 *priv) { - if (priv->gpio) { + if (!IS_ERR_OR_NULL(priv->gpio)) { __xr17v35x_unregister_gpio(priv->gpio); priv->gpio = NULL; } From 93db7f4e32e2d5f6c63e724452814bccb5bd6773 Mon Sep 17 00:00:00 2001 From: "Jiri Slaby (SUSE)" Date: Tue, 3 Nov 2026 12:16:38 +0100 Subject: [PATCH 02/12] serial: 8250_hp300: reorder HPDCA code To have less ifdefs (code is now under one) and no forward declarations. Signed-off-by: Jiri Slaby (SUSE) Link: https://patch.msgid.link/f4dbbb45248771baa130e56bcb0b1916cd909256.1793704520.git.jirislaby@kernel.org Signed-off-by: Greg Kroah-Hartman --- drivers/tty/serial/8250/8250_hp300.c | 62 ++++++++++++---------------- 1 file changed, 26 insertions(+), 36 deletions(-) diff --git a/drivers/tty/serial/8250/8250_hp300.c b/drivers/tty/serial/8250/8250_hp300.c index e9599c5c2fea..68ce5972c296 100644 --- a/drivers/tty/serial/8250/8250_hp300.c +++ b/drivers/tty/serial/8250/8250_hp300.c @@ -34,29 +34,6 @@ struct hp300_port { static struct hp300_port *hp300_ports; #endif -#ifdef CONFIG_HPDCA - -static int hpdca_init_one(struct dio_dev *d, - const struct dio_device_id *ent); -static void hpdca_remove_one(struct dio_dev *d); - -static struct dio_device_id hpdca_dio_tbl[] = { - { DIO_ID_DCA0 }, - { DIO_ID_DCA0REM }, - { DIO_ID_DCA1 }, - { DIO_ID_DCA1REM }, - { 0 } -}; - -static struct dio_driver hpdca_driver = { - .name = "hpdca", - .id_table = hpdca_dio_tbl, - .probe = hpdca_init_one, - .remove = hpdca_remove_one, -}; - -#endif - static unsigned int num_ports; extern int hp300_uart_scode; @@ -197,6 +174,32 @@ static int hpdca_init_one(struct dio_dev *d, return 0; } + +static void hpdca_remove_one(struct dio_dev *d) +{ + struct uart_8250_port *uport = dio_get_drvdata(d); + + if (d->resource.start) { + /* Disable board-interrupts */ + out_8(d->resource.start + DIO_VIRADDRBASE + DCA_IC, 0); + } + serial8250_unregister_port(uport); +} + +static struct dio_device_id hpdca_dio_tbl[] = { + { DIO_ID_DCA0 }, + { DIO_ID_DCA0REM }, + { DIO_ID_DCA1 }, + { DIO_ID_DCA1REM }, + { 0 } +}; + +static struct dio_driver hpdca_driver = { + .name = "hpdca", + .id_table = hpdca_dio_tbl, + .probe = hpdca_init_one, + .remove = hpdca_remove_one, +}; #endif static int __init hp300_8250_init(void) @@ -280,19 +283,6 @@ static int __init hp300_8250_init(void) return 0; } -#ifdef CONFIG_HPDCA -static void hpdca_remove_one(struct dio_dev *d) -{ - struct uart_8250_port *uport = dio_get_drvdata(d); - - if (d->resource.start) { - /* Disable board-interrupts */ - out_8(d->resource.start + DIO_VIRADDRBASE + DCA_IC, 0); - } - serial8250_unregister_port(uport); -} -#endif - static void __exit hp300_8250_exit(void) { #ifdef CONFIG_HPAPCI From 895dc0eaa2779ff46a0b2a20b5ce9eb0b1125cb2 Mon Sep 17 00:00:00 2001 From: "Jiri Slaby (SUSE)" Date: Tue, 3 Nov 2026 12:16:39 +0100 Subject: [PATCH 03/12] tty: fix misapplied compat_ptr() in tty_compat_ioctl() Since commit f0193d3ea73b below, `cmd` was converted with compat_ptr(), while `arg` was passed to ld->ops->ioctl() unmodified. Fix it so `cmd` stays `cmd` and `arg` gets converted through compat_ptr() as intended. Notes: 2) compat_ptr() did nothing to `cmd`, provided it is uint, 1) compat_ptr() is no-op everywhere (was different on s390 before 8e0b986c59c6 ("s390: Remove compat support")), 3) `arg` might not have been chopped correctly until 8e0b986c59c6. But I am not sure why noone noticed all those (7) years (from f0193d3ea73b to 8e0b986c59c6)? Fixes: f0193d3ea73b ("change semantics of ldisc ->compat_ioctl()") Signed-off-by: Jiri Slaby (SUSE) Cc: stable@vger.kernel.org # applicable from 4.20 to 6.18 incl Assisted-by: LLM Link: https://patch.msgid.link/63e9d84a1e8e23852423206cf3f8907aafc88f17.1793704520.git.jirislaby@kernel.org Signed-off-by: Greg Kroah-Hartman --- drivers/tty/tty_io.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c index 1a6c8a1bc764..150052f6d9db 100644 --- a/drivers/tty/tty_io.c +++ b/drivers/tty/tty_io.c @@ -2969,8 +2969,7 @@ static long tty_compat_ioctl(struct file *file, unsigned int cmd, if (ld->ops->compat_ioctl) retval = ld->ops->compat_ioctl(tty, cmd, arg); if (retval == -ENOIOCTLCMD && ld->ops->ioctl) - retval = ld->ops->ioctl(tty, (unsigned long)compat_ptr(cmd), - arg); + retval = ld->ops->ioctl(tty, cmd, (unsigned long)compat_ptr(arg)); tty_ldisc_deref(ld); return retval; From 5d1d814408c1c8e797031eac8ddd40de1a9e8e93 Mon Sep 17 00:00:00 2001 From: Chris Mason Date: Tue, 27 Oct 2026 12:06:27 +0100 Subject: [PATCH 04/12] vt: serialise the producers of the flip buffer Typing on a virtual console while the console replies to an escape sequence can make the kernel write past the end of a buffer. A user who can write to the foreground console can cause this on purpose if they can also inject key events, through /dev/uinput or by writing to the /dev/input/event* node of a keyboard. Input for a tty goes through the flip buffer of its port. A driver inserts the data with tty_insert_flip_*() and then calls tty_flip_buffer_push() to pass it on to the line discipline. The insert functions take no lock: they check that the current struct tty_buffer has room, copy the data to offset ->used, and then advance ->used. So a flip buffer supports only one producer at a time, and a driver that has several must serialise them. Four functions feed the flip buffer of a virtual console: - put_queue(), puts_queue() and fn_send_intr() insert typed characters and breaks for the keyboard handler. They run under kbd_event_lock. - respond_string() inserts the reply when a program writes an escape sequence that requests one, such as a cursor position report. It runs under the console lock. The keyboard handler gets its events from the input layer and feeds the foreground console. Key events that a program writes to /dev/uinput or to an event node reach it in the same way as typed keys. The keyboard handler and respond_string() share no lock, so they can interleave: keyboard handler respond_string() ================ ================ room check passes room check passes memcpy() to offset used used += len memcpy() to offset used used += len /* used > size of the buffer */ The room check subtracts ->used from the size, and both are unsigned. Once ->used exceeds the size, the result wraps, so the check always passes, and each later insert lands further past the buffer. Reproduced as root, with keys from a uinput keyboard and cursor position reports on the same console: KFENCE reported an out-of-bounds write 1,024 bytes past the buffer in under 10 s. Fix this by taking port->lock, with interrupts disabled, around the insert and the push in these four functions. kbd_keycode() already takes port->lock under kbd_event_lock, so this lock ordering is not new. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Cc: stable Cc: Jiri Slaby Cc: Nicolas Pitre Cc: Kees Cook Cc: Joshua Rogers Cc: Chris Mason Cc: Helge Deller Cc: Thomas Zimmermann Cc: Mingyu Wang <25181214217@stu.xidian.edu.cn> Cc: Randy Dunlap Cc: Ronan Pigott Cc: Liav Mordouch Signed-off-by: Chris Mason Signed-off-by: Greg Kroah-Hartman Link: https://patch.msgid.link/20261027-tty-llm-v1-1-99b0202ae546@linuxfoundation.org Signed-off-by: Greg Kroah-Hartman --- drivers/tty/vt/keyboard.c | 6 ++++++ drivers/tty/vt/vt.c | 2 ++ 2 files changed, 8 insertions(+) diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c index ef4a19aeb3ce..f4b742e091fb 100644 --- a/drivers/tty/vt/keyboard.c +++ b/drivers/tty/vt/keyboard.c @@ -322,15 +322,20 @@ int kbd_rate(struct kbd_repeat *rpt) /* * Helper Functions. + * + * A flip buffer allows one producer at a time, and respond_string() in vt.c + * feeds the same one under the console lock. So take the lock of the port. */ static void put_queue(struct vc_data *vc, int ch) { + guard(spinlock_irqsave)(&vc->port.lock); tty_insert_flip_char(&vc->port, ch, 0); tty_flip_buffer_push(&vc->port); } static void puts_queue(struct vc_data *vc, const char *cp) { + guard(spinlock_irqsave)(&vc->port.lock); tty_insert_flip_string(&vc->port, cp, strlen(cp)); tty_flip_buffer_push(&vc->port); } @@ -587,6 +592,7 @@ static void fn_inc_console(struct vc_data *vc) static void fn_send_intr(struct vc_data *vc) { + guard(spinlock_irqsave)(&vc->port.lock); tty_insert_flip_char(&vc->port, 0, TTY_BREAK); tty_flip_buffer_push(&vc->port); } diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c index 7dbc0072a40a..6a6eb8b2a6de 100644 --- a/drivers/tty/vt/vt.c +++ b/drivers/tty/vt/vt.c @@ -1971,6 +1971,8 @@ static void csi_m(struct vc_data *vc) static void respond_string(const char *p, size_t len, struct tty_port *port) { + /* The keyboard handler feeds the same flip buffer. */ + guard(spinlock_irqsave)(&port->lock); tty_insert_flip_string(port, p, len); tty_flip_buffer_push(port); } From 84da8238f7bd3025fc16da32c4cd9992c95a783b Mon Sep 17 00:00:00 2001 From: Josef Bacik Date: Tue, 27 Oct 2026 12:06:28 +0100 Subject: [PATCH 05/12] serial: core: respect runtime PM when sending x_char MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit __uart_start() calls the start_tx operation only if the port is runtime active. Otherwise it asks for a resume, and serial_port_runtime_resume() starts the transmitter. uart_send_xchar() calls start_tx at once, under the port lock, whatever the state of the device. With 8250_omap, serial8250_start_tx() then calls pm_runtime_get_sync() for a suspended device: that sleeps, and omap8250_runtime_resume() takes the port lock again. A tcflow(TCIOFF) on an idle port is enough, if autosuspend has been enabled. It was allowed as long as that driver used pm_runtime_irq_safe(). Share the part of __uart_start() that deals with runtime PM. A stopped transmission still does not hold up an XON or XOFF character. Let a pending x_char count as work for serial_port_runtime_resume(), and keep the port from being suspended with it. Fixes: 8700a7ea5519 ("serial: 8250_omap: Drop pm_runtime_irq_safe()") Cc: stable Cc: Jiri Slaby Cc: Hugo Villeneuve Cc: Johan Hovold Cc: Karl Mehltretter Cc: John Ogness Cc: "Uwe Kleine-König (The Capable Hub)" Cc: Tony Lindgren Signed-off-by: Josef Bacik Signed-off-by: Greg Kroah-Hartman Link: https://patch.msgid.link/20261027-tty-llm-v1-2-99b0202ae546@linuxfoundation.org Signed-off-by: Greg Kroah-Hartman --- drivers/tty/serial/serial_core.c | 25 +++++++++++++++---------- drivers/tty/serial/serial_port.c | 4 ++-- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c index c0deec0e6af4..b06d2649be34 100644 --- a/drivers/tty/serial/serial_core.c +++ b/drivers/tty/serial/serial_core.c @@ -135,17 +135,11 @@ static void uart_stop(struct tty_struct *tty) uart_port_unlock_deref(port, flags); } -static void __uart_start(struct uart_state *state) +static void uart_port_start_tx(struct uart_port *port) { - struct uart_port *port = state->uart_port; - struct serial_port_device *port_dev; + struct serial_port_device *port_dev = port->port_dev; int err; - if (!port || port->flags & UPF_DEAD || uart_tx_stopped(port)) - return; - - port_dev = port->port_dev; - /* Increment the runtime PM usage count for the active check below */ err = pm_runtime_get(&port_dev->dev); if (err < 0 && err != -EINPROGRESS) { @@ -164,6 +158,16 @@ static void __uart_start(struct uart_state *state) pm_runtime_put_autosuspend(&port_dev->dev); } +static void __uart_start(struct uart_state *state) +{ + struct uart_port *port = state->uart_port; + + if (!port || port->flags & UPF_DEAD || uart_tx_stopped(port)) + return; + + uart_port_start_tx(port); +} + static void uart_start(struct tty_struct *tty) { struct uart_state *state = tty->driver_data; @@ -718,8 +722,9 @@ static void uart_send_xchar(struct tty_struct *tty, u8 ch) else { guard(uart_port_lock_irqsave)(port); port->x_char = ch; - if (ch) - port->ops->start_tx(port); + /* It goes out even if the transmission is stopped */ + if (ch && !(port->flags & UPF_DEAD)) + uart_port_start_tx(port); } uart_port_deref(port); } diff --git a/drivers/tty/serial/serial_port.c b/drivers/tty/serial/serial_port.c index 2fc48cd63f6c..f2f7cdd3a54c 100644 --- a/drivers/tty/serial/serial_port.c +++ b/drivers/tty/serial/serial_port.c @@ -23,8 +23,8 @@ /* Only considers pending TX for now. Caller must take care of locking */ static int __serial_port_busy(struct uart_port *port) { - return !uart_tx_stopped(port) && - !kfifo_is_empty(&port->state->port.xmit_fifo); + return port->x_char || (!uart_tx_stopped(port) && + !kfifo_is_empty(&port->state->port.xmit_fifo)); } static int serial_port_runtime_resume(struct device *dev) From 08daebfd63e9054e097eb2653eff9381de43a422 Mon Sep 17 00:00:00 2001 From: Josef Bacik Date: Tue, 27 Oct 2026 12:06:42 +0100 Subject: [PATCH 06/12] serial: 8250_lpss: don't divide by 0 above 6.25 Mbaud MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit byt_set_termios() derives the clock of the UART from the baud rate in the termios, which nobody has looked at yet: fuart = baud * 16; ... fuart *= rounddown_pow_of_two(fref / fuart); ... p->uartclk = fuart; fref is 100 MHz. For a baud rate above 6250000, which BOTHER allows, fref / fuart is 0, and rounddown_pow_of_two(0) shifts 1UL by -1. On x86 that is 1UL << 63, the product with a multiple of 16 is 0, and so is uartclk. serial8250_get_baud_rate() then passes 0 for both limits, uart_get_baud_rate() finds no rate which fits, WARNs and returns 0, and uart_get_divisor() or dw8250_get_divisor() divide by 16 * 0. Everybody who may open the tty can oops the kernel with one TCSETS2. Don't ask for more than fref. The limits are those of a 100 MHz clock then, and uart_get_baud_rate() falls back to the old rate as for any other rate that the port cannot do. 8250_mid, which has the same formula, treats this case separately. Fixes: 21947ba654a6 ("serial: 8250_pci: replace switch-case by formula") Cc: stable Cc: "Ilpo Järvinen" Cc: Andy Shevchenko Cc: Jiri Slaby Cc: Heikki Krogerus Cc: Peter Hurley Signed-off-by: Josef Bacik Signed-off-by: Greg Kroah-Hartman Link: https://patch.msgid.link/20261027-tty-llm-v1-16-99b0202ae546@linuxfoundation.org Signed-off-by: Greg Kroah-Hartman --- drivers/tty/serial/8250/8250_lpss.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/tty/serial/8250/8250_lpss.c b/drivers/tty/serial/8250/8250_lpss.c index f1b4b975571a..7e88f2b793b5 100644 --- a/drivers/tty/serial/8250/8250_lpss.c +++ b/drivers/tty/serial/8250/8250_lpss.c @@ -83,6 +83,9 @@ static void byt_set_termios(struct uart_port *p, struct ktermios *termios, /* Gracefully handle the B0 case: fall back to B9600 */ fuart = fuart ? fuart : 9600 * 16; + /* Fuart <= Fref: leave it to the core to refuse a higher baud rate */ + fuart = min(fuart, fref); + /* Get Fuart closer to Fref */ fuart *= rounddown_pow_of_two(fref / fuart); From 899e3c6e30ff34cf7a260b806fdedb56749e36e9 Mon Sep 17 00:00:00 2001 From: Josef Bacik Date: Tue, 27 Oct 2026 12:06:43 +0100 Subject: [PATCH 07/12] serial: 8250_mxpcie: handle hangup during break Ending a software break on a Moxa PCIe port in RS-485 2-wire mode dereferences a NULL tty pointer if the port was hung up while the break was being sent. send_break() calls ->break_ctl(tty, -1), sleeps for the break duration and then calls ->break_ctl(tty, 0), without excluding a concurrent hangup. A hangup (a modem DCD drop, or the session leader exiting while another process of the session is in TCSBRK/TCSBRKP) runs uart_hangup(), which shuts the port down and clears port->state->port.tty. The second call still reaches mxpcie8250_software_break_ctl() through uart_break_ctl(), which then does: struct tty_struct *tty = port->state->port.tty; ... baud = tty_get_baud_rate(tty); with tty == NULL. The bug was found by code inspection and has not been reproduced. Fix by taking a reference to the port's tty with tty_port_tty_get() and only restoring the divisor when a tty is still attached; a hung up port is shut down, and the next open programs the divisor again through set_termios(). Fixes: ade78d3d253c ("serial: 8250_mxpcie: add break support for RS485 using MUEx50 features") Cc: stable Cc: Jiri Slaby Cc: Crescent Hsieh Cc: Andy Shevchenko Cc: Linmao Li Signed-off-by: Josef Bacik Signed-off-by: Greg Kroah-Hartman Link: https://patch.msgid.link/20261027-tty-llm-v1-17-99b0202ae546@linuxfoundation.org Signed-off-by: Greg Kroah-Hartman --- drivers/tty/serial/8250/8250_mxpcie.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/drivers/tty/serial/8250/8250_mxpcie.c b/drivers/tty/serial/8250/8250_mxpcie.c index 4935a5d1c1a3..b3418c1ccb05 100644 --- a/drivers/tty/serial/8250/8250_mxpcie.c +++ b/drivers/tty/serial/8250/8250_mxpcie.c @@ -412,7 +412,7 @@ static int mxpcie8250_handle_irq(struct uart_port *port) static void mxpcie8250_software_break_ctl(struct uart_port *port, int break_state) { struct uart_8250_port *up = up_to_u8250p(port); - struct tty_struct *tty = port->state->port.tty; + struct tty_struct *tty; unsigned int baud, quot; u8 sfr, tx_byte = 0x01; @@ -439,9 +439,14 @@ static void mxpcie8250_software_break_ctl(struct uart_port *port, int break_stat serial_out(up, UART_FCR, UART_FCR_CLEAR_XMIT); - baud = tty_get_baud_rate(tty); - quot = uart_get_divisor(port, baud); - serial8250_do_set_divisor(port, baud, quot); + /* A hangup during the break detaches the tty */ + tty = tty_port_tty_get(&port->state->port); + if (tty) { + baud = tty_get_baud_rate(tty); + quot = uart_get_divisor(port, baud); + serial8250_do_set_divisor(port, baud, quot); + tty_kref_put(tty); + } serial_out(up, UART_LCR, up->lcr); } } From 0f0664a63efdfd70d1c555080781f4e8464445aa Mon Sep 17 00:00:00 2001 From: Josef Bacik Date: Tue, 27 Oct 2026 12:06:44 +0100 Subject: [PATCH 08/12] serial: fsl_lpuart: fix tty ref of wakeup event 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 Cc: Jiri Slaby Cc: Frank Li Cc: Peng Fan Cc: Shitalkumar Gandhi Cc: Sherry Sun Signed-off-by: Josef Bacik Signed-off-by: Greg Kroah-Hartman Link: https://patch.msgid.link/20261027-tty-llm-v1-18-99b0202ae546@linuxfoundation.org Signed-off-by: Greg Kroah-Hartman --- 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); + } + } } } From 6d7fbd5a28d092ab61ec0092cf1e085d2bb9ed7e Mon Sep 17 00:00:00 2001 From: Josef Bacik Date: Tue, 27 Oct 2026 12:06:45 +0100 Subject: [PATCH 09/12] serial: imx: fix the tty reference of the wakeup event To report a wakeup event, imx_uart_enable_wakeup() 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. Fixes: 0cfadf4bcd28 ("tty: serial: imx: Add missing wakeup event reporting") Cc: stable Cc: Jiri Slaby Cc: Frank Li Cc: Sascha Hauer Cc: Pengutronix Kernel Team Cc: Fabio Estevam Cc: Robin Gong Cc: Petr Mladek Cc: John Ogness Cc: Pan Chuang Cc: Karl Mehltretter Cc: Sherry Sun Signed-off-by: Josef Bacik Signed-off-by: Greg Kroah-Hartman Link: https://patch.msgid.link/20261027-tty-llm-v1-19-99b0202ae546@linuxfoundation.org Signed-off-by: Greg Kroah-Hartman --- drivers/tty/serial/imx.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c index 986fefb45c63..18892fc4a35b 100644 --- a/drivers/tty/serial/imx.c +++ b/drivers/tty/serial/imx.c @@ -2742,8 +2742,14 @@ static void imx_uart_enable_wakeup(struct imx_port *sport, bool on) imx_uart_writel(sport, ucr1, UCR1); } - 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); + } + } uart_port_unlock_irq(&sport->port); } From 859f7c56709b161a72b629b6f2f1384dcd374404 Mon Sep 17 00:00:00 2001 From: Josef Bacik Date: Tue, 27 Oct 2026 12:06:46 +0100 Subject: [PATCH 10/12] serial: rda: free the interrupt on shutdown MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit rda_uart_startup() requests the interrupt, and nothing ever frees it. It is not shared, so once the port has been closed, the next startup fails with -EBUSY and the port cannot be opened any more. Free it in rda_uart_shutdown(). Fixes: c10b13325ced ("tty: serial: Add RDA8810PL UART driver") Cc: stable Cc: Jiri Slaby Cc: Arnd Bergmann Cc: "Andreas Färber" Cc: Olof Johansson Signed-off-by: Josef Bacik Reviewed-by: Manivannan Sadhasivam Signed-off-by: Greg Kroah-Hartman Link: https://patch.msgid.link/20261027-tty-llm-v1-20-99b0202ae546@linuxfoundation.org Signed-off-by: Greg Kroah-Hartman --- drivers/tty/serial/rda-uart.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/tty/serial/rda-uart.c b/drivers/tty/serial/rda-uart.c index 87fa30d68687..9c1785771cbb 100644 --- a/drivers/tty/serial/rda-uart.c +++ b/drivers/tty/serial/rda-uart.c @@ -471,6 +471,8 @@ static void rda_uart_shutdown(struct uart_port *port) rda_uart_write(port, val, RDA_UART_CTRL); uart_port_unlock_irqrestore(port, flags); + + free_irq(port->irq, port); } static const char *rda_uart_type(struct uart_port *port) From 7ada442f5ef77f8d53f608a0141a5e88a888ca9f Mon Sep 17 00:00:00 2001 From: Josef Bacik Date: Tue, 27 Oct 2026 12:06:47 +0100 Subject: [PATCH 11/12] serial: samsung: don't leak the tty on an RX IRQ s3c24xx_serial_rx_chars_dma() starts by taking a reference to the tty. If the interrupt is not a receive timeout, it switches the port from PIO back to DMA and leaves through the "finish" label, which does not drop the reference. A port with RX DMA changes to PIO on every receive timeout, that is at the end of every burst of data, and comes back this way when the next burst starts. So each burst takes a reference which is never dropped, and the tty structure is not freed when the port is closed for the last time. Drop the reference on both paths. Fixes: b543c301c2c5 ("serial: samsung: add DMA support for RX") Cc: stable Cc: Krzysztof Kozlowski Cc: Peter Griffin Cc: Alim Akhtar Cc: Jiri Slaby Cc: Robert Baldyga Signed-off-by: Josef Bacik Signed-off-by: Greg Kroah-Hartman Link: https://patch.msgid.link/20261027-tty-llm-v1-21-99b0202ae546@linuxfoundation.org Signed-off-by: Greg Kroah-Hartman --- drivers/tty/serial/samsung_tty.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/tty/serial/samsung_tty.c b/drivers/tty/serial/samsung_tty.c index 640f85e2d636..c9a870a8d155 100644 --- a/drivers/tty/serial/samsung_tty.c +++ b/drivers/tty/serial/samsung_tty.c @@ -736,14 +736,13 @@ static irqreturn_t s3c24xx_serial_rx_chars_dma(struct s3c24xx_uart_port *ourport s3c24xx_serial_rx_drain_fifo(ourport); - if (tty) { + if (tty) tty_flip_buffer_push(t); - tty_kref_put(tty); - } wr_regl(port, S3C2410_UTRSTAT, S3C2410_UTRSTAT_TIMEOUT); finish: + tty_kref_put(tty); uart_port_unlock(port); return IRQ_HANDLED; From eedf2cf3505c1562a2fb24f8b997056f023d242b Mon Sep 17 00:00:00 2001 From: Josef Bacik Date: Tue, 27 Oct 2026 12:06:48 +0100 Subject: [PATCH 12/12] serial: samsung: put the previous baud clock s3c24xx_serial_getclk() returns the best baud clock with the reference which clk_get() has taken. s3c24xx_serial_set_termios() stores it in ourport->baudclk and disables the clock which was there before, but does not put it. clk_get() hands out a new handle on every call, so the new clock never equals the old one, and every call of ->set_termios() leaks a handle: a struct clk and a copy of the connection name. Whoever has the port open can repeat that at will with tcsetattr(). Put the old clock when it is replaced, and the new one in case it is not stored. Fixes: 5f5a7a5578c5 ("serial: samsung: switch to clkdev based clock lookup") Cc: stable Cc: Krzysztof Kozlowski Cc: Peter Griffin Cc: Alim Akhtar Cc: Jiri Slaby Cc: Kukjin Kim Cc: Thomas Abraham Signed-off-by: Josef Bacik Signed-off-by: Greg Kroah-Hartman Link: https://patch.msgid.link/20261027-tty-llm-v1-22-99b0202ae546@linuxfoundation.org Signed-off-by: Greg Kroah-Hartman --- drivers/tty/serial/samsung_tty.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/tty/serial/samsung_tty.c b/drivers/tty/serial/samsung_tty.c index c9a870a8d155..f437f7363fd3 100644 --- a/drivers/tty/serial/samsung_tty.c +++ b/drivers/tty/serial/samsung_tty.c @@ -1501,11 +1501,14 @@ static void s3c24xx_serial_set_termios(struct uart_port *port, if (!IS_ERR(ourport->baudclk)) { clk_disable_unprepare(ourport->baudclk); + clk_put(ourport->baudclk); ourport->baudclk = ERR_PTR(-EINVAL); } ourport->baudclk = clk; ourport->baudclk_rate = clk ? clk_get_rate(clk) : 0; + } else { + clk_put(clk); } if (ourport->info->has_divslot) {