Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

serial: Refactor uart_flush_buffer() from uart_close()

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>

authored by

Peter Hurley and committed by
Greg Kroah-Hartman
479e9b94 86c80a8e

+34 -28
+1
drivers/tty/serial/amba-pl011.c
··· 1689 1689 plat->exit(); 1690 1690 } 1691 1691 1692 + pl011_dma_flush_buffer(port); 1692 1693 } 1693 1694 1694 1695 static void
+15 -13
drivers/tty/serial/atmel_serial.c
··· 1802 1802 } 1803 1803 1804 1804 /* 1805 + * Flush any TX data submitted for DMA. Called when the TX circular 1806 + * buffer is reset. 1807 + */ 1808 + static void atmel_flush_buffer(struct uart_port *port) 1809 + { 1810 + struct atmel_uart_port *atmel_port = to_atmel_uart_port(port); 1811 + 1812 + if (atmel_use_pdc_tx(port)) { 1813 + UART_PUT_TCR(port, 0); 1814 + atmel_port->pdc_tx.ofs = 0; 1815 + } 1816 + } 1817 + 1818 + /* 1805 1819 * Disable the port 1806 1820 */ 1807 1821 static void atmel_shutdown(struct uart_port *port) ··· 1866 1852 atmel_free_gpio_irq(port); 1867 1853 1868 1854 atmel_port->ms_irq_enabled = false; 1869 - } 1870 1855 1871 - /* 1872 - * Flush any TX data submitted for DMA. Called when the TX circular 1873 - * buffer is reset. 1874 - */ 1875 - static void atmel_flush_buffer(struct uart_port *port) 1876 - { 1877 - struct atmel_uart_port *atmel_port = to_atmel_uart_port(port); 1878 - 1879 - if (atmel_use_pdc_tx(port)) { 1880 - UART_PUT_TCR(port, 0); 1881 - atmel_port->pdc_tx.ofs = 0; 1882 - } 1856 + atmel_flush_buffer(port); 1883 1857 } 1884 1858 1885 1859 /*
+16 -14
drivers/tty/serial/serial-tegra.c
··· 1034 1034 return ret; 1035 1035 } 1036 1036 1037 + /* 1038 + * Flush any TX data submitted for DMA and PIO. Called when the 1039 + * TX circular buffer is reset. 1040 + */ 1041 + static void tegra_uart_flush_buffer(struct uart_port *u) 1042 + { 1043 + struct tegra_uart_port *tup = to_tegra_uport(u); 1044 + 1045 + tup->tx_bytes = 0; 1046 + if (tup->tx_dma_chan) 1047 + dmaengine_terminate_all(tup->tx_dma_chan); 1048 + return; 1049 + } 1050 + 1037 1051 static void tegra_uart_shutdown(struct uart_port *u) 1038 1052 { 1039 1053 struct tegra_uart_port *tup = to_tegra_uport(u); ··· 1060 1046 tegra_uart_dma_channel_free(tup, true); 1061 1047 tegra_uart_dma_channel_free(tup, false); 1062 1048 free_irq(u->irq, tup); 1049 + 1050 + tegra_uart_flush_buffer(u); 1063 1051 } 1064 1052 1065 1053 static void tegra_uart_enable_ms(struct uart_port *u) ··· 1187 1171 tegra_uart_read(tup, UART_IER); 1188 1172 1189 1173 spin_unlock_irqrestore(&u->lock, flags); 1190 - return; 1191 - } 1192 - 1193 - /* 1194 - * Flush any TX data submitted for DMA and PIO. Called when the 1195 - * TX circular buffer is reset. 1196 - */ 1197 - static void tegra_uart_flush_buffer(struct uart_port *u) 1198 - { 1199 - struct tegra_uart_port *tup = to_tegra_uport(u); 1200 - 1201 - tup->tx_bytes = 0; 1202 - if (tup->tx_dma_chan) 1203 - dmaengine_terminate_all(tup->tx_dma_chan); 1204 1174 return; 1205 1175 } 1206 1176
-1
drivers/tty/serial/serial_core.c
··· 1361 1361 1362 1362 mutex_lock(&port->mutex); 1363 1363 uart_shutdown(tty, state); 1364 - uart_flush_buffer(tty); 1365 1364 1366 1365 tty_ldisc_flush(tty); 1367 1366
+2
drivers/tty/serial/timbuart.c
··· 273 273 dev_dbg(port->dev, "%s\n", __func__); 274 274 free_irq(port->irq, uart); 275 275 iowrite32(0, port->membase + TIMBUART_IER); 276 + 277 + timbuart_flush_buffer(port); 276 278 } 277 279 278 280 static int get_bindex(int baud)