Skip to content

Commit 7363181

Browse files
jiada-wanggregkh
authored andcommitted
serial: imx: use locking to stop concurrent access of UCR1
Several places are accessing the UCR1 register without locking. This probably will cause a race issue when another thread is accessing the same register. Add locking to preventing concurrent access of the UCR1 register. Signed-off-by: Jiada Wang <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 55d8693 commit 7363181

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

drivers/tty/serial/imx.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,9 @@ static int start_rx_dma(struct imx_port *sport);
731731
static void imx_dma_rxint(struct imx_port *sport)
732732
{
733733
unsigned long temp;
734+
unsigned long flags;
735+
736+
spin_lock_irqsave(&sport->port.lock, flags);
734737

735738
temp = readl(sport->port.membase + USR2);
736739
if ((temp & USR2_RDR) && !sport->dma_is_rxing) {
@@ -744,6 +747,8 @@ static void imx_dma_rxint(struct imx_port *sport)
744747
/* tell the DMA to receive the data. */
745748
start_rx_dma(sport);
746749
}
750+
751+
spin_unlock_irqrestore(&sport->port.lock, flags);
747752
}
748753

749754
static irqreturn_t imx_int(int irq, void *dev_id)
@@ -873,6 +878,9 @@ static int imx_setup_ufcr(struct imx_port *sport, unsigned int mode)
873878
static void imx_rx_dma_done(struct imx_port *sport)
874879
{
875880
unsigned long temp;
881+
unsigned long flags;
882+
883+
spin_lock_irqsave(&sport->port.lock, flags);
876884

877885
/* Enable this interrupt when the RXFIFO is empty. */
878886
temp = readl(sport->port.membase + UCR1);
@@ -884,6 +892,8 @@ static void imx_rx_dma_done(struct imx_port *sport)
884892
/* Is the shutdown waiting for us? */
885893
if (waitqueue_active(&sport->dma_wait))
886894
wake_up(&sport->dma_wait);
895+
896+
spin_unlock_irqrestore(&sport->port.lock, flags);
887897
}
888898

889899
/*
@@ -1194,9 +1204,11 @@ static void imx_shutdown(struct uart_port *port)
11941204
dmaengine_terminate_all(sport->dma_chan_tx);
11951205
dmaengine_terminate_all(sport->dma_chan_rx);
11961206
}
1207+
spin_lock_irqsave(&sport->port.lock, flags);
11971208
imx_stop_tx(port);
11981209
imx_stop_rx(port);
11991210
imx_disable_dma(sport);
1211+
spin_unlock_irqrestore(&sport->port.lock, flags);
12001212
imx_uart_dma_exit(sport);
12011213
}
12021214

0 commit comments

Comments
 (0)