[PATCH 25/36] usb: serial: ti_usb_3410_5052: Check old_termios parameter in set_termios

From: Mathieu OTHACEHE
Date: Thu May 12 2016 - 04:51:14 EST


The old_termios parameter is never used in set_termios callback.

Add a check to old_termios to see if we can return right away because
there is nothing to change.
Add a check to old_termios CBAUD to see if we can set DTR/RTS because
last speed was B0.

Also pass NULL for old_termios in open callback because it is the
initial call to set_termios.

Signed-off-by: Mathieu OTHACEHE <m.othacehe@xxxxxxxxx>
---
drivers/usb/serial/ti_usb_3410_5052.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/serial/ti_usb_3410_5052.c b/drivers/usb/serial/ti_usb_3410_5052.c
index 4769c80..b50f52f 100644
--- a/drivers/usb/serial/ti_usb_3410_5052.c
+++ b/drivers/usb/serial/ti_usb_3410_5052.c
@@ -710,7 +710,7 @@ static int ti_open(struct tty_struct *tty, struct usb_serial_port *port)
}

if (tty)
- ti_set_termios(tty, port, &tty->termios);
+ ti_set_termios(tty, port, NULL);

status = ti_send_ctrl_urb(serial, TI_OPEN_PORT, open_settings,
TI_UART1_PORT + port_number);
@@ -750,7 +750,7 @@ static int ti_open(struct tty_struct *tty, struct usb_serial_port *port)
usb_clear_halt(serial->dev, port->read_urb->pipe);

if (tty)
- ti_set_termios(tty, port, &tty->termios);
+ ti_set_termios(tty, port, NULL);

status = ti_send_ctrl_urb(serial, TI_OPEN_PORT, open_settings,
TI_UART1_PORT + port_number);
@@ -913,6 +913,13 @@ static void ti_set_termios(struct tty_struct *tty,
cflag = tty->termios.c_cflag;
iflag = tty->termios.c_iflag;

+ if (old_termios &&
+ !tty_termios_hw_change(&tty->termios, old_termios) &&
+ tty->termios.c_iflag == old_termios->c_iflag) {
+ dev_dbg(&port->dev, "%s - nothing to change\n", __func__);
+ return;
+ }
+
dev_dbg(&port->dev,
"%s - cflag 0x%08x, iflag 0x%08x\n", __func__, cflag, iflag);

@@ -1020,6 +1027,9 @@ static void ti_set_termios(struct tty_struct *tty,
/* if baud rate is B0, clear RTS and DTR */
if (C_BAUD(tty) == B0)
mcr &= ~(TI_MCR_DTR | TI_MCR_RTS);
+ else if (old_termios && (old_termios->c_cflag & CBAUD) == B0)
+ mcr |= TI_MCR_DTR | TI_MCR_RTS;
+
status = ti_set_mcr(tport, mcr);
if (status)
dev_err(&port->dev,
--
2.8.2