FAILED: patch "[PATCH] serial: xilinx_uartps: fix rs485 delay_rts_after_send" failed to apply to 6.12-stable tree
Subsystems (3)
[email protected]
maintainerThe patch below does not apply to the 6.12-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.12.y
git checkout FETCH_HEAD
git cherry-pick -x 267ee93c417e685d9f8e079e41c70ba6ee4df5a5
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2025122923-amaretto-output-f3dc@gregkh' --subject-prefix 'PATCH 6.12.y' HEAD^..
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 267ee93c417e685d9f8e079e41c70ba6ee4df5a5 Mon Sep 17 00:00:00 2001
From: "j.turek" <[email protected]>
Date: Sun, 21 Dec 2025 11:32:21 +0100
Subject: [PATCH] serial: xilinx_uartps: fix rs485 delay_rts_after_send
RTS line control with delay should be triggered when there is no more bytes in kfifo and hardware buffer is empty. Without this patch RTS control is scheduled right after feeding hardware buffer and this is too early.
RTS line may change state before hardware buffer is empty.
With this patch delayed RTS state change is triggered when function cdns_uart_handle_tx is called from cdns_uart_isr on CDNS_UART_IXR_TXEMPTY exactly when hardware completed transmission
drivers/tty/serial/xilinx_uartps.c +7 -7
@@ -428,10 +428,17 @@ static void cdns_uart_handle_tx(void *dev_id)struct tty_port *tport = &port->state->port;unsigned int numbytes;unsigned char ch; +ktime_t rts_delay;if (kfifo_is_empty (&tport->xmit_fifo) ||uart_tx_stopped (port)) {/* Disable the TX Empty interrupt */ writel (CDNS_UART_IXR_TXEMPTY , port->membase +CDNS_UART_IDR ); +/* Set RTS line after delay */ +if (cdns_uart->port->rs485.flags &SER_RS485_ENABLED ) { + cdns_uart->tx_timer.function = &cdns_rs485_rx_callback; + rts_delay =ns_to_ktime (cdns_calc_after_tx_delay (cdns_uart)); +hrtimer_start (&cdns_uart->tx_timer, rts_delay,HRTIMER_MODE_REL ); + }return ; }
@@ -448,13 +455,6 @@ static void cdns_uart_handle_tx(void *dev_id)/* Enable the TX Empty interrupt */ writel (CDNS_UART_IXR_TXEMPTY , cdns_uart->port->membase +CDNS_UART_IER ); - -if (cdns_uart->port->rs485.flags &SER_RS485_ENABLED && - (kfifo_is_empty (&tport->xmit_fifo) ||uart_tx_stopped (port))) { -hrtimer_update_function (&cdns_uart->tx_timer, cdns_rs485_rx_callback); -hrtimer_start (&cdns_uart->tx_timer, -ns_to_ktime (cdns_calc_after_tx_delay (cdns_uart)),HRTIMER_MODE_REL ); - } }/**
Sasha Levin
maintainerPATCH 1/3 hrtimers: Introduce hrtimer_update_function()
From: Nam Cao <[email protected]>
[ Upstream commit 8f02e3563bb5824eb01c94f2c75f1dcee2d05625 ]
Some users of hrtimer need to change the callback function after the initial setup. They write to hrtimer::function directly.
That's not safe under all circumstances as the write is lockless and a concurrent timer expiry might end up using the wrong function pointer.
Introduce hrtimer_update_function(), which also performs runtime checks whether it is safe to modify the callback.
This allows to make hrtimer::function private once all users are converted.
Stable-dep-of: 267ee93c417e ("serial: xilinx_uartps: fix rs485 delay_rts_after_send")
--- include/linux/hrtimer.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
include/linux/hrtimer.h +22 -0
@@ -337,6 +337,28 @@ static inline int hrtimer_callback_running(struct hrtimer *timer)return timer->base->running == timer; } +/** +* hrtimer_update_function - Update the timer's callback function +* @timer: Timer to update +* @function: New callback function +* +* Only safe to call if the timer is not enqueued. Can be called in the callback function if the +* timer is not enqueued at the same time (see the comments above HRTIMER_STATE_ENQUEUED). +*/ +static inline void hrtimer_update_function (struct hrtimer *timer, +enum hrtimer_restart (*function)(struct hrtimer *)) +{ +guard (raw_spinlock_irqsave)(&timer->base->cpu_base->lock); + +if (WARN_ON_ONCE (hrtimer_is_queued (timer))) +return ; + +if (WARN_ON_ONCE (!function)) +return ; + + timer->function = function; +} +/* Forward a hrtimer so it expires after now: */ extern u64 hrtimer_forward (struct hrtimer *timer,ktime_t now,ktime_t interval);
Signature · 1 line
2.51.0
Sasha Levin
maintainerPATCH 2/3 serial: xilinx_uartps: Use helper function hrtimer_update_function()
From: Nam Cao <[email protected]>
[ Upstream commit eee00df8e1f1f5648ed8f9e40e2bb54c2877344a ]
The field 'function' of struct hrtimer should not be changed directly, as the write is lockless and a concurrent timer expiry might end up using the wrong function pointer.
Switch to use hrtimer_update_function() which also performs runtime checks that it is safe to modify the callback.
Stable-dep-of: 267ee93c417e ("serial: xilinx_uartps: fix rs485 delay_rts_after_send")
--- drivers/tty/serial/xilinx_uartps.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/tty/serial/xilinx_uartps.c +2 -2
@@ -454,7 +454,7 @@ static void cdns_uart_handle_tx(void *dev_id)if (cdns_uart->port->rs485.flags &SER_RS485_ENABLED && (kfifo_is_empty (&tport->xmit_fifo) ||uart_tx_stopped (port))) { - cdns_uart->tx_timer.function = &cdns_rs485_rx_callback; +hrtimer_update_function (&cdns_uart->tx_timer, cdns_rs485_rx_callback);hrtimer_start (&cdns_uart->tx_timer,ns_to_ktime (cdns_calc_after_tx_delay (cdns_uart)),HRTIMER_MODE_REL ); }
@@ -734,7 +734,7 @@ static void cdns_uart_start_tx(struct uart_port *port)if (cdns_uart->port->rs485.flags &SER_RS485_ENABLED ) {if (!cdns_uart->rs485_tx_started) { - cdns_uart->tx_timer.function = &cdns_rs485_tx_callback; +hrtimer_update_function (&cdns_uart->tx_timer, cdns_rs485_tx_callback);cdns_rs485_tx_setup (cdns_uart); return hrtimer_start(&cdns_uart->tx_timer, ms_to_ktime(port->rs485.delay_rts_before_send),
Signature · 1 line
2.51.0
Sasha Levin
maintainerPATCH 3/3 serial: xilinx_uartps: fix rs485 delay_rts_after_send
In reply to Sasha LevinFrom: "j.turek" <[email protected]>
[ Upstream commit 267ee93c417e685d9f8e079e41c70ba6ee4df5a5 ]
RTS line control with delay should be triggered when there is no more bytes in kfifo and hardware buffer is empty. Without this patch RTS control is scheduled right after feeding hardware buffer and this is too early.
RTS line may change state before hardware buffer is empty.
With this patch delayed RTS state change is triggered when function cdns_uart_handle_tx is called from cdns_uart_isr on CDNS_UART_IXR_TXEMPTY exactly when hardware completed transmission
--- drivers/tty/serial/xilinx_uartps.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/tty/serial/xilinx_uartps.c +7 -7
@@ -431,10 +431,17 @@ static void cdns_uart_handle_tx(void *dev_id)struct tty_port *tport = &port->state->port;unsigned int numbytes;unsigned char ch; +ktime_t rts_delay;if (kfifo_is_empty (&tport->xmit_fifo) ||uart_tx_stopped (port)) {/* Disable the TX Empty interrupt */ writel (CDNS_UART_IXR_TXEMPTY , port->membase +CDNS_UART_IDR ); +/* Set RTS line after delay */ +if (cdns_uart->port->rs485.flags &SER_RS485_ENABLED ) { + cdns_uart->tx_timer.function = &cdns_rs485_rx_callback; + rts_delay =ns_to_ktime (cdns_calc_after_tx_delay (cdns_uart)); +hrtimer_start (&cdns_uart->tx_timer, rts_delay,HRTIMER_MODE_REL ); + }return ; }
@@ -451,13 +458,6 @@ static void cdns_uart_handle_tx(void *dev_id)/* Enable the TX Empty interrupt */ writel (CDNS_UART_IXR_TXEMPTY , cdns_uart->port->membase +CDNS_UART_IER ); - -if (cdns_uart->port->rs485.flags &SER_RS485_ENABLED && - (kfifo_is_empty (&tport->xmit_fifo) ||uart_tx_stopped (port))) { -hrtimer_update_function (&cdns_uart->tx_timer, cdns_rs485_rx_callback); -hrtimer_start (&cdns_uart->tx_timer, -ns_to_ktime (cdns_calc_after_tx_delay (cdns_uart)),HRTIMER_MODE_REL ); - } }/**
Signature · 1 line
2.51.0