diff mbox series

[1/6] USB: serial: cp210x: return early on unchanged termios

Message ID 20201116161826.29417-2-johan@kernel.org (mailing list archive)
State Accepted
Commit 95168d624f3a8dee466525767200391a0fb006b9
Headers show
Series USB: serial: cp210x: clean up termios handling | expand

Commit Message

Johan Hovold Nov. 16, 2020, 4:18 p.m. UTC
Return early from set_termios() in case no relevant terminal settings
have changed.

This avoids testing each parameter in turn and specifically allows the
line-control handling to be cleaned up further.

Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/usb/serial/cp210x.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
diff mbox series

Patch

diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c
index d0c05aa8a0d6..f1fd109d97d5 100644
--- a/drivers/usb/serial/cp210x.c
+++ b/drivers/usb/serial/cp210x.c
@@ -1352,6 +1352,15 @@  static void cp210x_disable_event_mode(struct usb_serial_port *port)
 	port_priv->event_mode = false;
 }
 
+static bool cp210x_termios_change(const struct ktermios *a, const struct ktermios *b)
+{
+	bool iflag_change;
+
+	iflag_change = ((a->c_iflag ^ b->c_iflag) & INPCK);
+
+	return tty_termios_hw_change(a, b) || iflag_change;
+}
+
 static void cp210x_set_termios(struct tty_struct *tty,
 		struct usb_serial_port *port, struct ktermios *old_termios)
 {
@@ -1359,6 +1368,9 @@  static void cp210x_set_termios(struct tty_struct *tty,
 	unsigned int cflag, old_cflag;
 	u16 bits;
 
+	if (!cp210x_termios_change(&tty->termios, old_termios))
+		return;
+
 	cflag = tty->termios.c_cflag;
 	old_cflag = old_termios->c_cflag;