Commit ac89a917 authored by Linus Torvalds's avatar Linus Torvalds
Browse files

pty: don't limit the writes to 'pty_space()' inside 'pty_write()'

The whole write-room thing is something that is up to the _caller_ to
worry about, not the pty layer itself.  The total buffer space will
still be limited by the buffering routines themselves, so there is no
advantage or need in having pty_write() artificially limit the size

And what happened was that the caller (the n_tty line discipline, in
this case) may have verified that there is room for 2 bytes to be
written (for NL -> CRNL expansion), and it used to then do those writes
as two single-byte writes.  And if the first byte written (CR) then
caused a new tty buffer to be allocated, pty_space() may have returned
zero when trying to write the second byte (LF), and then incorrectly
failed the write - leading to a lost newline character.

This should finally fix

Reported-by: default avatarMikael Pettersson <>
Acked-by: default avatarAlan Cox <>
Signed-off-by: default avatarLinus Torvalds <>
parent 37f81fa1
......@@ -109,21 +109,13 @@ static int pty_space(struct tty_struct *to)
* the other side of the pty/tty pair.
static int pty_write(struct tty_struct *tty, const unsigned char *buf,
int count)
static int pty_write(struct tty_struct *tty, const unsigned char *buf, int c)
struct tty_struct *to = tty->link;
int c;
if (tty->stopped)
return 0;
/* This isn't locked but our 8K is quite sloppy so no
big deal */
c = pty_space(to);
if (c > count)
c = count;
if (c > 0) {
/* Stuff the data into the input queue of the other end */
c = tty_insert_flip_string(to, buf, c);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment