Skip to contentSkip to conversation

tty: handle the case where we cannot restore a line discipline

PATCH New Alan Cox 1 participant 1 message Jun 2, 2017 TTY layer and serial drivers

lore
Share & tools
lore

Alan Cox

author
#0 lore raw

PATCH 1/1 tty: handle the case where we cannot restore a line discipline

Historically the N_TTY driver could never fail but this has become broken over time. Rather than trying to rewrite half the ldisc layer to fix the breakage introduce a second level of fallback with an N_NULL ldisc which cannot fail, and thus restore the guarantees required by the ldisc layer.

We still try and fail to N_TTY first. It's much more useful to find yourself back in your old ldisc (first attempt) or in N_TTY (second attempt), and while I'm not aware of any code out there that makes those assumptions it's good to drive(r) defensively.

---
 drivers/tty/Makefile     |    3 +-
 drivers/tty/n_null.c     |   80 ++++++++++++++++++++++++++++++++++++++++++++++
 drivers/tty/tty_ldisc.c  |   44 +++++++++++++++++--------
 include/uapi/linux/tty.h |    1 +
 4 files changed, 113 insertions(+), 15 deletions(-)
 create mode 100644 drivers/tty/n_null.c
drivers/tty/Makefile +2 -1
index f02becd..8689279 100644
@@ -1,6 +1,7 @@
 obj-$(CONFIG_TTY)		+= tty_io.o n_tty.o tty_ioctl.o tty_ldisc.o \
 				   tty_buffer.o tty_port.o tty_mutex.o \
-				   tty_ldsem.o tty_baudrate.o tty_jobctrl.o
+				   tty_ldsem.o tty_baudrate.o tty_jobctrl.o \
+				   n_null.o
 obj-$(CONFIG_LEGACY_PTYS)	+= pty.o
 obj-$(CONFIG_UNIX98_PTYS)	+= pty.o
 obj-$(CONFIG_AUDIT)		+= tty_audit.o
drivers/tty/n_null.c new file +80 -0

80 lines not on this page · raw message

drivers/tty/tty_ldisc.c +30 -14

62 lines not on this page · raw message

include/uapi/linux/tty.h +1 -0
index e7855df..cf14553 100644
@@ -36,5 +36,6 @@
 #define N_TRACEROUTER	24	/* Trace data routing for MIPI P1149.7 */
 #define N_NCI		25	/* NFC NCI UART */
 #define N_SPEAKUP	26	/* Speakup communication with synths */
+#define N_NULL		27	/* Null ldisc used for error handling */
 
 #endif /* _UAPI_LINUX_TTY_H */