serial: pl011: Avoid assumptions about buffer size when refilling TX DMA
authorAndrew Jackson <Andrew.Jackson@arm.com>
Mon, 27 Oct 2014 14:29:56 +0000 (14:29 +0000)
committerLiviu Dudau <Liviu.Dudau@arm.com>
Fri, 31 Oct 2014 12:22:16 +0000 (12:22 +0000)
The existing code assumed that all the bytes in the
buffer are consumed in a call.  This isn't the case
since the count is adjusted.

Signed-off-by: Andrew Jackson <Andrew.Jackson@arm.com>
drivers/tty/serial/amba-pl011.c

index 2c9bfb263839df83f4166260a8634aa6bef0bd8f..c533bb334355838761e4519bc1b1ac8b5b6f6a8d 100644 (file)
@@ -501,11 +501,17 @@ 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;
+
+               if (first > count)
+                       first = count;
+               else {
+                       size_t second = count - first;
+
+                       if (second)
+                               memcpy(&dmatx->buf[first], &xmit->buf[0], second);
+               }
 
                memcpy(&dmatx->buf[0], &xmit->buf[xmit->tail], first);
-               if (second)
-                       memcpy(&dmatx->buf[first], &xmit->buf[0], second);
        }
 
        dmatx->sg.length = count;