Skip to content

Commit

Permalink
serial: sh-sci: let timeout timer only run when DMA is scheduled
Browse files Browse the repository at this point in the history
The hrtimer for RXDMA timeout was unconditionally restarted in the RXDMA
complete handler ignoring the fact that setting up DMA may fail and PIO
is used instead. Explicitly stop the timer when DMA is completed and
only restart it when setting up DMA was successful. This makes the
intention of the timer much clearer, the driver easier to understand and
simplifies assumptions about the timer. The latter avoids race
conditions if these assumptions were not met or confused.

Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Link: https://lore.kernel.org/r/20240506114016.30498-9-wsa+renesas@sang-engineering.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Wolfram Sang authored and Greg Kroah-Hartman committed May 10, 2024
1 parent 8efc440 commit 0c9c1ea
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions drivers/tty/serial/sh-sci.c
Original file line number Diff line number Diff line change
Expand Up @@ -1324,14 +1324,14 @@ static void sci_dma_rx_complete(void *arg)
dev_dbg(port->dev, "%s(%d) active cookie %d\n", __func__, port->line,
s->active_rx);

hrtimer_cancel(&s->rx_timer);

uart_port_lock_irqsave(port, &flags);

active = sci_dma_rx_find_active(s);
if (active >= 0)
count = sci_dma_rx_push(s, s->rx_buf[active], s->buf_len_rx);

start_hrtimer_us(&s->rx_timer, s->rx_timeout);

if (count)
tty_flip_buffer_push(&port->state->port);

Expand All @@ -1354,6 +1354,9 @@ static void sci_dma_rx_complete(void *arg)
uart_port_unlock_irqrestore(port, flags);
dev_dbg(port->dev, "%s: cookie %d #%d, new active cookie %d\n",
__func__, s->cookie_rx[active], active, s->active_rx);

start_hrtimer_us(&s->rx_timer, s->rx_timeout);

return;

fail:
Expand Down

0 comments on commit 0c9c1ea

Please sign in to comment.