Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755600AbbBPH6v (ORCPT ); Mon, 16 Feb 2015 02:58:51 -0500 Received: from mail-pa0-f42.google.com ([209.85.220.42]:38122 "EHLO mail-pa0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755526AbbBPH6t (ORCPT ); Mon, 16 Feb 2015 02:58:49 -0500 From: Peter Hung X-Google-Original-From: Peter Hung To: johan@kernel.org Cc: gregkh@linuxfoundation.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, tom_tsai@fintek.com.tw, peter_hong@fintek.com.tw, Peter Hung Subject: [PATCH V6 08/10] USB: f81232: fix read MSR strange value Date: Mon, 16 Feb 2015 15:58:00 +0800 Message-Id: <1424073482-18164-9-git-send-email-hpeter+linux_kernel@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1424073482-18164-1-git-send-email-hpeter+linux_kernel@gmail.com> References: <1424073482-18164-1-git-send-email-hpeter+linux_kernel@gmail.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2559 Lines: 77 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 --- 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-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/