Re: [PATCH] Fix Corruption issue in USB ftdi driver drivers/usb/serial/ftdi_sio.c

From: Andrew Worsley
Date: Fri Oct 28 2011 - 16:25:22 EST

On 28 October 2011 21:50, Uwe Bonnes
<bon@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
>>>>>> "Andrew" == Andrew Worsley <amworsley@xxxxxxxxx> writes:
> Â ÂAndrew> ftdi_set_termios() is always setting the baud rate and data bits
> Â ÂAndrew> and parity on every call. When called while characters are being
> Â ÂAndrew> transmitted can cause the FTDI chip to corrupt the serial port
> Â ÂAndrew> bit stream by stalling the output half a bit during the output
> Â ÂAndrew> of a character. ÂSimple fix by skipping this setting if the baud
> Â ÂAndrew> rate/data bits/parity are unchanged.
> Â ÂAndrew> Signed-off-by: Andrew Worsley <amworsley@xxxxxxxxx> ----
> Â ÂAndrew> This bug was observed on 2.6.32 kernel (this patch is ported to
> Â ÂAndrew> latest kernel for ease of review). ÂUsing a FTDI USB serial chip
> Â ÂAndrew> at 38400 repeatedly generating output by running a simple
> Â ÂAndrew> command such as "uname -a" or "echo Linux" gives occasional
> Â ÂAndrew> corruption on the output
> Â ÂAndrew> ...
> Â Â>> echo Linux
> Â ÂAndrew> Lï3u=nux
> Could you please give a more specific receipe to reproduce the bug. Running
> with an adapter with TX/RX shorted at "stty -F /dev/ttyUSB0" 38400", several
>> uname -a /dev/ttyUSB0
> runs gave no artifact in a "seyon -modem /dev/ttyUSB0" console.
> Doing
>> uname -a /dev/ttyUSB0
> in one xterm and receiving with
>>cat /dev/ttyUSB0
> in another xterm gives lot of repeated lines in the receiving terminal. But
> I have the same behaviour with /dev/ttyS0 on a real serial port on the
> mainboard.
> Otherwise, shouldn't all control transfers to the FTDI be only done with the
> tx buffer in the FTDI empty? I guess the RX buffer is not affected by some
> change. But this is something to be done with great knowledge...
Thank you for your testing efforts. In a sense I am not surprised that
an obvious attempt at reproduction doesn't show it as I would have
thought this bug would have been found long ago if it
did. At the moment the best I can do is describe my configuration and
invite requests for details on additional fields that you think

We use the ftdi chip to provide a serial console so the program I am
running on it is
/sbin/getty -L ttyUSB0 38400. I can't give you the exact stty settings
the defaults set up as I
am at home but ixon was set but clearing it didn't help.

My key detective was to configure CONFIG_USB_MON and look at the
requests going to the port.
There were always 3 Control requests after each carriage return which
set speed/baud rate/flow control which seemed kinda crazy.

Perhaps it was something to do with the prompt which had an escape
sequence in it as other people noticed that playing with the delay of
the prompt could clear it. Alternatively the more modern kernel may
not illustrate the same issue - due to some fix that avoids or
minimises the repeated calls of ftdi_set_termios() ?

I suspect the configuration of the tty line is critical and is
something I don't understand as it appears to be constantly adjusting
the settings but only changing the flow control.I don't have the exact
settings in front of me so from memory it appeared to be cycling

IXON, IXOFF and may be one other perhaps IXANY or possibly IUCLC?

If people are interested in any particular details I can send you
them, next week. Including
stack traces, CONFIG_USB_MON traces, screen shot of CRO with corrupted
character + other requested

But what I don't understand is the logic that drives
ftdi_set_termios() repeated calls with the flow control changes. I
would appreciate an explanation of this and others might be interested
in this if they are trying to optimise the kernel on serial I/O.

Even if such constant calling is justified (some how XON/XOFF is being
implemented?) I think it should be harmless (and more efficient) not
to skip setting the BAUD rate and other data parameters which is a
significant amount of work. And in my case this extract work appears
to be
glitch the FTDI chip.

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at
Please read the FAQ at