Skip to content

Commit

Permalink
pty: Fix overlimit memory use
Browse files Browse the repository at this point in the history
The pty_space() computation is broken; the space already consumed
in the tty buffer is not accounted for.

Use tty_buffer_set_limit(), which enforces the limit automatically.

Signed-off-by: Peter Hurley <peter@hurleysoftware.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Peter Hurley authored and Greg Kroah-Hartman committed Feb 2, 2015
1 parent 6ecde47 commit c81622a
Showing 1 changed file with 3 additions and 14 deletions.
17 changes: 3 additions & 14 deletions drivers/tty/pty.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,6 @@ static void pty_unthrottle(struct tty_struct *tty)
set_bit(TTY_THROTTLED, &tty->flags);
}

/**
* pty_space - report space left for writing
* @to: tty we are writing into
*
* Limit the buffer space used by ptys to 8k.
*/

static int pty_space(struct tty_struct *to)
{
int n = tty_buffer_space_avail(to->port);
return min(n, 8192);
}

/**
* pty_write - write to a pty
* @tty: the tty we write from
Expand Down Expand Up @@ -141,7 +128,7 @@ static int pty_write_room(struct tty_struct *tty)
{
if (tty->stopped)
return 0;
return pty_space(tty->link);
return tty_buffer_space_avail(tty->link->port);
}

/**
Expand Down Expand Up @@ -432,6 +419,8 @@ static int pty_common_install(struct tty_driver *driver, struct tty_struct *tty,
o_tty->link = tty;
tty_port_init(ports[0]);
tty_port_init(ports[1]);
tty_buffer_set_limit(ports[0], 8192);
tty_buffer_set_limit(ports[1], 8192);
o_tty->port = ports[0];
tty->port = ports[1];
o_tty->port->itty = o_tty;
Expand Down

0 comments on commit c81622a

Please sign in to comment.