]> git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/commitdiff
serial: Refactor uart_flush_buffer() from uart_close()
authorPeter Hurley <peter@hurleysoftware.com>
Thu, 16 Oct 2014 20:54:18 +0000 (16:54 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 6 Nov 2014 02:53:54 +0000 (18:53 -0800)
In the context of the final tty & port close, flushing the tx
ring buffer after the hardware has already been shutdown and
the ring buffer freed is neither required nor desirable.

uart_flush_buffer() performs 3 operations:
1. Resets tx ring buffer indices, but the tx ring buffer has
   already been freed and the indices are reset if the port is
   re-opened.
2. Calls uart driver's flush_buffer() method
   5 in-tree uart drivers define flush_buffer() methods:
     amba-pl011, atmel-serial, imx, serial-tegra, timbuart
   These have been refactored into the shutdown() method, if
   required.
3. Kicks the ldisc for more writing, but this is undesirable.
   The file handle is being released; any waiting writer will
   will be kicked out by tty_release() with a warning. Further,
   the N_TTY ldisc may generate SIGIO for a file handle which
   is no longer valid.

Cc: Nicolas Ferre <nicolas.ferre@atmel.com>
Cc: Russell King <linux@arm.linux.org.uk>
Cc: Laxman Dewangan <ldewangan@nvidia.com>
Signed-off-by: Peter Hurley <peter@hurleysoftware.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/tty/serial/amba-pl011.c
drivers/tty/serial/atmel_serial.c
drivers/tty/serial/serial-tegra.c
drivers/tty/serial/serial_core.c
drivers/tty/serial/timbuart.c

index 02016fcd91b850424c7534ce5a5ddc0ab7e6ecd1..8469b66ff832252b427aa22945e7a6f8363d8817 100644 (file)
@@ -1689,6 +1689,7 @@ static void pl011_shutdown(struct uart_port *port)
                        plat->exit();
        }
 
+       pl011_dma_flush_buffer(port);
 }
 
 static void
index edde3eca055d055b3978273deb9058713c2d7a09..8a84034d130c65b0e0435b6e270381b1ec620845 100644 (file)
@@ -1801,6 +1801,20 @@ free_irq:
        return retval;
 }
 
+/*
+ * Flush any TX data submitted for DMA. Called when the TX circular
+ * buffer is reset.
+ */
+static void atmel_flush_buffer(struct uart_port *port)
+{
+       struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
+
+       if (atmel_use_pdc_tx(port)) {
+               UART_PUT_TCR(port, 0);
+               atmel_port->pdc_tx.ofs = 0;
+       }
+}
+
 /*
  * Disable the port
  */
@@ -1852,20 +1866,8 @@ static void atmel_shutdown(struct uart_port *port)
        atmel_free_gpio_irq(port);
 
        atmel_port->ms_irq_enabled = false;
-}
 
-/*
- * Flush any TX data submitted for DMA. Called when the TX circular
- * buffer is reset.
- */
-static void atmel_flush_buffer(struct uart_port *port)
-{
-       struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
-
-       if (atmel_use_pdc_tx(port)) {
-               UART_PUT_TCR(port, 0);
-               atmel_port->pdc_tx.ofs = 0;
-       }
+       atmel_flush_buffer(port);
 }
 
 /*
index 53d7c31ce0986cb542208c4270b885af664b0786..78a5cf65bf02016fcd6f660af3551e491496af9a 100644 (file)
@@ -1034,6 +1034,20 @@ fail_rx_dma:
        return ret;
 }
 
+/*
+ * Flush any TX data submitted for DMA and PIO. Called when the
+ * TX circular buffer is reset.
+ */
+static void tegra_uart_flush_buffer(struct uart_port *u)
+{
+       struct tegra_uart_port *tup = to_tegra_uport(u);
+
+       tup->tx_bytes = 0;
+       if (tup->tx_dma_chan)
+               dmaengine_terminate_all(tup->tx_dma_chan);
+       return;
+}
+
 static void tegra_uart_shutdown(struct uart_port *u)
 {
        struct tegra_uart_port *tup = to_tegra_uport(u);
@@ -1046,6 +1060,8 @@ static void tegra_uart_shutdown(struct uart_port *u)
        tegra_uart_dma_channel_free(tup, true);
        tegra_uart_dma_channel_free(tup, false);
        free_irq(u->irq, tup);
+
+       tegra_uart_flush_buffer(u);
 }
 
 static void tegra_uart_enable_ms(struct uart_port *u)
@@ -1174,20 +1190,6 @@ static void tegra_uart_set_termios(struct uart_port *u,
        return;
 }
 
-/*
- * Flush any TX data submitted for DMA and PIO. Called when the
- * TX circular buffer is reset.
- */
-static void tegra_uart_flush_buffer(struct uart_port *u)
-{
-       struct tegra_uart_port *tup = to_tegra_uport(u);
-
-       tup->tx_bytes = 0;
-       if (tup->tx_dma_chan)
-               dmaengine_terminate_all(tup->tx_dma_chan);
-       return;
-}
-
 static const char *tegra_uart_type(struct uart_port *u)
 {
        return TEGRA_UART_TYPE;
index 1166c52e51f46f706c4c8a4704b211b4a418ef6d..787d67f74bd922bf3206608a02fd89fcf37873d5 100644 (file)
@@ -1361,7 +1361,6 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
 
        mutex_lock(&port->mutex);
        uart_shutdown(tty, state);
-       uart_flush_buffer(tty);
 
        tty_ldisc_flush(tty);
 
index 0d11d5032b938e4df90522717b08e6d4fd3e8ab1..e9e252324fb672d5843f754b61c278568444b0cc 100644 (file)
@@ -273,6 +273,8 @@ static void timbuart_shutdown(struct uart_port *port)
        dev_dbg(port->dev, "%s\n", __func__);
        free_irq(port->irq, uart);
        iowrite32(0, port->membase + TIMBUART_IER);
+
+       timbuart_flush_buffer(port);
 }
 
 static int get_bindex(int baud)