tty: Fix deadlock in tty output
authorAlan Cox <alan@linux.intel.com>
Sat, 19 Jan 2019 21:38:54 +0000 (21:38 +0000)
committerAlan Cox <alan@linux.intel.com>
Sat, 19 Jan 2019 21:38:54 +0000 (21:38 +0000)
If you had a dumb tty port (or driver) and your write blocked until pre-emption
then we'd sleep expecting a tty wake event even though the tty doesn't provide
one.

Instead if we got told 'soon' we yield when asked to pre-empt.

Kernel/tty.c

index 6a90fdb..37405a6 100644 (file)
@@ -547,10 +547,14 @@ uint8_t tty_putc_maywait(uint8_t minor, unsigned char c, uint8_t flag)
                                        udata.u_error = EAGAIN;
                                        return 1;
                                }
-                               irq = di();
-                               tty_sleeping(minor);
-                               psleep(&ttydata[minor]);
-                               irqrestore(irq);
+                               if (t != TTY_READY_SOON) {
+                                       irq = di();
+                                       tty_sleeping(minor);
+                                       psleep(&ttydata[minor]);
+                                       irqrestore(irq);
+                               } else
+                                       /* Yield */
+                                       switchout();
                        }
                }
        }