serial: fix TIOCSRS485 locking
PATCH 1/1 serial: fix TIOCSRS485 locking
The RS485 multipoint addressing support for some reason added a new ADDRB termios cflag which is (only!) updated from one of the RS485 ioctls.
Make sure to take the termios rw semaphore for the right ioctl (i.e. set, not get).
---
I did not have time to review the multipoint addressing patches at the time and only skimmed the archives now, but I can't seem to find any motivation for why a precious termios bit was seemingly wasted on ADDRB when it is only updated from the RS485 ioctls.
I hope it wasn't done just to simplify the implementation of tty_get_frame_size()? Or was it a left-over from the RFC which apparently actually used termios to enable this feature?
Should we consider dropping the Linux-specific ADDRB bit again?
Johan
drivers/tty/serial/serial_core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/tty/serial/serial_core.c +2 -2
@@ -1552,7 +1552,7 @@ uart_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg) goto out;/* rs485_config requires more locking than others */ -if (cmd ==TIOCGRS485 ) +if (cmd ==TIOCSRS485 )down_write (&tty->termios_rwsem);mutex_lock (&port->mutex);
@@ -1595,7 +1595,7 @@ uart_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg) } out_up:mutex_unlock (&port->mutex); -if (cmd ==TIOCGRS485 ) +if (cmd ==TIOCSRS485 )up_write (&tty->termios_rwsem); out:return ret;
Signature · 1 line
2.39.2
Quoted 13 lines · Johan Hovold
The RS485 multipoint addressing support for some reason added a new ADDRB termios cflag which is (only!) updated from one of the RS485 ioctls.
Make sure to take the termios rw semaphore for the right ioctl (i.e. set, not get).
Fixes ae50bb275283 ("serial: take termios_rwsem for ->rs485_config() & pass termios as param")Cc [email protected] # 6.0Cc Ilpo Järvinen <[email protected]>Signed-off-by Johan Hovold <[email protected]>---
Quoted 8 lines
I did not have time to review the multipoint addressing patches at the time and only skimmed the archives now, but I can't seem to find any motivation for why a precious termios bit was seemingly wasted on ADDRB when it is only updated from the RS485 ioctls.
I hope it wasn't done just to simplify the implementation of
tty_get_frame_size()? Or was it a left-over from the RFC which apparently actually used termios to enable this feature?
No. I made it intentionally. It felt natural place for storing it because ADDRB does impact the wire format and cflag is where other wire-format impacting bits are also stored.
Quoted 23 lines
Should we consider dropping the Linux-specific ADDRB bit again?
Johan
drivers/tty/serial/serial_core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/tty/serial/serial_core.c +1
-1@@ -1552,7 +1552,7 @@ uart_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg) goto out;/* rs485_config requires more locking than others */ -if (cmd ==TIOCGRS485 ) +if (cmd ==TIOCSRS485 )down_write (&tty->termios_rwsem);mutex_lock (&port->mutex);
drivers/tty/serial/serial_core.c uart_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg) · line 1601
Quoted 8 lines
drivers/tty/serial/serial_core.c +1
-1@@ -1595,7 +1595,7 @@ uart_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg) } out_up:mutex_unlock (&port->mutex); -if (cmd ==TIOCGRS485 ) +if (cmd ==TIOCSRS485 )up_write (&tty->termios_rwsem); out:return ret;
Indeed, the caps are so blinding.
Signature · 1 line
i.