serial: pl011: Avoid assumptions about buffer size when refilling TX DMA
authorAndrew Jackson <Andrew.Jackson@arm.com>
Fri, 7 Nov 2014 14:14:39 +0000 (14:14 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 7 Nov 2014 16:35:55 +0000 (08:35 -0800)
The existing code assumed that PL011_DMA_BUFFER_SIZE == UART_XMIT_SIZE,
which may not always be the case.  This allows for these two being
different sizes and not copying too much data.

Signed-off-by: Andrew Jackson <Andrew.Jackson@arm.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/tty/serial/amba-pl011.c

index 8654049..6153a42 100644 (file)
@@ -501,7 +501,11 @@ static int pl011_dma_tx_refill(struct uart_amba_port *uap)
                memcpy(&dmatx->buf[0], &xmit->buf[xmit->tail], count);
        else {
                size_t first = UART_XMIT_SIZE - xmit->tail;
-               size_t second = xmit->head;
+               size_t second;
+
+               if (first > count)
+                       first = count;
+               second = count - first;
 
                memcpy(&dmatx->buf[0], &xmit->buf[xmit->tail], first);
                if (second)