Skip to content

Commit 8704211

Browse files
cleitnergregkh
authored andcommitted
USB: ftdi_sio: fixed handling of unsupported CSIZE setting
FTDI UARTs support only 7 or 8 data bits. Until now the ftdi_sio driver would only report this limitation for CS6 to dmesg and fail to reflect this fact to tcgetattr. This patch reverts the unsupported CSIZE setting and reports the fact with less severance to dmesg for both CS5 and CS6. To test the patch it's sufficient to call stty -F /dev/ttyUSB0 cs5 which will succeed without the patch and report an error with the patch applied. As an additional fix this patch ensures that the control request will always include a data bit size. Signed-off-by: Colin Leitner <colin.leitner@gmail.com> Signed-off-by: Johan Hovold <jhovold@gmail.com> Cc: stable <stable@vger.kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 78692cc commit 8704211

1 file changed

Lines changed: 24 additions & 13 deletions

File tree

‎drivers/usb/serial/ftdi_sio.c‎

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2123,6 +2123,20 @@ static void ftdi_set_termios(struct tty_struct *tty,
21232123
termios->c_cflag |= CRTSCTS;
21242124
}
21252125

2126+
/*
2127+
* All FTDI UART chips are limited to CS7/8. We won't pretend to
2128+
* support CS5/6 and revert the CSIZE setting instead.
2129+
*/
2130+
if ((C_CSIZE(tty) != CS8) && (C_CSIZE(tty) != CS7)) {
2131+
dev_warn(ddev, "requested CSIZE setting not supported\n");
2132+
2133+
termios->c_cflag &= ~CSIZE;
2134+
if (old_termios)
2135+
termios->c_cflag |= old_termios->c_cflag & CSIZE;
2136+
else
2137+
termios->c_cflag |= CS8;
2138+
}
2139+
21262140
cflag = termios->c_cflag;
21272141

21282142
if (!old_termios)
@@ -2159,19 +2173,16 @@ static void ftdi_set_termios(struct tty_struct *tty,
21592173
} else {
21602174
urb_value |= FTDI_SIO_SET_DATA_PARITY_NONE;
21612175
}
2162-
if (cflag & CSIZE) {
2163-
switch (cflag & CSIZE) {
2164-
case CS7:
2165-
urb_value |= 7;
2166-
dev_dbg(ddev, "Setting CS7\n");
2167-
break;
2168-
case CS8:
2169-
urb_value |= 8;
2170-
dev_dbg(ddev, "Setting CS8\n");
2171-
break;
2172-
default:
2173-
dev_err(ddev, "CSIZE was set but not CS7-CS8\n");
2174-
}
2176+
switch (cflag & CSIZE) {
2177+
case CS7:
2178+
urb_value |= 7;
2179+
dev_dbg(ddev, "Setting CS7\n");
2180+
break;
2181+
default:
2182+
case CS8:
2183+
urb_value |= 8;
2184+
dev_dbg(ddev, "Setting CS8\n");
2185+
break;
21752186
}
21762187

21772188
/* This is needed by the break command since it uses the same command

0 commit comments

Comments
 (0)