When we use RS232 loopback, assume doing RTS change will cause CTS change, DTR change will cause DCD/DSR change too. Sometimes we got 7~4 bits of MSR changed but the 3~0 bits of MSR(delta) maybe not changed when set & get MCR fasterly. So we add more check not only UART_MSR_ANY_DELTA but also with comparing DCD/RI/DSR/CTS change with old value. Due to the state bit is always correct, we direct save msr when read. The following step to reproduce this problem with while loop step 1~4: 1. ioctl(fd, TIOCMSET, &data) to set RTS or DTR 2. ioctl(fd, TIOCMGET, &data) to read CTS or DCD/DSR state 3. ioctl(fd, TIOCMSET, &data) to unset RTS or DTR 4. ioctl(fd, TIOCMGET, &data) to read CTS or DCD/DSR state Signed-off-by: Peter Hung <hpeter+linux_kernel@xxxxxxxxx> --- drivers/usb/serial/f81232.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/drivers/usb/serial/f81232.c b/drivers/usb/serial/f81232.c index c87a3eb..94c05d7 100644 --- a/drivers/usb/serial/f81232.c +++ b/drivers/usb/serial/f81232.c @@ -110,7 +110,8 @@ static void f81232_read_msr(struct usb_serial_port *port) { int status; unsigned long flags; - u8 current_msr; + u8 current_msr, prev_msr; + u8 msr_mask = ~UART_MSR_ANY_DELTA; struct tty_struct *tty; struct f81232_private *priv = usb_get_serial_port_data(port); @@ -123,7 +124,21 @@ static void f81232_read_msr(struct usb_serial_port *port) return; } - if (!(current_msr & UART_MSR_ANY_DELTA)) + /* + * The 7~4 bits of MSR will change but the 3~0 bits of MSR(delta) + * maybe not change when set & get MCR fasterly. + * + * So we add more check with comparing DCD/RI/DSR/CTS + * change. and direct save msr when read. + */ + + spin_lock_irqsave(&priv->lock, flags); + prev_msr = priv->modem_status; + priv->modem_status = current_msr; + spin_unlock_irqrestore(&priv->lock, flags); + + if (!(current_msr & UART_MSR_ANY_DELTA) && + !((prev_msr ^ current_msr) & msr_mask)) return; tty = tty_port_tty_get(&port->port); @@ -136,10 +151,6 @@ static void f81232_read_msr(struct usb_serial_port *port) tty_kref_put(tty); } - spin_lock_irqsave(&priv->lock, flags); - priv->modem_status = current_msr; - spin_unlock_irqrestore(&priv->lock, flags); - wake_up_interruptible(&port->port.delta_msr_wait); } -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html