Merge tag 'tty-3.19-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty
[linux-2.6-block.git] / drivers / tty / n_tty.c
index 9e3b21624c8242cfc9353cd9a6916a8ca87c3cae..d2b496750d590c1e06d755b0b563f40c30f8d165 100644 (file)
@@ -2124,7 +2124,7 @@ static ssize_t n_tty_read(struct tty_struct *tty, struct file *file,
 {
        struct n_tty_data *ldata = tty->disc_data;
        unsigned char __user *b = buf;
-       DECLARE_WAITQUEUE(wait, current);
+       DEFINE_WAIT_FUNC(wait, woken_wake_function);
        int c;
        int minimum, time;
        ssize_t retval = 0;
@@ -2169,11 +2169,6 @@ static ssize_t n_tty_read(struct tty_struct *tty, struct file *file,
 
        add_wait_queue(&tty->read_wait, &wait);
        while (nr) {
-               /* This statement must be first before checking for input
-                  so that any interrupt will set the state back to
-                  TASK_RUNNING. */
-               set_current_state(TASK_INTERRUPTIBLE);
-
                /* First test for status change. */
                if (packet && tty->link->ctrl_status) {
                        unsigned char cs;
@@ -2216,12 +2211,12 @@ static ssize_t n_tty_read(struct tty_struct *tty, struct file *file,
                        n_tty_set_room(tty);
                        up_read(&tty->termios_rwsem);
 
-                       timeout = schedule_timeout(timeout);
+                       timeout = wait_woken(&wait, TASK_INTERRUPTIBLE,
+                                            timeout);
 
                        down_read(&tty->termios_rwsem);
                        continue;
                }
-               __set_current_state(TASK_RUNNING);
 
                if (ldata->icanon && !L_EXTPROC(tty)) {
                        retval = canon_copy_from_read_buf(tty, &b, &nr);
@@ -2267,7 +2262,6 @@ static ssize_t n_tty_read(struct tty_struct *tty, struct file *file,
 
        mutex_unlock(&ldata->atomic_read_lock);
 
-       __set_current_state(TASK_RUNNING);
        if (b - buf)
                retval = b - buf;
 
@@ -2300,7 +2294,7 @@ static ssize_t n_tty_write(struct tty_struct *tty, struct file *file,
                           const unsigned char *buf, size_t nr)
 {
        const unsigned char *b = buf;
-       DECLARE_WAITQUEUE(wait, current);
+       DEFINE_WAIT_FUNC(wait, woken_wake_function);
        int c;
        ssize_t retval = 0;
 
@@ -2318,7 +2312,6 @@ static ssize_t n_tty_write(struct tty_struct *tty, struct file *file,
 
        add_wait_queue(&tty->write_wait, &wait);
        while (1) {
-               set_current_state(TASK_INTERRUPTIBLE);
                if (signal_pending(current)) {
                        retval = -ERESTARTSYS;
                        break;
@@ -2372,12 +2365,11 @@ static ssize_t n_tty_write(struct tty_struct *tty, struct file *file,
                }
                up_read(&tty->termios_rwsem);
 
-               schedule();
+               wait_woken(&wait, TASK_INTERRUPTIBLE, MAX_SCHEDULE_TIMEOUT);
 
                down_read(&tty->termios_rwsem);
        }
 break_out:
-       __set_current_state(TASK_RUNNING);
        remove_wait_queue(&tty->write_wait, &wait);
        if (b - buf != nr && tty->fasync)
                set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);