[PATCH] serial: xilinx_uartps: fix oops when disabling RS-485
From: Niko Mauno
Date: Fri Nov 13 2026 - 15:07:06 EST
cdns_rs485_config() sets up tx_timer only when RS-485 is enabled, but
cancels it when RS-485 is disabled. A TIOCSRS485 that disables RS-485
on a port that was never in RS-485 mode cancels a zero-filled hrtimer
and oopses:
Unable to handle kernel NULL pointer dereference at virtual address 0000000c when read
PC is at hrtimer_active+0x4/0x94
LR is at hrtimer_cancel+0x10/0x64
...
Call trace:
hrtimer_active from hrtimer_cancel+0x10/0x64
hrtimer_cancel from cdns_rs485_config+0x10c/0x11c
cdns_rs485_config from uart_ioctl+0x7a4/0xc3c
uart_ioctl from tty_ioctl+0x3ec/0xbcc
Set the timer up once in probe instead. This also stops a TIOCSRS485
that enables RS-485 again from re-initialising the timer while a
transmit delay may have it queued. The callback is switched at run
time by the existing call sites, so its initial value does not matter.
Fixes: fccc9d9233f9 ("tty: serial: uartps: Add rs485 support to uartps driver")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Niko Mauno <niko.mauno@xxxxxxxxxxx>
---
Tested on a Zynq-7000 board on 6.12.y: without this patch the first
TIOCSRS485 that disables RS-485 after boot oopses as above; with it,
repeated enable/transmit/disable cycles run clean. Also reproduced and
verified on v7.4-rc1 in QEMU.
drivers/tty/serial/xilinx_uartps.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/drivers/tty/serial/xilinx_uartps.c b/drivers/tty/serial/xilinx_uartps.c
index e8c4b1fa7658..f93e374f6d0e 100644
--- a/drivers/tty/serial/xilinx_uartps.c
+++ b/drivers/tty/serial/xilinx_uartps.c
@@ -1620,10 +1620,6 @@ static int cdns_rs485_config(struct uart_port *port, struct ktermios *termios,
val &= ~CDNS_UART_MODEMCR_FCM;
writel(val, port->membase + CDNS_UART_MODEMCR);
- /* Timer setup */
- hrtimer_setup(&cdns_uart->tx_timer, &cdns_rs485_tx_callback, CLOCK_MONOTONIC,
- HRTIMER_MODE_REL);
-
/* Disable transmitter and make Rx setup*/
cdns_uart_stop_tx(port);
} else {
@@ -1782,6 +1778,8 @@ static int cdns_uart_probe(struct platform_device *pdev)
port->rs485_config = cdns_rs485_config;
port->rs485_supported = cdns_rs485_supported;
cdns_uart_data->port = port;
+ hrtimer_setup(&cdns_uart_data->tx_timer, &cdns_rs485_tx_callback,
+ CLOCK_MONOTONIC, HRTIMER_MODE_REL);
platform_set_drvdata(pdev, port);
rc = uart_get_rs485_mode(port);
base-commit: 067c5c24cef23d913b67eaaf71ae67e7169a6620
--
2.47.3