xtensa: ISS: don't hang if stdin EOF is reached
authorMax Filippov <jcmvbkbc@gmail.com>
Mon, 8 Feb 2016 22:02:38 +0000 (01:02 +0300)
committerWilly Tarreau <w@1wt.eu>
Tue, 7 Jun 2016 08:42:46 +0000 (10:42 +0200)
commit 362014c8d9d51d504c167c44ac280169457732be upstream.

Simulator stdin may be connected to a file, when its end is reached
kernel hangs in infinite loop inside rs_poll, because simc_poll always
signals that descriptor 0 is readable and simc_read always returns 0.
Check simc_read return value and exit loop if it's not positive. Also
don't rewind polling timer if it's zero.

Cc: stable@vger.kernel.org
Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
Signed-off-by: Willy Tarreau <w@1wt.eu>
arch/xtensa/platforms/iss/console.c

index 70cb408bc20dc8fc593fbbcebf68d3a06cb967b0..92d785fefb6d0634db9ef891f0ffbedbe2421a40 100644 (file)
@@ -100,21 +100,23 @@ static void rs_poll(unsigned long priv)
 {
        struct tty_port *port = (struct tty_port *)priv;
        int i = 0;
+       int rd = 1;
        unsigned char c;
 
        spin_lock(&timer_lock);
 
        while (simc_poll(0)) {
-               simc_read(0, &c, 1);
+               rd = simc_read(0, &c, 1);
+               if (rd <= 0)
+                       break;
                tty_insert_flip_char(port, c, TTY_NORMAL);
                i++;
        }
 
        if (i)
                tty_flip_buffer_push(port);
-
-
-       mod_timer(&serial_timer, jiffies + SERIAL_TIMER_VALUE);
+       if (rd)
+               mod_timer(&serial_timer, jiffies + SERIAL_TIMER_VALUE);
        spin_unlock(&timer_lock);
 }