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>
This commit is contained in:
parent
79b3e69fa4
commit
ae50bb2752
@ -203,7 +203,8 @@ void serial8250_rpm_put(struct uart_8250_port *p);
|
|||||||
void serial8250_rpm_get_tx(struct uart_8250_port *p);
|
void serial8250_rpm_get_tx(struct uart_8250_port *p);
|
||||||
void serial8250_rpm_put_tx(struct uart_8250_port *p);
|
void serial8250_rpm_put_tx(struct uart_8250_port *p);
|
||||||
|
|
||||||
int serial8250_em485_config(struct uart_port *port, struct serial_rs485 *rs485);
|
int serial8250_em485_config(struct uart_port *port, struct ktermios *termios,
|
||||||
|
struct serial_rs485 *rs485);
|
||||||
void serial8250_em485_start_tx(struct uart_8250_port *p);
|
void serial8250_em485_start_tx(struct uart_8250_port *p);
|
||||||
void serial8250_em485_stop_tx(struct uart_8250_port *p);
|
void serial8250_em485_stop_tx(struct uart_8250_port *p);
|
||||||
void serial8250_em485_destroy(struct uart_8250_port *p);
|
void serial8250_em485_destroy(struct uart_8250_port *p);
|
||||||
|
@ -85,7 +85,8 @@ void dw8250_do_set_termios(struct uart_port *p, struct ktermios *termios, struct
|
|||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(dw8250_do_set_termios);
|
EXPORT_SYMBOL_GPL(dw8250_do_set_termios);
|
||||||
|
|
||||||
static int dw8250_rs485_config(struct uart_port *p, struct serial_rs485 *rs485)
|
static int dw8250_rs485_config(struct uart_port *p, struct ktermios *termios,
|
||||||
|
struct serial_rs485 *rs485)
|
||||||
{
|
{
|
||||||
u32 tcr;
|
u32 tcr;
|
||||||
|
|
||||||
|
@ -112,7 +112,8 @@
|
|||||||
struct exar8250;
|
struct exar8250;
|
||||||
|
|
||||||
struct exar8250_platform {
|
struct exar8250_platform {
|
||||||
int (*rs485_config)(struct uart_port *, struct serial_rs485 *);
|
int (*rs485_config)(struct uart_port *port, struct ktermios *termios,
|
||||||
|
struct serial_rs485 *rs485);
|
||||||
const struct serial_rs485 *rs485_supported;
|
const struct serial_rs485 *rs485_supported;
|
||||||
int (*register_gpio)(struct pci_dev *, struct uart_8250_port *);
|
int (*register_gpio)(struct pci_dev *, struct uart_8250_port *);
|
||||||
void (*unregister_gpio)(struct uart_8250_port *);
|
void (*unregister_gpio)(struct uart_8250_port *);
|
||||||
@ -409,7 +410,7 @@ static void xr17v35x_unregister_gpio(struct uart_8250_port *port)
|
|||||||
port->port.private_data = NULL;
|
port->port.private_data = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int generic_rs485_config(struct uart_port *port,
|
static int generic_rs485_config(struct uart_port *port, struct ktermios *termios,
|
||||||
struct serial_rs485 *rs485)
|
struct serial_rs485 *rs485)
|
||||||
{
|
{
|
||||||
bool is_rs485 = !!(rs485->flags & SER_RS485_ENABLED);
|
bool is_rs485 = !!(rs485->flags & SER_RS485_ENABLED);
|
||||||
@ -441,7 +442,7 @@ static const struct exar8250_platform exar8250_default_platform = {
|
|||||||
.rs485_supported = &generic_rs485_supported,
|
.rs485_supported = &generic_rs485_supported,
|
||||||
};
|
};
|
||||||
|
|
||||||
static int iot2040_rs485_config(struct uart_port *port,
|
static int iot2040_rs485_config(struct uart_port *port, struct ktermios *termios,
|
||||||
struct serial_rs485 *rs485)
|
struct serial_rs485 *rs485)
|
||||||
{
|
{
|
||||||
bool is_rs485 = !!(rs485->flags & SER_RS485_ENABLED);
|
bool is_rs485 = !!(rs485->flags & SER_RS485_ENABLED);
|
||||||
@ -471,7 +472,7 @@ static int iot2040_rs485_config(struct uart_port *port,
|
|||||||
value |= mode;
|
value |= mode;
|
||||||
writeb(value, p + UART_EXAR_MPIOLVL_7_0);
|
writeb(value, p + UART_EXAR_MPIOLVL_7_0);
|
||||||
|
|
||||||
return generic_rs485_config(port, rs485);
|
return generic_rs485_config(port, termios, rs485);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct serial_rs485 iot2040_rs485_supported = {
|
static const struct serial_rs485 iot2040_rs485_supported = {
|
||||||
|
@ -191,7 +191,7 @@ static int fintek_8250_get_ldn_range(struct fintek_8250 *pdata, int *min,
|
|||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int fintek_8250_rs485_config(struct uart_port *port,
|
static int fintek_8250_rs485_config(struct uart_port *port, struct ktermios *termios,
|
||||||
struct serial_rs485 *rs485)
|
struct serial_rs485 *rs485)
|
||||||
{
|
{
|
||||||
uint8_t config = 0;
|
uint8_t config = 0;
|
||||||
|
@ -32,7 +32,7 @@ struct lpc18xx_uart_data {
|
|||||||
int line;
|
int line;
|
||||||
};
|
};
|
||||||
|
|
||||||
static int lpc18xx_rs485_config(struct uart_port *port,
|
static int lpc18xx_rs485_config(struct uart_port *port, struct ktermios *termios,
|
||||||
struct serial_rs485 *rs485)
|
struct serial_rs485 *rs485)
|
||||||
{
|
{
|
||||||
struct uart_8250_port *up = up_to_u8250p(port);
|
struct uart_8250_port *up = up_to_u8250p(port);
|
||||||
|
@ -1553,7 +1553,7 @@ pci_brcm_trumanage_setup(struct serial_private *priv,
|
|||||||
#define FINTEK_RTS_INVERT BIT(5)
|
#define FINTEK_RTS_INVERT BIT(5)
|
||||||
|
|
||||||
/* We should do proper H/W transceiver setting before change to RS485 mode */
|
/* We should do proper H/W transceiver setting before change to RS485 mode */
|
||||||
static int pci_fintek_rs485_config(struct uart_port *port,
|
static int pci_fintek_rs485_config(struct uart_port *port, struct ktermios *termios,
|
||||||
struct serial_rs485 *rs485)
|
struct serial_rs485 *rs485)
|
||||||
{
|
{
|
||||||
struct pci_dev *pci_dev = to_pci_dev(port->dev);
|
struct pci_dev *pci_dev = to_pci_dev(port->dev);
|
||||||
|
@ -664,7 +664,8 @@ EXPORT_SYMBOL_GPL(serial8250_em485_supported);
|
|||||||
* if the uart is incapable of driving RTS as a Transmit Enable signal in
|
* if the uart is incapable of driving RTS as a Transmit Enable signal in
|
||||||
* hardware, relying on software emulation instead.
|
* hardware, relying on software emulation instead.
|
||||||
*/
|
*/
|
||||||
int serial8250_em485_config(struct uart_port *port, struct serial_rs485 *rs485)
|
int serial8250_em485_config(struct uart_port *port, struct ktermios *termios,
|
||||||
|
struct serial_rs485 *rs485)
|
||||||
{
|
{
|
||||||
struct uart_8250_port *up = up_to_u8250p(port);
|
struct uart_8250_port *up = up_to_u8250p(port);
|
||||||
|
|
||||||
|
@ -2197,7 +2197,7 @@ static int pl011_verify_port(struct uart_port *port, struct serial_struct *ser)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int pl011_rs485_config(struct uart_port *port,
|
static int pl011_rs485_config(struct uart_port *port, struct ktermios *termios,
|
||||||
struct serial_rs485 *rs485)
|
struct serial_rs485 *rs485)
|
||||||
{
|
{
|
||||||
struct uart_amba_port *uap =
|
struct uart_amba_port *uap =
|
||||||
|
@ -580,7 +580,7 @@ static const struct uart_ops ar933x_uart_ops = {
|
|||||||
.verify_port = ar933x_uart_verify_port,
|
.verify_port = ar933x_uart_verify_port,
|
||||||
};
|
};
|
||||||
|
|
||||||
static int ar933x_config_rs485(struct uart_port *port,
|
static int ar933x_config_rs485(struct uart_port *port, struct ktermios *termios,
|
||||||
struct serial_rs485 *rs485conf)
|
struct serial_rs485 *rs485conf)
|
||||||
{
|
{
|
||||||
struct ar933x_uart_port *up =
|
struct ar933x_uart_port *up =
|
||||||
|
@ -283,7 +283,7 @@ static void atmel_tasklet_schedule(struct atmel_uart_port *atmel_port,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Enable or disable the rs485 support */
|
/* Enable or disable the rs485 support */
|
||||||
static int atmel_config_rs485(struct uart_port *port,
|
static int atmel_config_rs485(struct uart_port *port, struct ktermios *termios,
|
||||||
struct serial_rs485 *rs485conf)
|
struct serial_rs485 *rs485conf)
|
||||||
{
|
{
|
||||||
struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
|
struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
|
||||||
|
@ -1355,7 +1355,7 @@ static void lpuart_dma_rx_free(struct uart_port *port)
|
|||||||
sport->dma_rx_cookie = -EINVAL;
|
sport->dma_rx_cookie = -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int lpuart_config_rs485(struct uart_port *port,
|
static int lpuart_config_rs485(struct uart_port *port, struct ktermios *termios,
|
||||||
struct serial_rs485 *rs485)
|
struct serial_rs485 *rs485)
|
||||||
{
|
{
|
||||||
struct lpuart_port *sport = container_of(port,
|
struct lpuart_port *sport = container_of(port,
|
||||||
@ -1385,7 +1385,7 @@ static int lpuart_config_rs485(struct uart_port *port,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int lpuart32_config_rs485(struct uart_port *port,
|
static int lpuart32_config_rs485(struct uart_port *port, struct ktermios *termios,
|
||||||
struct serial_rs485 *rs485)
|
struct serial_rs485 *rs485)
|
||||||
{
|
{
|
||||||
struct lpuart_port *sport = container_of(port,
|
struct lpuart_port *sport = container_of(port,
|
||||||
|
@ -1907,7 +1907,7 @@ static void imx_uart_poll_put_char(struct uart_port *port, unsigned char c)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* called with port.lock taken and irqs off or from .probe without locking */
|
/* called with port.lock taken and irqs off or from .probe without locking */
|
||||||
static int imx_uart_rs485_config(struct uart_port *port,
|
static int imx_uart_rs485_config(struct uart_port *port, struct ktermios *termios,
|
||||||
struct serial_rs485 *rs485conf)
|
struct serial_rs485 *rs485conf)
|
||||||
{
|
{
|
||||||
struct imx_port *sport = (struct imx_port *)port;
|
struct imx_port *sport = (struct imx_port *)port;
|
||||||
|
@ -1036,7 +1036,7 @@ static void max310x_rs_proc(struct work_struct *ws)
|
|||||||
MAX310X_MODE2_ECHOSUPR_BIT, mode2);
|
MAX310X_MODE2_ECHOSUPR_BIT, mode2);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int max310x_rs485_config(struct uart_port *port,
|
static int max310x_rs485_config(struct uart_port *port, struct ktermios *termios,
|
||||||
struct serial_rs485 *rs485)
|
struct serial_rs485 *rs485)
|
||||||
{
|
{
|
||||||
struct max310x_one *one = to_max310x_port(port);
|
struct max310x_one *one = to_max310x_port(port);
|
||||||
|
@ -431,7 +431,8 @@ static int mcf_verify_port(struct uart_port *port, struct serial_struct *ser)
|
|||||||
/****************************************************************************/
|
/****************************************************************************/
|
||||||
|
|
||||||
/* Enable or disable the RS485 support */
|
/* Enable or disable the RS485 support */
|
||||||
static int mcf_config_rs485(struct uart_port *port, struct serial_rs485 *rs485)
|
static int mcf_config_rs485(struct uart_port *port, struct ktermios *termios,
|
||||||
|
struct serial_rs485 *rs485)
|
||||||
{
|
{
|
||||||
unsigned char mr1, mr2;
|
unsigned char mr1, mr2;
|
||||||
|
|
||||||
|
@ -1324,7 +1324,8 @@ static inline void serial_omap_add_console_port(struct uart_omap_port *up)
|
|||||||
|
|
||||||
/* Enable or disable the rs485 support */
|
/* Enable or disable the rs485 support */
|
||||||
static int
|
static int
|
||||||
serial_omap_config_rs485(struct uart_port *port, struct serial_rs485 *rs485)
|
serial_omap_config_rs485(struct uart_port *port, struct ktermios *termios,
|
||||||
|
struct serial_rs485 *rs485)
|
||||||
{
|
{
|
||||||
struct uart_omap_port *up = to_uart_omap_port(port);
|
struct uart_omap_port *up = to_uart_omap_port(port);
|
||||||
unsigned int mode;
|
unsigned int mode;
|
||||||
|
@ -1127,7 +1127,7 @@ static void sc16is7xx_set_termios(struct uart_port *port,
|
|||||||
spin_unlock_irqrestore(&port->lock, flags);
|
spin_unlock_irqrestore(&port->lock, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sc16is7xx_config_rs485(struct uart_port *port,
|
static int sc16is7xx_config_rs485(struct uart_port *port, struct ktermios *termios,
|
||||||
struct serial_rs485 *rs485)
|
struct serial_rs485 *rs485)
|
||||||
{
|
{
|
||||||
struct sc16is7xx_port *s = dev_get_drvdata(port->dev);
|
struct sc16is7xx_port *s = dev_get_drvdata(port->dev);
|
||||||
|
@ -1353,7 +1353,7 @@ int uart_rs485_config(struct uart_port *port)
|
|||||||
|
|
||||||
uart_sanitize_serial_rs485(port, rs485);
|
uart_sanitize_serial_rs485(port, rs485);
|
||||||
|
|
||||||
ret = port->rs485_config(port, rs485);
|
ret = port->rs485_config(port, NULL, rs485);
|
||||||
if (ret)
|
if (ret)
|
||||||
memset(rs485, 0, sizeof(*rs485));
|
memset(rs485, 0, sizeof(*rs485));
|
||||||
|
|
||||||
@ -1377,7 +1377,7 @@ static int uart_get_rs485_config(struct uart_port *port,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int uart_set_rs485_config(struct uart_port *port,
|
static int uart_set_rs485_config(struct tty_struct *tty, struct uart_port *port,
|
||||||
struct serial_rs485 __user *rs485_user)
|
struct serial_rs485 __user *rs485_user)
|
||||||
{
|
{
|
||||||
struct serial_rs485 rs485;
|
struct serial_rs485 rs485;
|
||||||
@ -1396,7 +1396,7 @@ static int uart_set_rs485_config(struct uart_port *port,
|
|||||||
uart_sanitize_serial_rs485(port, &rs485);
|
uart_sanitize_serial_rs485(port, &rs485);
|
||||||
|
|
||||||
spin_lock_irqsave(&port->lock, flags);
|
spin_lock_irqsave(&port->lock, flags);
|
||||||
ret = port->rs485_config(port, &rs485);
|
ret = port->rs485_config(port, &tty->termios, &rs485);
|
||||||
if (!ret)
|
if (!ret)
|
||||||
port->rs485 = rs485;
|
port->rs485 = rs485;
|
||||||
spin_unlock_irqrestore(&port->lock, flags);
|
spin_unlock_irqrestore(&port->lock, flags);
|
||||||
@ -1505,6 +1505,10 @@ uart_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg)
|
|||||||
if (ret != -ENOIOCTLCMD)
|
if (ret != -ENOIOCTLCMD)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
/* rs485_config requires more locking than others */
|
||||||
|
if (cmd == TIOCGRS485)
|
||||||
|
down_write(&tty->termios_rwsem);
|
||||||
|
|
||||||
mutex_lock(&port->mutex);
|
mutex_lock(&port->mutex);
|
||||||
uport = uart_port_check(state);
|
uport = uart_port_check(state);
|
||||||
|
|
||||||
@ -1528,7 +1532,7 @@ uart_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case TIOCSRS485:
|
case TIOCSRS485:
|
||||||
ret = uart_set_rs485_config(uport, uarg);
|
ret = uart_set_rs485_config(tty, uport, uarg);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TIOCSISO7816:
|
case TIOCSISO7816:
|
||||||
@ -1545,6 +1549,8 @@ uart_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg)
|
|||||||
}
|
}
|
||||||
out_up:
|
out_up:
|
||||||
mutex_unlock(&port->mutex);
|
mutex_unlock(&port->mutex);
|
||||||
|
if (cmd == TIOCGRS485)
|
||||||
|
up_write(&tty->termios_rwsem);
|
||||||
out:
|
out:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -97,7 +97,7 @@ static void stm32_usart_config_reg_rs485(u32 *cr1, u32 *cr3, u32 delay_ADE,
|
|||||||
*cr1 |= rs485_deat_dedt;
|
*cr1 |= rs485_deat_dedt;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int stm32_usart_config_rs485(struct uart_port *port,
|
static int stm32_usart_config_rs485(struct uart_port *port, struct ktermios *termios,
|
||||||
struct serial_rs485 *rs485conf)
|
struct serial_rs485 *rs485conf)
|
||||||
{
|
{
|
||||||
struct stm32_port *stm32_port = to_stm32_port(port);
|
struct stm32_port *stm32_port = to_stm32_port(port);
|
||||||
|
@ -133,6 +133,7 @@ struct uart_port {
|
|||||||
unsigned int old);
|
unsigned int old);
|
||||||
void (*handle_break)(struct uart_port *);
|
void (*handle_break)(struct uart_port *);
|
||||||
int (*rs485_config)(struct uart_port *,
|
int (*rs485_config)(struct uart_port *,
|
||||||
|
struct ktermios *termios,
|
||||||
struct serial_rs485 *rs485);
|
struct serial_rs485 *rs485);
|
||||||
int (*iso7816_config)(struct uart_port *,
|
int (*iso7816_config)(struct uart_port *,
|
||||||
struct serial_iso7816 *iso7816);
|
struct serial_iso7816 *iso7816);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user