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

Configure Feed

Select the types of activity you want to include in your feed.

serial: take termios_rwsem for ->rs485_config() & pass termios as param

To be able to alter ADDRB within ->rs485_config(), take termios_rwsem
before calling ->rs485_config() and pass termios.

Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Link: https://lore.kernel.org/r/20220624204210.11112-5-ilpo.jarvinen@linux.intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Ilpo Järvinen and committed by
Greg Kroah-Hartman
ae50bb27 79b3e69f

+38 -25
+2 -1
drivers/tty/serial/8250/8250.h
··· 203 203 void serial8250_rpm_get_tx(struct uart_8250_port *p); 204 204 void serial8250_rpm_put_tx(struct uart_8250_port *p); 205 205 206 - int serial8250_em485_config(struct uart_port *port, struct serial_rs485 *rs485); 206 + int serial8250_em485_config(struct uart_port *port, struct ktermios *termios, 207 + struct serial_rs485 *rs485); 207 208 void serial8250_em485_start_tx(struct uart_8250_port *p); 208 209 void serial8250_em485_stop_tx(struct uart_8250_port *p); 209 210 void serial8250_em485_destroy(struct uart_8250_port *p);
+2 -1
drivers/tty/serial/8250/8250_dwlib.c
··· 85 85 } 86 86 EXPORT_SYMBOL_GPL(dw8250_do_set_termios); 87 87 88 - static int dw8250_rs485_config(struct uart_port *p, struct serial_rs485 *rs485) 88 + static int dw8250_rs485_config(struct uart_port *p, struct ktermios *termios, 89 + struct serial_rs485 *rs485) 89 90 { 90 91 u32 tcr; 91 92
+5 -4
drivers/tty/serial/8250/8250_exar.c
··· 112 112 struct exar8250; 113 113 114 114 struct exar8250_platform { 115 - int (*rs485_config)(struct uart_port *, struct serial_rs485 *); 115 + int (*rs485_config)(struct uart_port *port, struct ktermios *termios, 116 + struct serial_rs485 *rs485); 116 117 const struct serial_rs485 *rs485_supported; 117 118 int (*register_gpio)(struct pci_dev *, struct uart_8250_port *); 118 119 void (*unregister_gpio)(struct uart_8250_port *); ··· 410 409 port->port.private_data = NULL; 411 410 } 412 411 413 - static int generic_rs485_config(struct uart_port *port, 412 + static int generic_rs485_config(struct uart_port *port, struct ktermios *termios, 414 413 struct serial_rs485 *rs485) 415 414 { 416 415 bool is_rs485 = !!(rs485->flags & SER_RS485_ENABLED); ··· 442 441 .rs485_supported = &generic_rs485_supported, 443 442 }; 444 443 445 - static int iot2040_rs485_config(struct uart_port *port, 444 + static int iot2040_rs485_config(struct uart_port *port, struct ktermios *termios, 446 445 struct serial_rs485 *rs485) 447 446 { 448 447 bool is_rs485 = !!(rs485->flags & SER_RS485_ENABLED); ··· 472 471 value |= mode; 473 472 writeb(value, p + UART_EXAR_MPIOLVL_7_0); 474 473 475 - return generic_rs485_config(port, rs485); 474 + return generic_rs485_config(port, termios, rs485); 476 475 } 477 476 478 477 static const struct serial_rs485 iot2040_rs485_supported = {
+1 -1
drivers/tty/serial/8250/8250_fintek.c
··· 191 191 return -ENODEV; 192 192 } 193 193 194 - static int fintek_8250_rs485_config(struct uart_port *port, 194 + static int fintek_8250_rs485_config(struct uart_port *port, struct ktermios *termios, 195 195 struct serial_rs485 *rs485) 196 196 { 197 197 uint8_t config = 0;
+1 -1
drivers/tty/serial/8250/8250_lpc18xx.c
··· 32 32 int line; 33 33 }; 34 34 35 - static int lpc18xx_rs485_config(struct uart_port *port, 35 + static int lpc18xx_rs485_config(struct uart_port *port, struct ktermios *termios, 36 36 struct serial_rs485 *rs485) 37 37 { 38 38 struct uart_8250_port *up = up_to_u8250p(port);
+1 -1
drivers/tty/serial/8250/8250_pci.c
··· 1553 1553 #define FINTEK_RTS_INVERT BIT(5) 1554 1554 1555 1555 /* We should do proper H/W transceiver setting before change to RS485 mode */ 1556 - static int pci_fintek_rs485_config(struct uart_port *port, 1556 + static int pci_fintek_rs485_config(struct uart_port *port, struct ktermios *termios, 1557 1557 struct serial_rs485 *rs485) 1558 1558 { 1559 1559 struct pci_dev *pci_dev = to_pci_dev(port->dev);
+2 -1
drivers/tty/serial/8250/8250_port.c
··· 664 664 * if the uart is incapable of driving RTS as a Transmit Enable signal in 665 665 * hardware, relying on software emulation instead. 666 666 */ 667 - int serial8250_em485_config(struct uart_port *port, struct serial_rs485 *rs485) 667 + int serial8250_em485_config(struct uart_port *port, struct ktermios *termios, 668 + struct serial_rs485 *rs485) 668 669 { 669 670 struct uart_8250_port *up = up_to_u8250p(port); 670 671
+1 -1
drivers/tty/serial/amba-pl011.c
··· 2197 2197 return ret; 2198 2198 } 2199 2199 2200 - static int pl011_rs485_config(struct uart_port *port, 2200 + static int pl011_rs485_config(struct uart_port *port, struct ktermios *termios, 2201 2201 struct serial_rs485 *rs485) 2202 2202 { 2203 2203 struct uart_amba_port *uap =
+1 -1
drivers/tty/serial/ar933x_uart.c
··· 580 580 .verify_port = ar933x_uart_verify_port, 581 581 }; 582 582 583 - static int ar933x_config_rs485(struct uart_port *port, 583 + static int ar933x_config_rs485(struct uart_port *port, struct ktermios *termios, 584 584 struct serial_rs485 *rs485conf) 585 585 { 586 586 struct ar933x_uart_port *up =
+1 -1
drivers/tty/serial/atmel_serial.c
··· 283 283 } 284 284 285 285 /* Enable or disable the rs485 support */ 286 - static int atmel_config_rs485(struct uart_port *port, 286 + static int atmel_config_rs485(struct uart_port *port, struct ktermios *termios, 287 287 struct serial_rs485 *rs485conf) 288 288 { 289 289 struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
+2 -2
drivers/tty/serial/fsl_lpuart.c
··· 1355 1355 sport->dma_rx_cookie = -EINVAL; 1356 1356 } 1357 1357 1358 - static int lpuart_config_rs485(struct uart_port *port, 1358 + static int lpuart_config_rs485(struct uart_port *port, struct ktermios *termios, 1359 1359 struct serial_rs485 *rs485) 1360 1360 { 1361 1361 struct lpuart_port *sport = container_of(port, ··· 1385 1385 return 0; 1386 1386 } 1387 1387 1388 - static int lpuart32_config_rs485(struct uart_port *port, 1388 + static int lpuart32_config_rs485(struct uart_port *port, struct ktermios *termios, 1389 1389 struct serial_rs485 *rs485) 1390 1390 { 1391 1391 struct lpuart_port *sport = container_of(port,
+1 -1
drivers/tty/serial/imx.c
··· 1907 1907 #endif 1908 1908 1909 1909 /* called with port.lock taken and irqs off or from .probe without locking */ 1910 - static int imx_uart_rs485_config(struct uart_port *port, 1910 + static int imx_uart_rs485_config(struct uart_port *port, struct ktermios *termios, 1911 1911 struct serial_rs485 *rs485conf) 1912 1912 { 1913 1913 struct imx_port *sport = (struct imx_port *)port;
+1 -1
drivers/tty/serial/max310x.c
··· 1036 1036 MAX310X_MODE2_ECHOSUPR_BIT, mode2); 1037 1037 } 1038 1038 1039 - static int max310x_rs485_config(struct uart_port *port, 1039 + static int max310x_rs485_config(struct uart_port *port, struct ktermios *termios, 1040 1040 struct serial_rs485 *rs485) 1041 1041 { 1042 1042 struct max310x_one *one = to_max310x_port(port);
+2 -1
drivers/tty/serial/mcf.c
··· 431 431 /****************************************************************************/ 432 432 433 433 /* Enable or disable the RS485 support */ 434 - static int mcf_config_rs485(struct uart_port *port, struct serial_rs485 *rs485) 434 + static int mcf_config_rs485(struct uart_port *port, struct ktermios *termios, 435 + struct serial_rs485 *rs485) 435 436 { 436 437 unsigned char mr1, mr2; 437 438
+2 -1
drivers/tty/serial/omap-serial.c
··· 1324 1324 1325 1325 /* Enable or disable the rs485 support */ 1326 1326 static int 1327 - serial_omap_config_rs485(struct uart_port *port, struct serial_rs485 *rs485) 1327 + serial_omap_config_rs485(struct uart_port *port, struct ktermios *termios, 1328 + struct serial_rs485 *rs485) 1328 1329 { 1329 1330 struct uart_omap_port *up = to_uart_omap_port(port); 1330 1331 unsigned int mode;
+1 -1
drivers/tty/serial/sc16is7xx.c
··· 1127 1127 spin_unlock_irqrestore(&port->lock, flags); 1128 1128 } 1129 1129 1130 - static int sc16is7xx_config_rs485(struct uart_port *port, 1130 + static int sc16is7xx_config_rs485(struct uart_port *port, struct ktermios *termios, 1131 1131 struct serial_rs485 *rs485) 1132 1132 { 1133 1133 struct sc16is7xx_port *s = dev_get_drvdata(port->dev);
+10 -4
drivers/tty/serial/serial_core.c
··· 1353 1353 1354 1354 uart_sanitize_serial_rs485(port, rs485); 1355 1355 1356 - ret = port->rs485_config(port, rs485); 1356 + ret = port->rs485_config(port, NULL, rs485); 1357 1357 if (ret) 1358 1358 memset(rs485, 0, sizeof(*rs485)); 1359 1359 ··· 1377 1377 return 0; 1378 1378 } 1379 1379 1380 - static int uart_set_rs485_config(struct uart_port *port, 1380 + static int uart_set_rs485_config(struct tty_struct *tty, struct uart_port *port, 1381 1381 struct serial_rs485 __user *rs485_user) 1382 1382 { 1383 1383 struct serial_rs485 rs485; ··· 1396 1396 uart_sanitize_serial_rs485(port, &rs485); 1397 1397 1398 1398 spin_lock_irqsave(&port->lock, flags); 1399 - ret = port->rs485_config(port, &rs485); 1399 + ret = port->rs485_config(port, &tty->termios, &rs485); 1400 1400 if (!ret) 1401 1401 port->rs485 = rs485; 1402 1402 spin_unlock_irqrestore(&port->lock, flags); ··· 1505 1505 if (ret != -ENOIOCTLCMD) 1506 1506 goto out; 1507 1507 1508 + /* rs485_config requires more locking than others */ 1509 + if (cmd == TIOCGRS485) 1510 + down_write(&tty->termios_rwsem); 1511 + 1508 1512 mutex_lock(&port->mutex); 1509 1513 uport = uart_port_check(state); 1510 1514 ··· 1532 1528 break; 1533 1529 1534 1530 case TIOCSRS485: 1535 - ret = uart_set_rs485_config(uport, uarg); 1531 + ret = uart_set_rs485_config(tty, uport, uarg); 1536 1532 break; 1537 1533 1538 1534 case TIOCSISO7816: ··· 1549 1545 } 1550 1546 out_up: 1551 1547 mutex_unlock(&port->mutex); 1548 + if (cmd == TIOCGRS485) 1549 + up_write(&tty->termios_rwsem); 1552 1550 out: 1553 1551 return ret; 1554 1552 }
+1 -1
drivers/tty/serial/stm32-usart.c
··· 97 97 *cr1 |= rs485_deat_dedt; 98 98 } 99 99 100 - static int stm32_usart_config_rs485(struct uart_port *port, 100 + static int stm32_usart_config_rs485(struct uart_port *port, struct ktermios *termios, 101 101 struct serial_rs485 *rs485conf) 102 102 { 103 103 struct stm32_port *stm32_port = to_stm32_port(port);
+1
include/linux/serial_core.h
··· 133 133 unsigned int old); 134 134 void (*handle_break)(struct uart_port *); 135 135 int (*rs485_config)(struct uart_port *, 136 + struct ktermios *termios, 136 137 struct serial_rs485 *rs485); 137 138 int (*iso7816_config)(struct uart_port *, 138 139 struct serial_iso7816 *iso7816);