Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jikos/trivial
[firefly-linux-kernel-4.4.55.git] / drivers / tty / n_tty.c
index dd8ae0cad1d5353d88c44e9b5bb55edb09bbd33f..c9a9ddd1d0bc2aa5091d7e1678920df2d9292429 100644 (file)
@@ -2122,6 +2122,17 @@ static ssize_t n_tty_read(struct tty_struct *tty, struct file *file,
        if (c < 0)
                return c;
 
+       /*
+        *      Internal serialization of reads.
+        */
+       if (file->f_flags & O_NONBLOCK) {
+               if (!mutex_trylock(&ldata->atomic_read_lock))
+                       return -EAGAIN;
+       } else {
+               if (mutex_lock_interruptible(&ldata->atomic_read_lock))
+                       return -ERESTARTSYS;
+       }
+
        down_read(&tty->termios_rwsem);
 
        minimum = time = 0;
@@ -2141,20 +2152,6 @@ static ssize_t n_tty_read(struct tty_struct *tty, struct file *file,
                }
        }
 
-       /*
-        *      Internal serialization of reads.
-        */
-       if (file->f_flags & O_NONBLOCK) {
-               if (!mutex_trylock(&ldata->atomic_read_lock)) {
-                       up_read(&tty->termios_rwsem);
-                       return -EAGAIN;
-               }
-       } else {
-               if (mutex_lock_interruptible(&ldata->atomic_read_lock)) {
-                       up_read(&tty->termios_rwsem);
-                       return -ERESTARTSYS;
-               }
-       }
        packet = tty->packet;
 
        add_wait_queue(&tty->read_wait, &wait);