Fix some issues identified by Andrew Morton:
  * Kill unused PDC_RX_BUF() and PDC_RX_SWITCH() macros
  * Simplify TX circ buffer management a bit.
  * Don't open-code min()
  * Add comment explaining why "count = head - tail" will not cause
    wraparound problems.

Also, s/SERIAL_XMIT_SIZE/UART_XMIT_SIZE/ since the latter is what the
serial core circ macros use.

Signed-off-by: Haavard Skinnemoen <[EMAIL PROTECTED]>
---
Please fold into atmel_serial-add-dma-support.patch, or let me know if
you want a replacement for that patch.

 drivers/serial/atmel_serial.c |   27 +++++++++++++--------------
 1 files changed, 13 insertions(+), 14 deletions(-)

diff --git a/drivers/serial/atmel_serial.c b/drivers/serial/atmel_serial.c
index 63505cc..62654ab 100644
--- a/drivers/serial/atmel_serial.c
+++ b/drivers/serial/atmel_serial.c
@@ -114,7 +114,7 @@ static void (*atmel_close_hook)(struct uart_port *);
 struct atmel_dma_buffer {
        unsigned char   *buf;
        dma_addr_t      dma_addr;
-       size_t          dma_size;
+       unsigned int    dma_size;
        unsigned int    ofs;
 };
 
@@ -150,9 +150,6 @@ struct atmel_uart_port {
 
 static struct atmel_uart_port atmel_ports[ATMEL_MAX_UART];
 
-#define PDC_RX_BUF(port)       &(port)->pdc_rx[(port)->pdc_rx_idx]
-#define PDC_RX_SWITCH(port)    (port)->pdc_rx_idx = !(port)->pdc_rx_idx
-
 #ifdef SUPPORT_SYSRQ
 static struct console atmel_console;
 #endif
@@ -567,8 +564,7 @@ static void atmel_tx_dma(struct uart_port *port)
        int count;
 
        xmit->tail += pdc->ofs;
-       if (xmit->tail >= SERIAL_XMIT_SIZE)
-               xmit->tail -= SERIAL_XMIT_SIZE;
+       xmit->tail &= UART_XMIT_SIZE - 1;
 
        port->icount.tx += pdc->ofs;
        pdc->ofs = 0;
@@ -583,10 +579,7 @@ static void atmel_tx_dma(struct uart_port *port)
                                           pdc->dma_size,
                                           DMA_TO_DEVICE);
 
-               if (xmit->tail < xmit->head)
-                       count = xmit->head - xmit->tail;
-               else
-                       count = SERIAL_XMIT_SIZE - xmit->tail;
+               count = CIRC_CNT_TO_END(xmit->head, xmit->tail, UART_XMIT_SIZE);
                pdc->ofs = count;
 
                UART_PUT_TPR(port, pdc->dma_addr + xmit->tail);
@@ -701,14 +694,20 @@ static void atmel_rx_from_dma(struct uart_port *port)
                 * ENDRX bit as well, so that we can safely re-enable
                 * all interrupts below.
                 */
-               if (head >= pdc->dma_size)
-                       head = pdc->dma_size;
+               head = min(head, pdc->dma_size);
 
                if (likely(head != tail)) {
                        dma_sync_single_for_cpu(port->dev, pdc->dma_addr,
                                        pdc->dma_size, DMA_FROM_DEVICE);
 
+                       /*
+                        * head will only wrap around when we recycle
+                        * the DMA buffer, and when that happens, we
+                        * explicitly set tail to 0. So head will
+                        * always be greater than tail.
+                        */
                        count = head - tail;
+
                        tty_insert_flip_string(tty, pdc->buf + pdc->ofs, count);
 
                        dma_sync_single_for_device(port->dev, pdc->dma_addr,
@@ -859,9 +858,9 @@ static int atmel_startup(struct uart_port *port)
                pdc->buf = xmit->buf;
                pdc->dma_addr = dma_map_single(port->dev,
                                               pdc->buf,
-                                              SERIAL_XMIT_SIZE,
+                                              UART_XMIT_SIZE,
                                               DMA_TO_DEVICE);
-               pdc->dma_size = SERIAL_XMIT_SIZE;
+               pdc->dma_size = UART_XMIT_SIZE;
                pdc->ofs = 0;
        }
 
-- 
1.5.3.8

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to