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.

Fixes: 52af954599 ("USB: add USB serial ssu100 driver")
Cc: [email protected]	# 2.6.36
Cc: Bill Pemberton <[email protected]>
Assisted-by: LLM
Signed-off-by: Johan Hovold <[email protected]>
This commit is contained in:
Johan Hovold committed 2026-09-16 15:24:51 +02:00
1 parent d84e27d877
commit afc235a217
1 file changed
+16 -2
+16 -2
View File
@@ -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);
}