X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=drivers%2Fchar%2Fpty.c;h=da32889d22c0992a32f00560f2fbeec41519878f;hb=6a77f38946aaee1cd85eeec6cf4229b204c15071;hp=9826bbd0f67a475985ff3a47f9de9130f335afa8;hpb=87fc8d1bb10cd459024a742c6a10961fefcef18f;p=linux-2.6.git diff --git a/drivers/char/pty.c b/drivers/char/pty.c index 9826bbd0f..da32889d2 100644 --- a/drivers/char/pty.c +++ b/drivers/char/pty.c @@ -29,13 +29,13 @@ #include #include -#include +#include #include /* These are global because they are accessed in tty_io.c */ #ifdef CONFIG_UNIX98_PTYS struct tty_driver *ptm_driver; -struct tty_driver *pts_driver; +static struct tty_driver *pts_driver; #endif static void pty_close(struct tty_struct * tty, struct file * filp) @@ -55,9 +55,9 @@ static void pty_close(struct tty_struct * tty, struct file * filp) if (!tty->link) return; tty->link->packet = 0; + set_bit(TTY_OTHER_CLOSED, &tty->link->flags); wake_up_interruptible(&tty->link->read_wait); wake_up_interruptible(&tty->link->write_wait); - set_bit(TTY_OTHER_CLOSED, &tty->link->flags); if (tty->driver->subtype == PTY_TYPE_MASTER) { set_bit(TTY_OTHER_CLOSED, &tty->flags); #ifdef CONFIG_UNIX98_PTYS @@ -103,51 +103,18 @@ static void pty_unthrottle(struct tty_struct * tty) * not our partners. We can't just take the other one blindly without * risking deadlocks. There is also the small matter of TTY_DONT_FLIP */ -static int pty_write(struct tty_struct * tty, int from_user, - const unsigned char *buf, int count) +static int pty_write(struct tty_struct * tty, const unsigned char *buf, int count) { struct tty_struct *to = tty->link; - int c=0, n, room; - char *temp_buffer; + int c; if (!to || tty->stopped) return 0; - if (from_user) { - down(&tty->flip.pty_sem); - temp_buffer = &tty->flip.char_buf[0]; - while (count > 0) { - /* check space so we don't copy needlessly */ - n = to->ldisc.receive_room(to); - if (n > count) - n = count; - if (!n) break; - - n = min(n, PTY_BUF_SIZE); - n -= copy_from_user(temp_buffer, buf, n); - if (!n) { - if (!c) - c = -EFAULT; - break; - } - - /* check again in case the buffer filled up */ - room = to->ldisc.receive_room(to); - if (n > room) - n = room; - if (!n) break; - buf += n; - c += n; - count -= n; - to->ldisc.receive_buf(to, temp_buffer, NULL, n); - } - up(&tty->flip.pty_sem); - } else { - c = to->ldisc.receive_room(to); - if (c > count) - c = count; - to->ldisc.receive_buf(to, buf, NULL, c); - } + c = to->ldisc.receive_room(to); + if (c > count) + c = count; + to->ldisc.receive_buf(to, buf, NULL, c); return c; } @@ -182,13 +149,15 @@ static int pty_write_room(struct tty_struct *tty) static int pty_chars_in_buffer(struct tty_struct *tty) { struct tty_struct *to = tty->link; + ssize_t (*chars_in_buffer)(struct tty_struct *); int count; - if (!to || !to->ldisc.chars_in_buffer) + /* We should get the line discipline lock for "tty->link" */ + if (!to || !(chars_in_buffer = to->ldisc.chars_in_buffer)) return 0; /* The ldisc must report 0 if no characters available to be read */ - count = to->ldisc.chars_in_buffer(to); + count = chars_in_buffer(to); if (tty->driver->subtype == PTY_TYPE_SLAVE) return count;