USB: serial: quatech: fix baud rate overflow
Subsystems (3)
Johan Hovold
maintainercover USB: serial: quatech: fix baud rate overflow
The two Quatech drivers are using the wrong the type for the line speed, which prevents speeds above 65 k bps to be set.
Johan
Johan Hovold (2):
USB: serial: ssu100: fix baud rate overflow
USB: serial: quatech2: fix baud rate overflow
drivers/usb/serial/quatech2.c | 19 ++++++++++++++++--- drivers/usb/serial/ssu100.c | 18 ++++++++++++++++-- 2 files changed, 32 insertions(+), 5 deletions(-)
Signature · 1 line
2.55.0
Johan Hovold
maintainerPATCH 1/2 USB: serial: ssu100: fix baud rate overflow
The requested baud rate is incorrectly truncated to 16 bits so that line speeds above 65535 bps cannot be set.
Use 32 bits for the rate and remainder while rejecting rates outside of [50,460800] to avoid having the divisor or remainder overflow.
This issue was flagged by an LLM.
--- drivers/usb/serial/ssu100.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)
drivers/usb/serial/ssu100.c +16 -2
@@ -32,6 +32,7 @@#define SERIAL_EVEN_PARITY (UART_LCR_PARITY | UART_LCR_EPAR) +#define MIN_BAUD_RATE 50#define MAX_BAUD_RATE 460800#define ATC_DISABLED 0x00
@@ -217,9 +218,10 @@ static void ssu100_set_termios(struct tty_struct *tty, {struct usb_device *dev = port->serial->dev;struct ktermios *termios = &tty->termios; -u16 baud, divisor, remainder; +speed_t baud, remainder;unsigned int cflag = termios->c_cflag;u16 urb_value =0 ;/* will hold the new flags */ +u16 divisor;int result;if (cflag &PARENB ) {
@@ -235,6 +237,18 @@ static void ssu100_set_termios(struct tty_struct *tty,if (!baud) baud =9600 ; +if (baud <MIN_BAUD_RATE || baud >MAX_BAUD_RATE ) { +if (old_termios) + baud =tty_termios_baud_rate (old_termios); +else + baud =clamp (baud,MIN_BAUD_RATE ,MAX_BAUD_RATE ); + +tty_encode_baud_rate (tty, baud, baud); + +if (!baud) + baud =9600 ; + } +dev_dbg (&port->dev,"%s - got baud = %d\n" , __func__, baud);
@@ -310,7 +324,7 @@ static int ssu100_open(struct tty_struct *tty, struct usb_serial_port *port)dev_dbg (&port->dev,"%s - set uart failed\n" , __func__);if (tty) -ssu100_set_termios (tty, port, &tty->termios); +ssu100_set_termios (tty, port,NULL );return usb_serial_generic_open (tty, port); }
Signature · 1 line
2.55.0
Johan Hovold
maintainerPATCH 2/2 USB: serial: quatech2: fix baud rate overflow
In reply to Johan HovoldThe requested baud rate is incorrectly truncated to 16 bits so that line speeds above 65535 bps cannot be set.
Use 32 bits for the rate while rejecting rates outside of [50,921600] to avoid having the 16-bit divisor overflow.
--- drivers/usb/serial/quatech2.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-)
drivers/usb/serial/quatech2.c +16 -3
@@ -52,6 +52,7 @@#define QT2_XMIT_FLUSH 0x05/* no following info */ #define QT2_CONTROL_ESCAPE 0xff/* pass through previous 2 control bytes */ +#define MIN_BAUD_RATE 50#define MAX_BAUD_RATE 921600#define DEFAULT_BAUD_RATE 9600
@@ -156,7 +157,7 @@ static inline int calc_baud_divisor(int baudrate)static inline int qt2_set_port_config (struct usb_device *dev,unsigned char port_number, -u16 baudrate,u16 lcr) +speed_t baudrate,u16 lcr) {int divisor =calc_baud_divisor (baudrate);u16 index = ((u16) (lcr <<8 ) | (u16) (port_number));
@@ -257,9 +258,9 @@ static void qt2_set_termios(struct tty_struct *tty,struct usb_device *dev = port->serial->dev;struct qt2_port_private *port_priv;struct ktermios *termios = &tty->termios; -u16 baud;unsigned int cflag = termios->c_cflag;u16 new_lcr =0 ; +speed_t baud;int status; port_priv =usb_get_serial_port_data (port);
@@ -277,6 +278,18 @@ static void qt2_set_termios(struct tty_struct *tty,if (!baud) baud =9600 ; +if (baud <MIN_BAUD_RATE || baud >MAX_BAUD_RATE ) { +if (old_termios) + baud =tty_termios_baud_rate (old_termios); +else + baud =clamp (baud,MIN_BAUD_RATE ,MAX_BAUD_RATE ); + +tty_encode_baud_rate (tty, baud, baud); + +if (!baud) + baud =9600 ; + } + status =qt2_set_port_config (dev, port_priv->device_port, baud, new_lcr);if (status <0 )
@@ -373,7 +386,7 @@ static int qt2_open(struct tty_struct *tty, struct usb_serial_port *port) port_priv->device_port = (u8 ) device_port;if (tty) -qt2_set_termios (tty, port, &tty->termios); +qt2_set_termios (tty, port,NULL );return 0 ;
Signature · 1 line
2.55.0