Skip to content

Commit

Permalink
USB: ftdi_sio: fixed handling of unsupported CSIZE setting
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Colin Leitner authored and Greg Kroah-Hartman committed Dec 3, 2013
1 parent 78692cc commit 8704211
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions drivers/usb/serial/ftdi_sio.c
Original file line number Diff line number Diff line change
Expand Up @@ -2123,6 +2123,20 @@ static void ftdi_set_termios(struct tty_struct *tty,
termios->c_cflag |= CRTSCTS;
}

/*
* All FTDI UART chips are limited to CS7/8. We won't pretend to
* support CS5/6 and revert the CSIZE setting instead.
*/
if ((C_CSIZE(tty) != CS8) && (C_CSIZE(tty) != CS7)) {
dev_warn(ddev, "requested CSIZE setting not supported\n");

termios->c_cflag &= ~CSIZE;
if (old_termios)
termios->c_cflag |= old_termios->c_cflag & CSIZE;
else
termios->c_cflag |= CS8;
}

cflag = termios->c_cflag;

if (!old_termios)
Expand Down Expand Up @@ -2159,19 +2173,16 @@ static void ftdi_set_termios(struct tty_struct *tty,
} else {
urb_value |= FTDI_SIO_SET_DATA_PARITY_NONE;
}
if (cflag & CSIZE) {
switch (cflag & CSIZE) {
case CS7:
urb_value |= 7;
dev_dbg(ddev, "Setting CS7\n");
break;
case CS8:
urb_value |= 8;
dev_dbg(ddev, "Setting CS8\n");
break;
default:
dev_err(ddev, "CSIZE was set but not CS7-CS8\n");
}
switch (cflag & CSIZE) {
case CS7:
urb_value |= 7;
dev_dbg(ddev, "Setting CS7\n");
break;
default:
case CS8:
urb_value |= 8;
dev_dbg(ddev, "Setting CS8\n");
break;
}

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

0 comments on commit 8704211

Please sign in to comment.