serial/imx: check that the buffer is non-empty before sending it out
authorVolker Ernst <volker.ernst@txtr.com>
Wed, 13 Oct 2010 09:03:57 +0000 (11:03 +0200)
committerGreg Kroah-Hartman <gregkh@suse.de>
Fri, 22 Oct 2010 17:20:10 +0000 (10:20 -0700)
The .start_tx callback (imx_start_tx here) isn't only called when the
buffer is non-empty.  E.g. after resume or when handshaking is enabled
and the other side starts to signal being ready.

So check for an empty puffer already before sending the first character.
This prevents sending out stale (or uninitialised) data.

Signed-off-by: Volker Ernst <volker.ernst@txtr.com>
Signed-off-by: Daniel Mack <daniel@caiaq.de>
Cc: Andy Green <andy@warmcat.com>
[ukl: reword commit log, put check in while condition]
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
drivers/serial/imx.c

index 66ecc7ab6daba803c5c74f8fa06a6a6b105b8f8c..dfcf4b1878aa3f2596fc9d6a8ffa21722bb2224e 100644 (file)
@@ -327,14 +327,13 @@ static inline void imx_transmit_buffer(struct imx_port *sport)
 {
        struct circ_buf *xmit = &sport->port.state->xmit;
 
-       while (!(readl(sport->port.membase + UTS) & UTS_TXFULL)) {
+       while (!uart_circ_empty(xmit) &&
+                       !(readl(sport->port.membase + UTS) & UTS_TXFULL)) {
                /* send xmit->buf[xmit->tail]
                 * out the port here */
                writel(xmit->buf[xmit->tail], sport->port.membase + URTX0);
                xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
                sport->port.icount.tx++;
-               if (uart_circ_empty(xmit))
-                       break;
        }
 
        if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)