196fd7ce5SGreg Kroah-Hartman #include <linux/types.h> 296fd7ce5SGreg Kroah-Hartman #include <linux/errno.h> 38b3ffa17SJiri Slaby #include <linux/kmod.h> 496fd7ce5SGreg Kroah-Hartman #include <linux/sched.h> 596fd7ce5SGreg Kroah-Hartman #include <linux/interrupt.h> 696fd7ce5SGreg Kroah-Hartman #include <linux/tty.h> 796fd7ce5SGreg Kroah-Hartman #include <linux/tty_driver.h> 896fd7ce5SGreg Kroah-Hartman #include <linux/file.h> 996fd7ce5SGreg Kroah-Hartman #include <linux/mm.h> 1096fd7ce5SGreg Kroah-Hartman #include <linux/string.h> 1196fd7ce5SGreg Kroah-Hartman #include <linux/slab.h> 1296fd7ce5SGreg Kroah-Hartman #include <linux/poll.h> 1396fd7ce5SGreg Kroah-Hartman #include <linux/proc_fs.h> 1496fd7ce5SGreg Kroah-Hartman #include <linux/init.h> 1596fd7ce5SGreg Kroah-Hartman #include <linux/module.h> 1696fd7ce5SGreg Kroah-Hartman #include <linux/device.h> 1796fd7ce5SGreg Kroah-Hartman #include <linux/wait.h> 1896fd7ce5SGreg Kroah-Hartman #include <linux/bitops.h> 1996fd7ce5SGreg Kroah-Hartman #include <linux/seq_file.h> 2096fd7ce5SGreg Kroah-Hartman #include <linux/uaccess.h> 210c73c08eSJiri Slaby #include <linux/ratelimit.h> 2296fd7ce5SGreg Kroah-Hartman 23fc575ee6SPeter Hurley #undef LDISC_DEBUG_HANGUP 24fc575ee6SPeter Hurley 25fc575ee6SPeter Hurley #ifdef LDISC_DEBUG_HANGUP 26fc575ee6SPeter Hurley #define tty_ldisc_debug(tty, f, args...) ({ \ 27fc575ee6SPeter Hurley char __b[64]; \ 28fc575ee6SPeter Hurley printk(KERN_DEBUG "%s: %s: " f, __func__, tty_name(tty, __b), ##args); \ 29fc575ee6SPeter Hurley }) 30fc575ee6SPeter Hurley #else 31fc575ee6SPeter Hurley #define tty_ldisc_debug(tty, f, args...) 32fc575ee6SPeter Hurley #endif 33fc575ee6SPeter Hurley 3496fd7ce5SGreg Kroah-Hartman /* 3596fd7ce5SGreg Kroah-Hartman * This guards the refcounted line discipline lists. The lock 3696fd7ce5SGreg Kroah-Hartman * must be taken with irqs off because there are hangup path 3796fd7ce5SGreg Kroah-Hartman * callers who will do ldisc lookups and cannot sleep. 3896fd7ce5SGreg Kroah-Hartman */ 3996fd7ce5SGreg Kroah-Hartman 40137084bbSPeter Hurley static DEFINE_RAW_SPINLOCK(tty_ldiscs_lock); 4196fd7ce5SGreg Kroah-Hartman static DECLARE_WAIT_QUEUE_HEAD(tty_ldisc_wait); 4296fd7ce5SGreg Kroah-Hartman /* Line disc dispatch table */ 4396fd7ce5SGreg Kroah-Hartman static struct tty_ldisc_ops *tty_ldiscs[NR_LDISCS]; 4496fd7ce5SGreg Kroah-Hartman 4596fd7ce5SGreg Kroah-Hartman /** 4696fd7ce5SGreg Kroah-Hartman * tty_register_ldisc - install a line discipline 4796fd7ce5SGreg Kroah-Hartman * @disc: ldisc number 4896fd7ce5SGreg Kroah-Hartman * @new_ldisc: pointer to the ldisc object 4996fd7ce5SGreg Kroah-Hartman * 5096fd7ce5SGreg Kroah-Hartman * Installs a new line discipline into the kernel. The discipline 5196fd7ce5SGreg Kroah-Hartman * is set up as unreferenced and then made available to the kernel 5296fd7ce5SGreg Kroah-Hartman * from this point onwards. 5396fd7ce5SGreg Kroah-Hartman * 5496fd7ce5SGreg Kroah-Hartman * Locking: 55137084bbSPeter Hurley * takes tty_ldiscs_lock to guard against ldisc races 5696fd7ce5SGreg Kroah-Hartman */ 5796fd7ce5SGreg Kroah-Hartman 5896fd7ce5SGreg Kroah-Hartman int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc) 5996fd7ce5SGreg Kroah-Hartman { 6096fd7ce5SGreg Kroah-Hartman unsigned long flags; 6196fd7ce5SGreg Kroah-Hartman int ret = 0; 6296fd7ce5SGreg Kroah-Hartman 6396fd7ce5SGreg Kroah-Hartman if (disc < N_TTY || disc >= NR_LDISCS) 6496fd7ce5SGreg Kroah-Hartman return -EINVAL; 6596fd7ce5SGreg Kroah-Hartman 66137084bbSPeter Hurley raw_spin_lock_irqsave(&tty_ldiscs_lock, flags); 6796fd7ce5SGreg Kroah-Hartman tty_ldiscs[disc] = new_ldisc; 6896fd7ce5SGreg Kroah-Hartman new_ldisc->num = disc; 6996fd7ce5SGreg Kroah-Hartman new_ldisc->refcount = 0; 70137084bbSPeter Hurley raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags); 7196fd7ce5SGreg Kroah-Hartman 7296fd7ce5SGreg Kroah-Hartman return ret; 7396fd7ce5SGreg Kroah-Hartman } 7496fd7ce5SGreg Kroah-Hartman EXPORT_SYMBOL(tty_register_ldisc); 7596fd7ce5SGreg Kroah-Hartman 7696fd7ce5SGreg Kroah-Hartman /** 7796fd7ce5SGreg Kroah-Hartman * tty_unregister_ldisc - unload a line discipline 7896fd7ce5SGreg Kroah-Hartman * @disc: ldisc number 7996fd7ce5SGreg Kroah-Hartman * @new_ldisc: pointer to the ldisc object 8096fd7ce5SGreg Kroah-Hartman * 8196fd7ce5SGreg Kroah-Hartman * Remove a line discipline from the kernel providing it is not 8296fd7ce5SGreg Kroah-Hartman * currently in use. 8396fd7ce5SGreg Kroah-Hartman * 8496fd7ce5SGreg Kroah-Hartman * Locking: 85137084bbSPeter Hurley * takes tty_ldiscs_lock to guard against ldisc races 8696fd7ce5SGreg Kroah-Hartman */ 8796fd7ce5SGreg Kroah-Hartman 8896fd7ce5SGreg Kroah-Hartman int tty_unregister_ldisc(int disc) 8996fd7ce5SGreg Kroah-Hartman { 9096fd7ce5SGreg Kroah-Hartman unsigned long flags; 9196fd7ce5SGreg Kroah-Hartman int ret = 0; 9296fd7ce5SGreg Kroah-Hartman 9396fd7ce5SGreg Kroah-Hartman if (disc < N_TTY || disc >= NR_LDISCS) 9496fd7ce5SGreg Kroah-Hartman return -EINVAL; 9596fd7ce5SGreg Kroah-Hartman 96137084bbSPeter Hurley raw_spin_lock_irqsave(&tty_ldiscs_lock, flags); 9796fd7ce5SGreg Kroah-Hartman if (tty_ldiscs[disc]->refcount) 9896fd7ce5SGreg Kroah-Hartman ret = -EBUSY; 9996fd7ce5SGreg Kroah-Hartman else 10096fd7ce5SGreg Kroah-Hartman tty_ldiscs[disc] = NULL; 101137084bbSPeter Hurley raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags); 10296fd7ce5SGreg Kroah-Hartman 10396fd7ce5SGreg Kroah-Hartman return ret; 10496fd7ce5SGreg Kroah-Hartman } 10596fd7ce5SGreg Kroah-Hartman EXPORT_SYMBOL(tty_unregister_ldisc); 10696fd7ce5SGreg Kroah-Hartman 10796fd7ce5SGreg Kroah-Hartman static struct tty_ldisc_ops *get_ldops(int disc) 10896fd7ce5SGreg Kroah-Hartman { 10996fd7ce5SGreg Kroah-Hartman unsigned long flags; 11096fd7ce5SGreg Kroah-Hartman struct tty_ldisc_ops *ldops, *ret; 11196fd7ce5SGreg Kroah-Hartman 112137084bbSPeter Hurley raw_spin_lock_irqsave(&tty_ldiscs_lock, flags); 11396fd7ce5SGreg Kroah-Hartman ret = ERR_PTR(-EINVAL); 11496fd7ce5SGreg Kroah-Hartman ldops = tty_ldiscs[disc]; 11596fd7ce5SGreg Kroah-Hartman if (ldops) { 11696fd7ce5SGreg Kroah-Hartman ret = ERR_PTR(-EAGAIN); 11796fd7ce5SGreg Kroah-Hartman if (try_module_get(ldops->owner)) { 11896fd7ce5SGreg Kroah-Hartman ldops->refcount++; 11996fd7ce5SGreg Kroah-Hartman ret = ldops; 12096fd7ce5SGreg Kroah-Hartman } 12196fd7ce5SGreg Kroah-Hartman } 122137084bbSPeter Hurley raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags); 12396fd7ce5SGreg Kroah-Hartman return ret; 12496fd7ce5SGreg Kroah-Hartman } 12596fd7ce5SGreg Kroah-Hartman 12696fd7ce5SGreg Kroah-Hartman static void put_ldops(struct tty_ldisc_ops *ldops) 12796fd7ce5SGreg Kroah-Hartman { 12896fd7ce5SGreg Kroah-Hartman unsigned long flags; 12996fd7ce5SGreg Kroah-Hartman 130137084bbSPeter Hurley raw_spin_lock_irqsave(&tty_ldiscs_lock, flags); 13196fd7ce5SGreg Kroah-Hartman ldops->refcount--; 13296fd7ce5SGreg Kroah-Hartman module_put(ldops->owner); 133137084bbSPeter Hurley raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags); 13496fd7ce5SGreg Kroah-Hartman } 13596fd7ce5SGreg Kroah-Hartman 13696fd7ce5SGreg Kroah-Hartman /** 13796fd7ce5SGreg Kroah-Hartman * tty_ldisc_get - take a reference to an ldisc 13896fd7ce5SGreg Kroah-Hartman * @disc: ldisc number 13996fd7ce5SGreg Kroah-Hartman * 14096fd7ce5SGreg Kroah-Hartman * Takes a reference to a line discipline. Deals with refcounts and 14196fd7ce5SGreg Kroah-Hartman * module locking counts. Returns NULL if the discipline is not available. 14296fd7ce5SGreg Kroah-Hartman * Returns a pointer to the discipline and bumps the ref count if it is 14396fd7ce5SGreg Kroah-Hartman * available 14496fd7ce5SGreg Kroah-Hartman * 14596fd7ce5SGreg Kroah-Hartman * Locking: 146137084bbSPeter Hurley * takes tty_ldiscs_lock to guard against ldisc races 14796fd7ce5SGreg Kroah-Hartman */ 14896fd7ce5SGreg Kroah-Hartman 14996fd7ce5SGreg Kroah-Hartman static struct tty_ldisc *tty_ldisc_get(int disc) 15096fd7ce5SGreg Kroah-Hartman { 15196fd7ce5SGreg Kroah-Hartman struct tty_ldisc *ld; 15296fd7ce5SGreg Kroah-Hartman struct tty_ldisc_ops *ldops; 15396fd7ce5SGreg Kroah-Hartman 15496fd7ce5SGreg Kroah-Hartman if (disc < N_TTY || disc >= NR_LDISCS) 15596fd7ce5SGreg Kroah-Hartman return ERR_PTR(-EINVAL); 15696fd7ce5SGreg Kroah-Hartman 15796fd7ce5SGreg Kroah-Hartman /* 15896fd7ce5SGreg Kroah-Hartman * Get the ldisc ops - we may need to request them to be loaded 15996fd7ce5SGreg Kroah-Hartman * dynamically and try again. 16096fd7ce5SGreg Kroah-Hartman */ 16196fd7ce5SGreg Kroah-Hartman ldops = get_ldops(disc); 16296fd7ce5SGreg Kroah-Hartman if (IS_ERR(ldops)) { 16396fd7ce5SGreg Kroah-Hartman request_module("tty-ldisc-%d", disc); 16496fd7ce5SGreg Kroah-Hartman ldops = get_ldops(disc); 16596fd7ce5SGreg Kroah-Hartman if (IS_ERR(ldops)) 16696fd7ce5SGreg Kroah-Hartman return ERR_CAST(ldops); 16796fd7ce5SGreg Kroah-Hartman } 16896fd7ce5SGreg Kroah-Hartman 16996fd7ce5SGreg Kroah-Hartman ld = kmalloc(sizeof(struct tty_ldisc), GFP_KERNEL); 17096fd7ce5SGreg Kroah-Hartman if (ld == NULL) { 17196fd7ce5SGreg Kroah-Hartman put_ldops(ldops); 17296fd7ce5SGreg Kroah-Hartman return ERR_PTR(-ENOMEM); 17396fd7ce5SGreg Kroah-Hartman } 17496fd7ce5SGreg Kroah-Hartman 17596fd7ce5SGreg Kroah-Hartman ld->ops = ldops; 17696fd7ce5SGreg Kroah-Hartman atomic_set(&ld->users, 1); 1771541f845SIvo Sieben init_waitqueue_head(&ld->wq_idle); 1781541f845SIvo Sieben 17996fd7ce5SGreg Kroah-Hartman return ld; 18096fd7ce5SGreg Kroah-Hartman } 18196fd7ce5SGreg Kroah-Hartman 182734de249SPeter Hurley /** 183734de249SPeter Hurley * tty_ldisc_put - release the ldisc 184734de249SPeter Hurley * 185734de249SPeter Hurley * Complement of tty_ldisc_get(). 186734de249SPeter Hurley */ 187734de249SPeter Hurley static inline void tty_ldisc_put(struct tty_ldisc *ld) 188734de249SPeter Hurley { 189734de249SPeter Hurley unsigned long flags; 190734de249SPeter Hurley 191734de249SPeter Hurley if (WARN_ON_ONCE(!ld)) 192734de249SPeter Hurley return; 193734de249SPeter Hurley 194137084bbSPeter Hurley raw_spin_lock_irqsave(&tty_ldiscs_lock, flags); 195734de249SPeter Hurley 196734de249SPeter Hurley /* unreleased reader reference(s) will cause this WARN */ 197734de249SPeter Hurley WARN_ON(!atomic_dec_and_test(&ld->users)); 198734de249SPeter Hurley 199734de249SPeter Hurley ld->ops->refcount--; 200734de249SPeter Hurley module_put(ld->ops->owner); 201734de249SPeter Hurley kfree(ld); 202137084bbSPeter Hurley raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags); 203734de249SPeter Hurley } 204734de249SPeter Hurley 20596fd7ce5SGreg Kroah-Hartman static void *tty_ldiscs_seq_start(struct seq_file *m, loff_t *pos) 20696fd7ce5SGreg Kroah-Hartman { 20796fd7ce5SGreg Kroah-Hartman return (*pos < NR_LDISCS) ? pos : NULL; 20896fd7ce5SGreg Kroah-Hartman } 20996fd7ce5SGreg Kroah-Hartman 21096fd7ce5SGreg Kroah-Hartman static void *tty_ldiscs_seq_next(struct seq_file *m, void *v, loff_t *pos) 21196fd7ce5SGreg Kroah-Hartman { 21296fd7ce5SGreg Kroah-Hartman (*pos)++; 21396fd7ce5SGreg Kroah-Hartman return (*pos < NR_LDISCS) ? pos : NULL; 21496fd7ce5SGreg Kroah-Hartman } 21596fd7ce5SGreg Kroah-Hartman 21696fd7ce5SGreg Kroah-Hartman static void tty_ldiscs_seq_stop(struct seq_file *m, void *v) 21796fd7ce5SGreg Kroah-Hartman { 21896fd7ce5SGreg Kroah-Hartman } 21996fd7ce5SGreg Kroah-Hartman 22096fd7ce5SGreg Kroah-Hartman static int tty_ldiscs_seq_show(struct seq_file *m, void *v) 22196fd7ce5SGreg Kroah-Hartman { 22296fd7ce5SGreg Kroah-Hartman int i = *(loff_t *)v; 22396fd7ce5SGreg Kroah-Hartman struct tty_ldisc_ops *ldops; 22496fd7ce5SGreg Kroah-Hartman 22596fd7ce5SGreg Kroah-Hartman ldops = get_ldops(i); 22696fd7ce5SGreg Kroah-Hartman if (IS_ERR(ldops)) 22796fd7ce5SGreg Kroah-Hartman return 0; 22896fd7ce5SGreg Kroah-Hartman seq_printf(m, "%-10s %2d\n", ldops->name ? ldops->name : "???", i); 22996fd7ce5SGreg Kroah-Hartman put_ldops(ldops); 23096fd7ce5SGreg Kroah-Hartman return 0; 23196fd7ce5SGreg Kroah-Hartman } 23296fd7ce5SGreg Kroah-Hartman 23396fd7ce5SGreg Kroah-Hartman static const struct seq_operations tty_ldiscs_seq_ops = { 23496fd7ce5SGreg Kroah-Hartman .start = tty_ldiscs_seq_start, 23596fd7ce5SGreg Kroah-Hartman .next = tty_ldiscs_seq_next, 23696fd7ce5SGreg Kroah-Hartman .stop = tty_ldiscs_seq_stop, 23796fd7ce5SGreg Kroah-Hartman .show = tty_ldiscs_seq_show, 23896fd7ce5SGreg Kroah-Hartman }; 23996fd7ce5SGreg Kroah-Hartman 24096fd7ce5SGreg Kroah-Hartman static int proc_tty_ldiscs_open(struct inode *inode, struct file *file) 24196fd7ce5SGreg Kroah-Hartman { 24296fd7ce5SGreg Kroah-Hartman return seq_open(file, &tty_ldiscs_seq_ops); 24396fd7ce5SGreg Kroah-Hartman } 24496fd7ce5SGreg Kroah-Hartman 24596fd7ce5SGreg Kroah-Hartman const struct file_operations tty_ldiscs_proc_fops = { 24696fd7ce5SGreg Kroah-Hartman .owner = THIS_MODULE, 24796fd7ce5SGreg Kroah-Hartman .open = proc_tty_ldiscs_open, 24896fd7ce5SGreg Kroah-Hartman .read = seq_read, 24996fd7ce5SGreg Kroah-Hartman .llseek = seq_lseek, 25096fd7ce5SGreg Kroah-Hartman .release = seq_release, 25196fd7ce5SGreg Kroah-Hartman }; 25296fd7ce5SGreg Kroah-Hartman 25396fd7ce5SGreg Kroah-Hartman /** 25496fd7ce5SGreg Kroah-Hartman * tty_ldisc_try - internal helper 25596fd7ce5SGreg Kroah-Hartman * @tty: the tty 25696fd7ce5SGreg Kroah-Hartman * 25796fd7ce5SGreg Kroah-Hartman * Make a single attempt to grab and bump the refcount on 25896fd7ce5SGreg Kroah-Hartman * the tty ldisc. Return 0 on failure or 1 on success. This is 25996fd7ce5SGreg Kroah-Hartman * used to implement both the waiting and non waiting versions 26096fd7ce5SGreg Kroah-Hartman * of tty_ldisc_ref 26196fd7ce5SGreg Kroah-Hartman * 262137084bbSPeter Hurley * Locking: takes tty_ldiscs_lock 26396fd7ce5SGreg Kroah-Hartman */ 26496fd7ce5SGreg Kroah-Hartman 26596fd7ce5SGreg Kroah-Hartman static struct tty_ldisc *tty_ldisc_try(struct tty_struct *tty) 26696fd7ce5SGreg Kroah-Hartman { 26796fd7ce5SGreg Kroah-Hartman unsigned long flags; 26896fd7ce5SGreg Kroah-Hartman struct tty_ldisc *ld; 26996fd7ce5SGreg Kroah-Hartman 27016759f6cSPeter Hurley /* FIXME: this allows reference acquire after TTY_LDISC is cleared */ 271137084bbSPeter Hurley raw_spin_lock_irqsave(&tty_ldiscs_lock, flags); 27296fd7ce5SGreg Kroah-Hartman ld = NULL; 27316759f6cSPeter Hurley if (test_bit(TTY_LDISC, &tty->flags) && tty->ldisc) { 27416759f6cSPeter Hurley ld = tty->ldisc; 27516759f6cSPeter Hurley atomic_inc(&ld->users); 27616759f6cSPeter Hurley } 277137084bbSPeter Hurley raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags); 27896fd7ce5SGreg Kroah-Hartman return ld; 27996fd7ce5SGreg Kroah-Hartman } 28096fd7ce5SGreg Kroah-Hartman 28196fd7ce5SGreg Kroah-Hartman /** 28296fd7ce5SGreg Kroah-Hartman * tty_ldisc_ref_wait - wait for the tty ldisc 28396fd7ce5SGreg Kroah-Hartman * @tty: tty device 28496fd7ce5SGreg Kroah-Hartman * 28596fd7ce5SGreg Kroah-Hartman * Dereference the line discipline for the terminal and take a 28696fd7ce5SGreg Kroah-Hartman * reference to it. If the line discipline is in flux then 28796fd7ce5SGreg Kroah-Hartman * wait patiently until it changes. 28896fd7ce5SGreg Kroah-Hartman * 28996fd7ce5SGreg Kroah-Hartman * Note: Must not be called from an IRQ/timer context. The caller 29096fd7ce5SGreg Kroah-Hartman * must also be careful not to hold other locks that will deadlock 29196fd7ce5SGreg Kroah-Hartman * against a discipline change, such as an existing ldisc reference 29296fd7ce5SGreg Kroah-Hartman * (which we check for) 29396fd7ce5SGreg Kroah-Hartman * 294137084bbSPeter Hurley * Locking: call functions take tty_ldiscs_lock 29596fd7ce5SGreg Kroah-Hartman */ 29696fd7ce5SGreg Kroah-Hartman 29796fd7ce5SGreg Kroah-Hartman struct tty_ldisc *tty_ldisc_ref_wait(struct tty_struct *tty) 29896fd7ce5SGreg Kroah-Hartman { 29996fd7ce5SGreg Kroah-Hartman struct tty_ldisc *ld; 30096fd7ce5SGreg Kroah-Hartman 30196fd7ce5SGreg Kroah-Hartman /* wait_event is a macro */ 30296fd7ce5SGreg Kroah-Hartman wait_event(tty_ldisc_wait, (ld = tty_ldisc_try(tty)) != NULL); 30396fd7ce5SGreg Kroah-Hartman return ld; 30496fd7ce5SGreg Kroah-Hartman } 30596fd7ce5SGreg Kroah-Hartman EXPORT_SYMBOL_GPL(tty_ldisc_ref_wait); 30696fd7ce5SGreg Kroah-Hartman 30796fd7ce5SGreg Kroah-Hartman /** 30896fd7ce5SGreg Kroah-Hartman * tty_ldisc_ref - get the tty ldisc 30996fd7ce5SGreg Kroah-Hartman * @tty: tty device 31096fd7ce5SGreg Kroah-Hartman * 31196fd7ce5SGreg Kroah-Hartman * Dereference the line discipline for the terminal and take a 31296fd7ce5SGreg Kroah-Hartman * reference to it. If the line discipline is in flux then 31396fd7ce5SGreg Kroah-Hartman * return NULL. Can be called from IRQ and timer functions. 31496fd7ce5SGreg Kroah-Hartman * 315137084bbSPeter Hurley * Locking: called functions take tty_ldiscs_lock 31696fd7ce5SGreg Kroah-Hartman */ 31796fd7ce5SGreg Kroah-Hartman 31896fd7ce5SGreg Kroah-Hartman struct tty_ldisc *tty_ldisc_ref(struct tty_struct *tty) 31996fd7ce5SGreg Kroah-Hartman { 32096fd7ce5SGreg Kroah-Hartman return tty_ldisc_try(tty); 32196fd7ce5SGreg Kroah-Hartman } 32296fd7ce5SGreg Kroah-Hartman EXPORT_SYMBOL_GPL(tty_ldisc_ref); 32396fd7ce5SGreg Kroah-Hartman 32496fd7ce5SGreg Kroah-Hartman /** 32596fd7ce5SGreg Kroah-Hartman * tty_ldisc_deref - free a tty ldisc reference 32696fd7ce5SGreg Kroah-Hartman * @ld: reference to free up 32796fd7ce5SGreg Kroah-Hartman * 32896fd7ce5SGreg Kroah-Hartman * Undoes the effect of tty_ldisc_ref or tty_ldisc_ref_wait. May 32996fd7ce5SGreg Kroah-Hartman * be called in IRQ context. 33096fd7ce5SGreg Kroah-Hartman * 331137084bbSPeter Hurley * Locking: takes tty_ldiscs_lock 33296fd7ce5SGreg Kroah-Hartman */ 33396fd7ce5SGreg Kroah-Hartman 33496fd7ce5SGreg Kroah-Hartman void tty_ldisc_deref(struct tty_ldisc *ld) 33596fd7ce5SGreg Kroah-Hartman { 336ebc9baedSPeter Hurley unsigned long flags; 337ebc9baedSPeter Hurley 338ebc9baedSPeter Hurley if (WARN_ON_ONCE(!ld)) 339ebc9baedSPeter Hurley return; 340ebc9baedSPeter Hurley 341137084bbSPeter Hurley raw_spin_lock_irqsave(&tty_ldiscs_lock, flags); 342ebc9baedSPeter Hurley /* 343ebc9baedSPeter Hurley * WARNs if one-too-many reader references were released 344ebc9baedSPeter Hurley * - the last reference must be released with tty_ldisc_put 345ebc9baedSPeter Hurley */ 346ebc9baedSPeter Hurley WARN_ON(atomic_dec_and_test(&ld->users)); 347137084bbSPeter Hurley raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags); 348ebc9baedSPeter Hurley 349ebc9baedSPeter Hurley if (waitqueue_active(&ld->wq_idle)) 350ebc9baedSPeter Hurley wake_up(&ld->wq_idle); 35196fd7ce5SGreg Kroah-Hartman } 35296fd7ce5SGreg Kroah-Hartman EXPORT_SYMBOL_GPL(tty_ldisc_deref); 35396fd7ce5SGreg Kroah-Hartman 354ebc9baedSPeter Hurley /** 35596fd7ce5SGreg Kroah-Hartman * tty_ldisc_enable - allow ldisc use 35696fd7ce5SGreg Kroah-Hartman * @tty: terminal to activate ldisc on 35796fd7ce5SGreg Kroah-Hartman * 35896fd7ce5SGreg Kroah-Hartman * Set the TTY_LDISC flag when the line discipline can be called 35996fd7ce5SGreg Kroah-Hartman * again. Do necessary wakeups for existing sleepers. Clear the LDISC 36096fd7ce5SGreg Kroah-Hartman * changing flag to indicate any ldisc change is now over. 36196fd7ce5SGreg Kroah-Hartman * 36296fd7ce5SGreg Kroah-Hartman * Note: nobody should set the TTY_LDISC bit except via this function. 36396fd7ce5SGreg Kroah-Hartman * Clearing directly is allowed. 36496fd7ce5SGreg Kroah-Hartman */ 36596fd7ce5SGreg Kroah-Hartman 366d9121566SPeter Hurley static void tty_ldisc_enable(struct tty_struct *tty) 36796fd7ce5SGreg Kroah-Hartman { 36821622939SPeter Hurley clear_bit(TTY_LDISC_HALTED, &tty->flags); 36996fd7ce5SGreg Kroah-Hartman set_bit(TTY_LDISC, &tty->flags); 37096fd7ce5SGreg Kroah-Hartman clear_bit(TTY_LDISC_CHANGING, &tty->flags); 37196fd7ce5SGreg Kroah-Hartman wake_up(&tty_ldisc_wait); 37296fd7ce5SGreg Kroah-Hartman } 37396fd7ce5SGreg Kroah-Hartman 37496fd7ce5SGreg Kroah-Hartman /** 37596fd7ce5SGreg Kroah-Hartman * tty_ldisc_flush - flush line discipline queue 37696fd7ce5SGreg Kroah-Hartman * @tty: tty 37796fd7ce5SGreg Kroah-Hartman * 37896fd7ce5SGreg Kroah-Hartman * Flush the line discipline queue (if any) for this tty. If there 37996fd7ce5SGreg Kroah-Hartman * is no line discipline active this is a no-op. 38096fd7ce5SGreg Kroah-Hartman */ 38196fd7ce5SGreg Kroah-Hartman 38296fd7ce5SGreg Kroah-Hartman void tty_ldisc_flush(struct tty_struct *tty) 38396fd7ce5SGreg Kroah-Hartman { 38496fd7ce5SGreg Kroah-Hartman struct tty_ldisc *ld = tty_ldisc_ref(tty); 38596fd7ce5SGreg Kroah-Hartman if (ld) { 38696fd7ce5SGreg Kroah-Hartman if (ld->ops->flush_buffer) 38796fd7ce5SGreg Kroah-Hartman ld->ops->flush_buffer(tty); 38896fd7ce5SGreg Kroah-Hartman tty_ldisc_deref(ld); 38996fd7ce5SGreg Kroah-Hartman } 39096fd7ce5SGreg Kroah-Hartman tty_buffer_flush(tty); 39196fd7ce5SGreg Kroah-Hartman } 39296fd7ce5SGreg Kroah-Hartman EXPORT_SYMBOL_GPL(tty_ldisc_flush); 39396fd7ce5SGreg Kroah-Hartman 39496fd7ce5SGreg Kroah-Hartman /** 39596fd7ce5SGreg Kroah-Hartman * tty_set_termios_ldisc - set ldisc field 39696fd7ce5SGreg Kroah-Hartman * @tty: tty structure 39796fd7ce5SGreg Kroah-Hartman * @num: line discipline number 39896fd7ce5SGreg Kroah-Hartman * 39996fd7ce5SGreg Kroah-Hartman * This is probably overkill for real world processors but 40096fd7ce5SGreg Kroah-Hartman * they are not on hot paths so a little discipline won't do 40196fd7ce5SGreg Kroah-Hartman * any harm. 40296fd7ce5SGreg Kroah-Hartman * 40396fd7ce5SGreg Kroah-Hartman * Locking: takes termios_mutex 40496fd7ce5SGreg Kroah-Hartman */ 40596fd7ce5SGreg Kroah-Hartman 40696fd7ce5SGreg Kroah-Hartman static void tty_set_termios_ldisc(struct tty_struct *tty, int num) 40796fd7ce5SGreg Kroah-Hartman { 40896fd7ce5SGreg Kroah-Hartman mutex_lock(&tty->termios_mutex); 409adc8d746SAlan Cox tty->termios.c_line = num; 41096fd7ce5SGreg Kroah-Hartman mutex_unlock(&tty->termios_mutex); 41196fd7ce5SGreg Kroah-Hartman } 41296fd7ce5SGreg Kroah-Hartman 41396fd7ce5SGreg Kroah-Hartman /** 41496fd7ce5SGreg Kroah-Hartman * tty_ldisc_open - open a line discipline 41596fd7ce5SGreg Kroah-Hartman * @tty: tty we are opening the ldisc on 41696fd7ce5SGreg Kroah-Hartman * @ld: discipline to open 41796fd7ce5SGreg Kroah-Hartman * 41896fd7ce5SGreg Kroah-Hartman * A helper opening method. Also a convenient debugging and check 41996fd7ce5SGreg Kroah-Hartman * point. 42096fd7ce5SGreg Kroah-Hartman * 42196fd7ce5SGreg Kroah-Hartman * Locking: always called with BTM already held. 42296fd7ce5SGreg Kroah-Hartman */ 42396fd7ce5SGreg Kroah-Hartman 42496fd7ce5SGreg Kroah-Hartman static int tty_ldisc_open(struct tty_struct *tty, struct tty_ldisc *ld) 42596fd7ce5SGreg Kroah-Hartman { 42696fd7ce5SGreg Kroah-Hartman WARN_ON(test_and_set_bit(TTY_LDISC_OPEN, &tty->flags)); 42796fd7ce5SGreg Kroah-Hartman if (ld->ops->open) { 42896fd7ce5SGreg Kroah-Hartman int ret; 42996fd7ce5SGreg Kroah-Hartman /* BTM here locks versus a hangup event */ 43096fd7ce5SGreg Kroah-Hartman ret = ld->ops->open(tty); 4317f90cfc5SJiri Slaby if (ret) 4327f90cfc5SJiri Slaby clear_bit(TTY_LDISC_OPEN, &tty->flags); 43396fd7ce5SGreg Kroah-Hartman return ret; 43496fd7ce5SGreg Kroah-Hartman } 43596fd7ce5SGreg Kroah-Hartman return 0; 43696fd7ce5SGreg Kroah-Hartman } 43796fd7ce5SGreg Kroah-Hartman 43896fd7ce5SGreg Kroah-Hartman /** 43996fd7ce5SGreg Kroah-Hartman * tty_ldisc_close - close a line discipline 44096fd7ce5SGreg Kroah-Hartman * @tty: tty we are opening the ldisc on 44196fd7ce5SGreg Kroah-Hartman * @ld: discipline to close 44296fd7ce5SGreg Kroah-Hartman * 44396fd7ce5SGreg Kroah-Hartman * A helper close method. Also a convenient debugging and check 44496fd7ce5SGreg Kroah-Hartman * point. 44596fd7ce5SGreg Kroah-Hartman */ 44696fd7ce5SGreg Kroah-Hartman 44796fd7ce5SGreg Kroah-Hartman static void tty_ldisc_close(struct tty_struct *tty, struct tty_ldisc *ld) 44896fd7ce5SGreg Kroah-Hartman { 44996fd7ce5SGreg Kroah-Hartman WARN_ON(!test_bit(TTY_LDISC_OPEN, &tty->flags)); 45096fd7ce5SGreg Kroah-Hartman clear_bit(TTY_LDISC_OPEN, &tty->flags); 45196fd7ce5SGreg Kroah-Hartman if (ld->ops->close) 45296fd7ce5SGreg Kroah-Hartman ld->ops->close(tty); 45396fd7ce5SGreg Kroah-Hartman } 45496fd7ce5SGreg Kroah-Hartman 45596fd7ce5SGreg Kroah-Hartman /** 45696fd7ce5SGreg Kroah-Hartman * tty_ldisc_restore - helper for tty ldisc change 45796fd7ce5SGreg Kroah-Hartman * @tty: tty to recover 45896fd7ce5SGreg Kroah-Hartman * @old: previous ldisc 45996fd7ce5SGreg Kroah-Hartman * 46096fd7ce5SGreg Kroah-Hartman * Restore the previous line discipline or N_TTY when a line discipline 46196fd7ce5SGreg Kroah-Hartman * change fails due to an open error 46296fd7ce5SGreg Kroah-Hartman */ 46396fd7ce5SGreg Kroah-Hartman 46496fd7ce5SGreg Kroah-Hartman static void tty_ldisc_restore(struct tty_struct *tty, struct tty_ldisc *old) 46596fd7ce5SGreg Kroah-Hartman { 46696fd7ce5SGreg Kroah-Hartman char buf[64]; 46796fd7ce5SGreg Kroah-Hartman struct tty_ldisc *new_ldisc; 46896fd7ce5SGreg Kroah-Hartman int r; 46996fd7ce5SGreg Kroah-Hartman 47096fd7ce5SGreg Kroah-Hartman /* There is an outstanding reference here so this is safe */ 47196fd7ce5SGreg Kroah-Hartman old = tty_ldisc_get(old->ops->num); 47296fd7ce5SGreg Kroah-Hartman WARN_ON(IS_ERR(old)); 473f4807045SPeter Hurley tty->ldisc = old; 47496fd7ce5SGreg Kroah-Hartman tty_set_termios_ldisc(tty, old->ops->num); 47596fd7ce5SGreg Kroah-Hartman if (tty_ldisc_open(tty, old) < 0) { 47696fd7ce5SGreg Kroah-Hartman tty_ldisc_put(old); 47796fd7ce5SGreg Kroah-Hartman /* This driver is always present */ 47896fd7ce5SGreg Kroah-Hartman new_ldisc = tty_ldisc_get(N_TTY); 47996fd7ce5SGreg Kroah-Hartman if (IS_ERR(new_ldisc)) 48096fd7ce5SGreg Kroah-Hartman panic("n_tty: get"); 481f4807045SPeter Hurley tty->ldisc = new_ldisc; 48296fd7ce5SGreg Kroah-Hartman tty_set_termios_ldisc(tty, N_TTY); 48396fd7ce5SGreg Kroah-Hartman r = tty_ldisc_open(tty, new_ldisc); 48496fd7ce5SGreg Kroah-Hartman if (r < 0) 48596fd7ce5SGreg Kroah-Hartman panic("Couldn't open N_TTY ldisc for " 48696fd7ce5SGreg Kroah-Hartman "%s --- error %d.", 48796fd7ce5SGreg Kroah-Hartman tty_name(tty, buf), r); 48896fd7ce5SGreg Kroah-Hartman } 48996fd7ce5SGreg Kroah-Hartman } 49096fd7ce5SGreg Kroah-Hartman 49196fd7ce5SGreg Kroah-Hartman /** 492100eeae2SJiri Slaby * tty_ldisc_wait_idle - wait for the ldisc to become idle 493100eeae2SJiri Slaby * @tty: tty to wait for 494df92d056SJiri Slaby * @timeout: for how long to wait at most 495100eeae2SJiri Slaby * 496100eeae2SJiri Slaby * Wait for the line discipline to become idle. The discipline must 497100eeae2SJiri Slaby * have been halted for this to guarantee it remains idle. 498100eeae2SJiri Slaby */ 499df92d056SJiri Slaby static int tty_ldisc_wait_idle(struct tty_struct *tty, long timeout) 500100eeae2SJiri Slaby { 501df92d056SJiri Slaby long ret; 5021541f845SIvo Sieben ret = wait_event_timeout(tty->ldisc->wq_idle, 503df92d056SJiri Slaby atomic_read(&tty->ldisc->users) == 1, timeout); 504100eeae2SJiri Slaby return ret > 0 ? 0 : -EBUSY; 505100eeae2SJiri Slaby } 506100eeae2SJiri Slaby 507100eeae2SJiri Slaby /** 50811cf48eaSPeter Hurley * tty_ldisc_halt - shut down the line discipline 50911cf48eaSPeter Hurley * @tty: tty device 510f4cf7a38SPeter Hurley * @o_tty: paired pty device (can be NULL) 511cf528476SPeter Hurley * @timeout: # of jiffies to wait for ldisc refs to be released 51211cf48eaSPeter Hurley * 513f4cf7a38SPeter Hurley * Shut down the line discipline and work queue for this tty device and 514f4cf7a38SPeter Hurley * its paired pty (if exists). Clearing the TTY_LDISC flag ensures 5154f98d467SPeter Hurley * no further references can be obtained, while waiting for existing 5164f98d467SPeter Hurley * references to be released ensures no more data is fed to the ldisc. 517cf528476SPeter Hurley * 51811cf48eaSPeter Hurley * You need to do a 'flush_scheduled_work()' (outside the ldisc_mutex) 51911cf48eaSPeter Hurley * in order to make sure any currently executing ldisc work is also 52011cf48eaSPeter Hurley * flushed. 52111cf48eaSPeter Hurley */ 52211cf48eaSPeter Hurley 523f4cf7a38SPeter Hurley static int tty_ldisc_halt(struct tty_struct *tty, struct tty_struct *o_tty, 5244f98d467SPeter Hurley long timeout) 52511cf48eaSPeter Hurley { 5264f98d467SPeter Hurley int retval; 527cf528476SPeter Hurley 52811cf48eaSPeter Hurley clear_bit(TTY_LDISC, &tty->flags); 529f4cf7a38SPeter Hurley if (o_tty) 530f4cf7a38SPeter Hurley clear_bit(TTY_LDISC, &o_tty->flags); 531f4cf7a38SPeter Hurley 532cf528476SPeter Hurley retval = tty_ldisc_wait_idle(tty, timeout); 533f4cf7a38SPeter Hurley if (!retval && o_tty) 534f4cf7a38SPeter Hurley retval = tty_ldisc_wait_idle(o_tty, timeout); 535cf528476SPeter Hurley if (retval) 536cf528476SPeter Hurley return retval; 537cf528476SPeter Hurley 53811cf48eaSPeter Hurley set_bit(TTY_LDISC_HALTED, &tty->flags); 5394f98d467SPeter Hurley if (o_tty) 540f4cf7a38SPeter Hurley set_bit(TTY_LDISC_HALTED, &o_tty->flags); 541f4cf7a38SPeter Hurley 542cf528476SPeter Hurley return 0; 54311cf48eaSPeter Hurley } 54411cf48eaSPeter Hurley 54511cf48eaSPeter Hurley /** 54676bc35e7SPeter Hurley * tty_ldisc_hangup_halt - halt the line discipline for hangup 54776bc35e7SPeter Hurley * @tty: tty being hung up 548168942c9SPeter Hurley * 54976bc35e7SPeter Hurley * Shut down the line discipline and work queue for the tty device 55076bc35e7SPeter Hurley * being hungup. Clear the TTY_LDISC flag to ensure no further 5514f98d467SPeter Hurley * references can be obtained and wait for remaining references to be 5524f98d467SPeter Hurley * released to ensure no more data is fed to this ldisc. 553168942c9SPeter Hurley * Caller must hold legacy and ->ldisc_mutex. 5542276ad97SPeter Hurley * 5552276ad97SPeter Hurley * NB: tty_set_ldisc() is prevented from changing the ldisc concurrently 5562276ad97SPeter Hurley * with this function by checking the TTY_HUPPING flag. 557168942c9SPeter Hurley */ 55876bc35e7SPeter Hurley static bool tty_ldisc_hangup_halt(struct tty_struct *tty) 559168942c9SPeter Hurley { 560168942c9SPeter Hurley char cur_n[TASK_COMM_LEN], tty_n[64]; 561168942c9SPeter Hurley long timeout = 3 * HZ; 5622276ad97SPeter Hurley 56376bc35e7SPeter Hurley clear_bit(TTY_LDISC, &tty->flags); 56476bc35e7SPeter Hurley 5652276ad97SPeter Hurley if (tty->ldisc) { /* Not yet closed */ 566168942c9SPeter Hurley tty_unlock(tty); 567168942c9SPeter Hurley 568168942c9SPeter Hurley while (tty_ldisc_wait_idle(tty, timeout) == -EBUSY) { 569168942c9SPeter Hurley timeout = MAX_SCHEDULE_TIMEOUT; 570168942c9SPeter Hurley printk_ratelimited(KERN_WARNING 571168942c9SPeter Hurley "%s: waiting (%s) for %s took too long, but we keep waiting...\n", 572168942c9SPeter Hurley __func__, get_task_comm(cur_n, current), 573168942c9SPeter Hurley tty_name(tty, tty_n)); 574168942c9SPeter Hurley } 57576bc35e7SPeter Hurley 57676bc35e7SPeter Hurley set_bit(TTY_LDISC_HALTED, &tty->flags); 57776bc35e7SPeter Hurley 578168942c9SPeter Hurley /* must reacquire both locks and preserve lock order */ 579168942c9SPeter Hurley mutex_unlock(&tty->ldisc_mutex); 580168942c9SPeter Hurley tty_lock(tty); 581168942c9SPeter Hurley mutex_lock(&tty->ldisc_mutex); 582168942c9SPeter Hurley } 583168942c9SPeter Hurley return !!tty->ldisc; 584168942c9SPeter Hurley } 585168942c9SPeter Hurley 586168942c9SPeter Hurley /** 58796fd7ce5SGreg Kroah-Hartman * tty_set_ldisc - set line discipline 58896fd7ce5SGreg Kroah-Hartman * @tty: the terminal to set 58996fd7ce5SGreg Kroah-Hartman * @ldisc: the line discipline 59096fd7ce5SGreg Kroah-Hartman * 59196fd7ce5SGreg Kroah-Hartman * Set the discipline of a tty line. Must be called from a process 59296fd7ce5SGreg Kroah-Hartman * context. The ldisc change logic has to protect itself against any 59396fd7ce5SGreg Kroah-Hartman * overlapping ldisc change (including on the other end of pty pairs), 59496fd7ce5SGreg Kroah-Hartman * the close of one side of a tty/pty pair, and eventually hangup. 59596fd7ce5SGreg Kroah-Hartman * 596137084bbSPeter Hurley * Locking: takes tty_ldiscs_lock, termios_mutex 59796fd7ce5SGreg Kroah-Hartman */ 59896fd7ce5SGreg Kroah-Hartman 59996fd7ce5SGreg Kroah-Hartman int tty_set_ldisc(struct tty_struct *tty, int ldisc) 60096fd7ce5SGreg Kroah-Hartman { 60196fd7ce5SGreg Kroah-Hartman int retval; 60296fd7ce5SGreg Kroah-Hartman struct tty_ldisc *o_ldisc, *new_ldisc; 60396fd7ce5SGreg Kroah-Hartman struct tty_struct *o_tty; 60496fd7ce5SGreg Kroah-Hartman 60596fd7ce5SGreg Kroah-Hartman new_ldisc = tty_ldisc_get(ldisc); 60696fd7ce5SGreg Kroah-Hartman if (IS_ERR(new_ldisc)) 60796fd7ce5SGreg Kroah-Hartman return PTR_ERR(new_ldisc); 60896fd7ce5SGreg Kroah-Hartman 60989c8d91eSAlan Cox tty_lock(tty); 61096fd7ce5SGreg Kroah-Hartman /* 61196fd7ce5SGreg Kroah-Hartman * We need to look at the tty locking here for pty/tty pairs 61296fd7ce5SGreg Kroah-Hartman * when both sides try to change in parallel. 61396fd7ce5SGreg Kroah-Hartman */ 61496fd7ce5SGreg Kroah-Hartman 61596fd7ce5SGreg Kroah-Hartman o_tty = tty->link; /* o_tty is the pty side or NULL */ 61696fd7ce5SGreg Kroah-Hartman 61796fd7ce5SGreg Kroah-Hartman 61896fd7ce5SGreg Kroah-Hartman /* 61996fd7ce5SGreg Kroah-Hartman * Check the no-op case 62096fd7ce5SGreg Kroah-Hartman */ 62196fd7ce5SGreg Kroah-Hartman 62296fd7ce5SGreg Kroah-Hartman if (tty->ldisc->ops->num == ldisc) { 62389c8d91eSAlan Cox tty_unlock(tty); 62496fd7ce5SGreg Kroah-Hartman tty_ldisc_put(new_ldisc); 62596fd7ce5SGreg Kroah-Hartman return 0; 62696fd7ce5SGreg Kroah-Hartman } 62796fd7ce5SGreg Kroah-Hartman 62896fd7ce5SGreg Kroah-Hartman mutex_lock(&tty->ldisc_mutex); 62996fd7ce5SGreg Kroah-Hartman 63096fd7ce5SGreg Kroah-Hartman /* 63196fd7ce5SGreg Kroah-Hartman * We could be midstream of another ldisc change which has 63296fd7ce5SGreg Kroah-Hartman * dropped the lock during processing. If so we need to wait. 63396fd7ce5SGreg Kroah-Hartman */ 63496fd7ce5SGreg Kroah-Hartman 63596fd7ce5SGreg Kroah-Hartman while (test_bit(TTY_LDISC_CHANGING, &tty->flags)) { 63696fd7ce5SGreg Kroah-Hartman mutex_unlock(&tty->ldisc_mutex); 63789c8d91eSAlan Cox tty_unlock(tty); 63896fd7ce5SGreg Kroah-Hartman wait_event(tty_ldisc_wait, 63996fd7ce5SGreg Kroah-Hartman test_bit(TTY_LDISC_CHANGING, &tty->flags) == 0); 64089c8d91eSAlan Cox tty_lock(tty); 64196fd7ce5SGreg Kroah-Hartman mutex_lock(&tty->ldisc_mutex); 64296fd7ce5SGreg Kroah-Hartman } 64396fd7ce5SGreg Kroah-Hartman 64496fd7ce5SGreg Kroah-Hartman set_bit(TTY_LDISC_CHANGING, &tty->flags); 64596fd7ce5SGreg Kroah-Hartman 64696fd7ce5SGreg Kroah-Hartman /* 64796fd7ce5SGreg Kroah-Hartman * No more input please, we are switching. The new ldisc 64896fd7ce5SGreg Kroah-Hartman * will update this value in the ldisc open function 64996fd7ce5SGreg Kroah-Hartman */ 65096fd7ce5SGreg Kroah-Hartman 65196fd7ce5SGreg Kroah-Hartman tty->receive_room = 0; 65296fd7ce5SGreg Kroah-Hartman 65396fd7ce5SGreg Kroah-Hartman o_ldisc = tty->ldisc; 65496fd7ce5SGreg Kroah-Hartman 65589c8d91eSAlan Cox tty_unlock(tty); 65696fd7ce5SGreg Kroah-Hartman /* 65796fd7ce5SGreg Kroah-Hartman * Make sure we don't change while someone holds a 65896fd7ce5SGreg Kroah-Hartman * reference to the line discipline. The TTY_LDISC bit 65996fd7ce5SGreg Kroah-Hartman * prevents anyone taking a reference once it is clear. 66096fd7ce5SGreg Kroah-Hartman * We need the lock to avoid racing reference takers. 66196fd7ce5SGreg Kroah-Hartman * 66296fd7ce5SGreg Kroah-Hartman * We must clear the TTY_LDISC bit here to avoid a livelock 66396fd7ce5SGreg Kroah-Hartman * with a userspace app continually trying to use the tty in 66496fd7ce5SGreg Kroah-Hartman * parallel to the change and re-referencing the tty. 66596fd7ce5SGreg Kroah-Hartman */ 66696fd7ce5SGreg Kroah-Hartman 6674f98d467SPeter Hurley retval = tty_ldisc_halt(tty, o_tty, 5 * HZ); 66896fd7ce5SGreg Kroah-Hartman 66996fd7ce5SGreg Kroah-Hartman /* 670a2965b7bSPeter Hurley * Wait for hangup to complete, if pending. 67196fd7ce5SGreg Kroah-Hartman * We must drop the mutex here in case a hangup is also in process. 67296fd7ce5SGreg Kroah-Hartman */ 67396fd7ce5SGreg Kroah-Hartman 67496fd7ce5SGreg Kroah-Hartman mutex_unlock(&tty->ldisc_mutex); 67596fd7ce5SGreg Kroah-Hartman 676a2965b7bSPeter Hurley flush_work(&tty->hangup_work); 67796fd7ce5SGreg Kroah-Hartman 67889c8d91eSAlan Cox tty_lock(tty); 67996fd7ce5SGreg Kroah-Hartman mutex_lock(&tty->ldisc_mutex); 680100eeae2SJiri Slaby 681100eeae2SJiri Slaby /* handle wait idle failure locked */ 682100eeae2SJiri Slaby if (retval) { 683100eeae2SJiri Slaby tty_ldisc_put(new_ldisc); 684100eeae2SJiri Slaby goto enable; 685100eeae2SJiri Slaby } 686100eeae2SJiri Slaby 68740c9f61eSShachar Shemesh if (test_bit(TTY_HUPPING, &tty->flags)) { 68896fd7ce5SGreg Kroah-Hartman /* We were raced by the hangup method. It will have stomped 68996fd7ce5SGreg Kroah-Hartman the ldisc data and closed the ldisc down */ 69096fd7ce5SGreg Kroah-Hartman clear_bit(TTY_LDISC_CHANGING, &tty->flags); 69196fd7ce5SGreg Kroah-Hartman mutex_unlock(&tty->ldisc_mutex); 69296fd7ce5SGreg Kroah-Hartman tty_ldisc_put(new_ldisc); 69389c8d91eSAlan Cox tty_unlock(tty); 69496fd7ce5SGreg Kroah-Hartman return -EIO; 69596fd7ce5SGreg Kroah-Hartman } 69696fd7ce5SGreg Kroah-Hartman 69796fd7ce5SGreg Kroah-Hartman /* Shutdown the current discipline. */ 69896fd7ce5SGreg Kroah-Hartman tty_ldisc_close(tty, o_ldisc); 69996fd7ce5SGreg Kroah-Hartman 70096fd7ce5SGreg Kroah-Hartman /* Now set up the new line discipline. */ 701f4807045SPeter Hurley tty->ldisc = new_ldisc; 70296fd7ce5SGreg Kroah-Hartman tty_set_termios_ldisc(tty, ldisc); 70396fd7ce5SGreg Kroah-Hartman 70496fd7ce5SGreg Kroah-Hartman retval = tty_ldisc_open(tty, new_ldisc); 70596fd7ce5SGreg Kroah-Hartman if (retval < 0) { 70696fd7ce5SGreg Kroah-Hartman /* Back to the old one or N_TTY if we can't */ 70796fd7ce5SGreg Kroah-Hartman tty_ldisc_put(new_ldisc); 70896fd7ce5SGreg Kroah-Hartman tty_ldisc_restore(tty, o_ldisc); 70996fd7ce5SGreg Kroah-Hartman } 71096fd7ce5SGreg Kroah-Hartman 71196fd7ce5SGreg Kroah-Hartman /* At this point we hold a reference to the new ldisc and a 71296fd7ce5SGreg Kroah-Hartman a reference to the old ldisc. If we ended up flipping back 71396fd7ce5SGreg Kroah-Hartman to the existing ldisc we have two references to it */ 71496fd7ce5SGreg Kroah-Hartman 71596fd7ce5SGreg Kroah-Hartman if (tty->ldisc->ops->num != o_ldisc->ops->num && tty->ops->set_ldisc) 71696fd7ce5SGreg Kroah-Hartman tty->ops->set_ldisc(tty); 71796fd7ce5SGreg Kroah-Hartman 71896fd7ce5SGreg Kroah-Hartman tty_ldisc_put(o_ldisc); 71996fd7ce5SGreg Kroah-Hartman 720100eeae2SJiri Slaby enable: 72196fd7ce5SGreg Kroah-Hartman /* 72296fd7ce5SGreg Kroah-Hartman * Allow ldisc referencing to occur again 72396fd7ce5SGreg Kroah-Hartman */ 72496fd7ce5SGreg Kroah-Hartman 72596fd7ce5SGreg Kroah-Hartman tty_ldisc_enable(tty); 72696fd7ce5SGreg Kroah-Hartman if (o_tty) 72796fd7ce5SGreg Kroah-Hartman tty_ldisc_enable(o_tty); 72896fd7ce5SGreg Kroah-Hartman 72996fd7ce5SGreg Kroah-Hartman /* Restart the work queue in case no characters kick it off. Safe if 73096fd7ce5SGreg Kroah-Hartman already running */ 731ecbbfd44SJiri Slaby schedule_work(&tty->port->buf.work); 7324f98d467SPeter Hurley if (o_tty) 733ecbbfd44SJiri Slaby schedule_work(&o_tty->port->buf.work); 7344f98d467SPeter Hurley 73596fd7ce5SGreg Kroah-Hartman mutex_unlock(&tty->ldisc_mutex); 73689c8d91eSAlan Cox tty_unlock(tty); 73796fd7ce5SGreg Kroah-Hartman return retval; 73896fd7ce5SGreg Kroah-Hartman } 73996fd7ce5SGreg Kroah-Hartman 74096fd7ce5SGreg Kroah-Hartman /** 74196fd7ce5SGreg Kroah-Hartman * tty_reset_termios - reset terminal state 74296fd7ce5SGreg Kroah-Hartman * @tty: tty to reset 74396fd7ce5SGreg Kroah-Hartman * 74496fd7ce5SGreg Kroah-Hartman * Restore a terminal to the driver default state. 74596fd7ce5SGreg Kroah-Hartman */ 74696fd7ce5SGreg Kroah-Hartman 74796fd7ce5SGreg Kroah-Hartman static void tty_reset_termios(struct tty_struct *tty) 74896fd7ce5SGreg Kroah-Hartman { 74996fd7ce5SGreg Kroah-Hartman mutex_lock(&tty->termios_mutex); 750adc8d746SAlan Cox tty->termios = tty->driver->init_termios; 751adc8d746SAlan Cox tty->termios.c_ispeed = tty_termios_input_baud_rate(&tty->termios); 752adc8d746SAlan Cox tty->termios.c_ospeed = tty_termios_baud_rate(&tty->termios); 75396fd7ce5SGreg Kroah-Hartman mutex_unlock(&tty->termios_mutex); 75496fd7ce5SGreg Kroah-Hartman } 75596fd7ce5SGreg Kroah-Hartman 75696fd7ce5SGreg Kroah-Hartman 75796fd7ce5SGreg Kroah-Hartman /** 75896fd7ce5SGreg Kroah-Hartman * tty_ldisc_reinit - reinitialise the tty ldisc 75996fd7ce5SGreg Kroah-Hartman * @tty: tty to reinit 76096fd7ce5SGreg Kroah-Hartman * @ldisc: line discipline to reinitialize 76196fd7ce5SGreg Kroah-Hartman * 76296fd7ce5SGreg Kroah-Hartman * Switch the tty to a line discipline and leave the ldisc 76396fd7ce5SGreg Kroah-Hartman * state closed 76496fd7ce5SGreg Kroah-Hartman */ 76596fd7ce5SGreg Kroah-Hartman 7661c95ba1eSPhilippe Rétornaz static int tty_ldisc_reinit(struct tty_struct *tty, int ldisc) 76796fd7ce5SGreg Kroah-Hartman { 7681c95ba1eSPhilippe Rétornaz struct tty_ldisc *ld = tty_ldisc_get(ldisc); 7691c95ba1eSPhilippe Rétornaz 7701c95ba1eSPhilippe Rétornaz if (IS_ERR(ld)) 7711c95ba1eSPhilippe Rétornaz return -1; 77296fd7ce5SGreg Kroah-Hartman 77396fd7ce5SGreg Kroah-Hartman tty_ldisc_close(tty, tty->ldisc); 77496fd7ce5SGreg Kroah-Hartman tty_ldisc_put(tty->ldisc); 77596fd7ce5SGreg Kroah-Hartman /* 77696fd7ce5SGreg Kroah-Hartman * Switch the line discipline back 77796fd7ce5SGreg Kroah-Hartman */ 778f4807045SPeter Hurley tty->ldisc = ld; 77996fd7ce5SGreg Kroah-Hartman tty_set_termios_ldisc(tty, ldisc); 7801c95ba1eSPhilippe Rétornaz 7811c95ba1eSPhilippe Rétornaz return 0; 78296fd7ce5SGreg Kroah-Hartman } 78396fd7ce5SGreg Kroah-Hartman 78496fd7ce5SGreg Kroah-Hartman /** 78596fd7ce5SGreg Kroah-Hartman * tty_ldisc_hangup - hangup ldisc reset 78696fd7ce5SGreg Kroah-Hartman * @tty: tty being hung up 78796fd7ce5SGreg Kroah-Hartman * 78896fd7ce5SGreg Kroah-Hartman * Some tty devices reset their termios when they receive a hangup 78996fd7ce5SGreg Kroah-Hartman * event. In that situation we must also switch back to N_TTY properly 79096fd7ce5SGreg Kroah-Hartman * before we reset the termios data. 79196fd7ce5SGreg Kroah-Hartman * 79296fd7ce5SGreg Kroah-Hartman * Locking: We can take the ldisc mutex as the rest of the code is 79396fd7ce5SGreg Kroah-Hartman * careful to allow for this. 79496fd7ce5SGreg Kroah-Hartman * 79596fd7ce5SGreg Kroah-Hartman * In the pty pair case this occurs in the close() path of the 79696fd7ce5SGreg Kroah-Hartman * tty itself so we must be careful about locking rules. 79796fd7ce5SGreg Kroah-Hartman */ 79896fd7ce5SGreg Kroah-Hartman 79996fd7ce5SGreg Kroah-Hartman void tty_ldisc_hangup(struct tty_struct *tty) 80096fd7ce5SGreg Kroah-Hartman { 80196fd7ce5SGreg Kroah-Hartman struct tty_ldisc *ld; 80296fd7ce5SGreg Kroah-Hartman int reset = tty->driver->flags & TTY_DRIVER_RESET_TERMIOS; 80396fd7ce5SGreg Kroah-Hartman int err = 0; 80496fd7ce5SGreg Kroah-Hartman 805fc575ee6SPeter Hurley tty_ldisc_debug(tty, "closing ldisc: %p\n", tty->ldisc); 806fc575ee6SPeter Hurley 80796fd7ce5SGreg Kroah-Hartman /* 80896fd7ce5SGreg Kroah-Hartman * FIXME! What are the locking issues here? This may me overdoing 80996fd7ce5SGreg Kroah-Hartman * things... This question is especially important now that we've 81096fd7ce5SGreg Kroah-Hartman * removed the irqlock. 81196fd7ce5SGreg Kroah-Hartman */ 81296fd7ce5SGreg Kroah-Hartman ld = tty_ldisc_ref(tty); 81396fd7ce5SGreg Kroah-Hartman if (ld != NULL) { 81496fd7ce5SGreg Kroah-Hartman /* We may have no line discipline at this point */ 81596fd7ce5SGreg Kroah-Hartman if (ld->ops->flush_buffer) 81696fd7ce5SGreg Kroah-Hartman ld->ops->flush_buffer(tty); 81796fd7ce5SGreg Kroah-Hartman tty_driver_flush_buffer(tty); 81896fd7ce5SGreg Kroah-Hartman if ((test_bit(TTY_DO_WRITE_WAKEUP, &tty->flags)) && 81996fd7ce5SGreg Kroah-Hartman ld->ops->write_wakeup) 82096fd7ce5SGreg Kroah-Hartman ld->ops->write_wakeup(tty); 82196fd7ce5SGreg Kroah-Hartman if (ld->ops->hangup) 82296fd7ce5SGreg Kroah-Hartman ld->ops->hangup(tty); 82396fd7ce5SGreg Kroah-Hartman tty_ldisc_deref(ld); 82496fd7ce5SGreg Kroah-Hartman } 82596fd7ce5SGreg Kroah-Hartman /* 82696fd7ce5SGreg Kroah-Hartman * FIXME: Once we trust the LDISC code better we can wait here for 82796fd7ce5SGreg Kroah-Hartman * ldisc completion and fix the driver call race 82896fd7ce5SGreg Kroah-Hartman */ 82996fd7ce5SGreg Kroah-Hartman wake_up_interruptible_poll(&tty->write_wait, POLLOUT); 83096fd7ce5SGreg Kroah-Hartman wake_up_interruptible_poll(&tty->read_wait, POLLIN); 83196fd7ce5SGreg Kroah-Hartman /* 83296fd7ce5SGreg Kroah-Hartman * Shutdown the current line discipline, and reset it to 83396fd7ce5SGreg Kroah-Hartman * N_TTY if need be. 83496fd7ce5SGreg Kroah-Hartman * 83596fd7ce5SGreg Kroah-Hartman * Avoid racing set_ldisc or tty_ldisc_release 83696fd7ce5SGreg Kroah-Hartman */ 83796fd7ce5SGreg Kroah-Hartman mutex_lock(&tty->ldisc_mutex); 83896fd7ce5SGreg Kroah-Hartman 83976bc35e7SPeter Hurley if (tty_ldisc_hangup_halt(tty)) { 840c8785241SPeter Hurley 841c8785241SPeter Hurley /* At this point we have a halted ldisc; we want to close it and 842c8785241SPeter Hurley reopen a new ldisc. We could defer the reopen to the next 843c8785241SPeter Hurley open but it means auditing a lot of other paths so this is 844c8785241SPeter Hurley a FIXME */ 84596fd7ce5SGreg Kroah-Hartman if (reset == 0) { 8461c95ba1eSPhilippe Rétornaz 847adc8d746SAlan Cox if (!tty_ldisc_reinit(tty, tty->termios.c_line)) 84896fd7ce5SGreg Kroah-Hartman err = tty_ldisc_open(tty, tty->ldisc); 8491c95ba1eSPhilippe Rétornaz else 8501c95ba1eSPhilippe Rétornaz err = 1; 85196fd7ce5SGreg Kroah-Hartman } 85296fd7ce5SGreg Kroah-Hartman /* If the re-open fails or we reset then go to N_TTY. The 85396fd7ce5SGreg Kroah-Hartman N_TTY open cannot fail */ 85496fd7ce5SGreg Kroah-Hartman if (reset || err) { 8551c95ba1eSPhilippe Rétornaz BUG_ON(tty_ldisc_reinit(tty, N_TTY)); 85696fd7ce5SGreg Kroah-Hartman WARN_ON(tty_ldisc_open(tty, tty->ldisc)); 85796fd7ce5SGreg Kroah-Hartman } 85896fd7ce5SGreg Kroah-Hartman tty_ldisc_enable(tty); 85996fd7ce5SGreg Kroah-Hartman } 86096fd7ce5SGreg Kroah-Hartman mutex_unlock(&tty->ldisc_mutex); 86196fd7ce5SGreg Kroah-Hartman if (reset) 86296fd7ce5SGreg Kroah-Hartman tty_reset_termios(tty); 863fc575ee6SPeter Hurley 864fc575ee6SPeter Hurley tty_ldisc_debug(tty, "re-opened ldisc: %p\n", tty->ldisc); 86596fd7ce5SGreg Kroah-Hartman } 86696fd7ce5SGreg Kroah-Hartman 86796fd7ce5SGreg Kroah-Hartman /** 86896fd7ce5SGreg Kroah-Hartman * tty_ldisc_setup - open line discipline 86996fd7ce5SGreg Kroah-Hartman * @tty: tty being shut down 87096fd7ce5SGreg Kroah-Hartman * @o_tty: pair tty for pty/tty pairs 87196fd7ce5SGreg Kroah-Hartman * 87296fd7ce5SGreg Kroah-Hartman * Called during the initial open of a tty/pty pair in order to set up the 87396fd7ce5SGreg Kroah-Hartman * line disciplines and bind them to the tty. This has no locking issues 87496fd7ce5SGreg Kroah-Hartman * as the device isn't yet active. 87596fd7ce5SGreg Kroah-Hartman */ 87696fd7ce5SGreg Kroah-Hartman 87796fd7ce5SGreg Kroah-Hartman int tty_ldisc_setup(struct tty_struct *tty, struct tty_struct *o_tty) 87896fd7ce5SGreg Kroah-Hartman { 87996fd7ce5SGreg Kroah-Hartman struct tty_ldisc *ld = tty->ldisc; 88096fd7ce5SGreg Kroah-Hartman int retval; 88196fd7ce5SGreg Kroah-Hartman 88296fd7ce5SGreg Kroah-Hartman retval = tty_ldisc_open(tty, ld); 88396fd7ce5SGreg Kroah-Hartman if (retval) 88496fd7ce5SGreg Kroah-Hartman return retval; 88596fd7ce5SGreg Kroah-Hartman 88696fd7ce5SGreg Kroah-Hartman if (o_tty) { 88796fd7ce5SGreg Kroah-Hartman retval = tty_ldisc_open(o_tty, o_tty->ldisc); 88896fd7ce5SGreg Kroah-Hartman if (retval) { 88996fd7ce5SGreg Kroah-Hartman tty_ldisc_close(tty, ld); 89096fd7ce5SGreg Kroah-Hartman return retval; 89196fd7ce5SGreg Kroah-Hartman } 89296fd7ce5SGreg Kroah-Hartman tty_ldisc_enable(o_tty); 89396fd7ce5SGreg Kroah-Hartman } 89496fd7ce5SGreg Kroah-Hartman tty_ldisc_enable(tty); 89596fd7ce5SGreg Kroah-Hartman return 0; 89696fd7ce5SGreg Kroah-Hartman } 89789c8d91eSAlan Cox 89889c8d91eSAlan Cox static void tty_ldisc_kill(struct tty_struct *tty) 89989c8d91eSAlan Cox { 90089c8d91eSAlan Cox mutex_lock(&tty->ldisc_mutex); 90189c8d91eSAlan Cox /* 90289c8d91eSAlan Cox * Now kill off the ldisc 90389c8d91eSAlan Cox */ 90489c8d91eSAlan Cox tty_ldisc_close(tty, tty->ldisc); 90589c8d91eSAlan Cox tty_ldisc_put(tty->ldisc); 90689c8d91eSAlan Cox /* Force an oops if we mess this up */ 90789c8d91eSAlan Cox tty->ldisc = NULL; 90889c8d91eSAlan Cox 90989c8d91eSAlan Cox /* Ensure the next open requests the N_TTY ldisc */ 91089c8d91eSAlan Cox tty_set_termios_ldisc(tty, N_TTY); 91189c8d91eSAlan Cox mutex_unlock(&tty->ldisc_mutex); 91289c8d91eSAlan Cox } 91389c8d91eSAlan Cox 91496fd7ce5SGreg Kroah-Hartman /** 91596fd7ce5SGreg Kroah-Hartman * tty_ldisc_release - release line discipline 91696fd7ce5SGreg Kroah-Hartman * @tty: tty being shut down 91796fd7ce5SGreg Kroah-Hartman * @o_tty: pair tty for pty/tty pairs 91896fd7ce5SGreg Kroah-Hartman * 91996fd7ce5SGreg Kroah-Hartman * Called during the final close of a tty/pty pair in order to shut down 92096fd7ce5SGreg Kroah-Hartman * the line discpline layer. On exit the ldisc assigned is N_TTY and the 92196fd7ce5SGreg Kroah-Hartman * ldisc has not been opened. 92296fd7ce5SGreg Kroah-Hartman */ 92396fd7ce5SGreg Kroah-Hartman 92496fd7ce5SGreg Kroah-Hartman void tty_ldisc_release(struct tty_struct *tty, struct tty_struct *o_tty) 92596fd7ce5SGreg Kroah-Hartman { 92696fd7ce5SGreg Kroah-Hartman /* 927a2965b7bSPeter Hurley * Shutdown this line discipline. As this is the final close, 928a2965b7bSPeter Hurley * it does not race with the set_ldisc code path. 92996fd7ce5SGreg Kroah-Hartman */ 93096fd7ce5SGreg Kroah-Hartman 931fc575ee6SPeter Hurley tty_ldisc_debug(tty, "closing ldisc: %p\n", tty->ldisc); 932fc575ee6SPeter Hurley 9334f98d467SPeter Hurley tty_ldisc_halt(tty, o_tty, MAX_SCHEDULE_TIMEOUT); 934852e4a81SSebastian Andrzej Siewior 935852e4a81SSebastian Andrzej Siewior tty_lock_pair(tty, o_tty); 9366d31a88cSAlan Cox /* This will need doing differently if we need to lock */ 93789c8d91eSAlan Cox tty_ldisc_kill(tty); 93889c8d91eSAlan Cox if (o_tty) 93989c8d91eSAlan Cox tty_ldisc_kill(o_tty); 94089c8d91eSAlan Cox 94189c8d91eSAlan Cox tty_unlock_pair(tty, o_tty); 94296fd7ce5SGreg Kroah-Hartman /* And the memory resources remaining (buffers, termios) will be 94396fd7ce5SGreg Kroah-Hartman disposed of when the kref hits zero */ 944fc575ee6SPeter Hurley 945fc575ee6SPeter Hurley tty_ldisc_debug(tty, "ldisc closed\n"); 94696fd7ce5SGreg Kroah-Hartman } 94796fd7ce5SGreg Kroah-Hartman 94896fd7ce5SGreg Kroah-Hartman /** 94996fd7ce5SGreg Kroah-Hartman * tty_ldisc_init - ldisc setup for new tty 95096fd7ce5SGreg Kroah-Hartman * @tty: tty being allocated 95196fd7ce5SGreg Kroah-Hartman * 95296fd7ce5SGreg Kroah-Hartman * Set up the line discipline objects for a newly allocated tty. Note that 95396fd7ce5SGreg Kroah-Hartman * the tty structure is not completely set up when this call is made. 95496fd7ce5SGreg Kroah-Hartman */ 95596fd7ce5SGreg Kroah-Hartman 95696fd7ce5SGreg Kroah-Hartman void tty_ldisc_init(struct tty_struct *tty) 95796fd7ce5SGreg Kroah-Hartman { 95896fd7ce5SGreg Kroah-Hartman struct tty_ldisc *ld = tty_ldisc_get(N_TTY); 95996fd7ce5SGreg Kroah-Hartman if (IS_ERR(ld)) 96096fd7ce5SGreg Kroah-Hartman panic("n_tty: init_tty"); 961f4807045SPeter Hurley tty->ldisc = ld; 96296fd7ce5SGreg Kroah-Hartman } 96396fd7ce5SGreg Kroah-Hartman 9646716671dSJiri Slaby /** 9656716671dSJiri Slaby * tty_ldisc_init - ldisc cleanup for new tty 9666716671dSJiri Slaby * @tty: tty that was allocated recently 9676716671dSJiri Slaby * 9686716671dSJiri Slaby * The tty structure must not becompletely set up (tty_ldisc_setup) when 9696716671dSJiri Slaby * this call is made. 9706716671dSJiri Slaby */ 9716716671dSJiri Slaby void tty_ldisc_deinit(struct tty_struct *tty) 9726716671dSJiri Slaby { 973ebc9baedSPeter Hurley tty_ldisc_put(tty->ldisc); 974f4807045SPeter Hurley tty->ldisc = NULL; 9756716671dSJiri Slaby } 9766716671dSJiri Slaby 97796fd7ce5SGreg Kroah-Hartman void tty_ldisc_begin(void) 97896fd7ce5SGreg Kroah-Hartman { 97996fd7ce5SGreg Kroah-Hartman /* Setup the default TTY line discipline. */ 98096fd7ce5SGreg Kroah-Hartman (void) tty_register_ldisc(N_TTY, &tty_ldisc_N_TTY); 98196fd7ce5SGreg Kroah-Hartman } 982