spi: Fix documentation of spi_alloc_master()
[linux-2.6/btrfs-unstable.git] / drivers / tty / tty_ldisc.c
blobc07fb5d9bcf9b5429689a908417021fb5716e8f9
1 #include <linux/types.h>
2 #include <linux/errno.h>
3 #include <linux/kmod.h>
4 #include <linux/sched.h>
5 #include <linux/interrupt.h>
6 #include <linux/tty.h>
7 #include <linux/tty_driver.h>
8 #include <linux/file.h>
9 #include <linux/mm.h>
10 #include <linux/string.h>
11 #include <linux/slab.h>
12 #include <linux/poll.h>
13 #include <linux/proc_fs.h>
14 #include <linux/module.h>
15 #include <linux/device.h>
16 #include <linux/wait.h>
17 #include <linux/bitops.h>
18 #include <linux/seq_file.h>
19 #include <linux/uaccess.h>
20 #include <linux/ratelimit.h>
22 #undef LDISC_DEBUG_HANGUP
24 #ifdef LDISC_DEBUG_HANGUP
25 #define tty_ldisc_debug(tty, f, args...) ({ \
26 printk(KERN_DEBUG "%s: %s: " f, __func__, tty_name(tty), ##args); \
28 #else
29 #define tty_ldisc_debug(tty, f, args...)
30 #endif
32 /* lockdep nested classes for tty->ldisc_sem */
33 enum {
34 LDISC_SEM_NORMAL,
35 LDISC_SEM_OTHER,
40 * This guards the refcounted line discipline lists. The lock
41 * must be taken with irqs off because there are hangup path
42 * callers who will do ldisc lookups and cannot sleep.
45 static DEFINE_RAW_SPINLOCK(tty_ldiscs_lock);
46 /* Line disc dispatch table */
47 static struct tty_ldisc_ops *tty_ldiscs[NR_LDISCS];
49 /**
50 * tty_register_ldisc - install a line discipline
51 * @disc: ldisc number
52 * @new_ldisc: pointer to the ldisc object
54 * Installs a new line discipline into the kernel. The discipline
55 * is set up as unreferenced and then made available to the kernel
56 * from this point onwards.
58 * Locking:
59 * takes tty_ldiscs_lock to guard against ldisc races
62 int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
64 unsigned long flags;
65 int ret = 0;
67 if (disc < N_TTY || disc >= NR_LDISCS)
68 return -EINVAL;
70 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
71 tty_ldiscs[disc] = new_ldisc;
72 new_ldisc->num = disc;
73 new_ldisc->refcount = 0;
74 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
76 return ret;
78 EXPORT_SYMBOL(tty_register_ldisc);
80 /**
81 * tty_unregister_ldisc - unload a line discipline
82 * @disc: ldisc number
83 * @new_ldisc: pointer to the ldisc object
85 * Remove a line discipline from the kernel providing it is not
86 * currently in use.
88 * Locking:
89 * takes tty_ldiscs_lock to guard against ldisc races
92 int tty_unregister_ldisc(int disc)
94 unsigned long flags;
95 int ret = 0;
97 if (disc < N_TTY || disc >= NR_LDISCS)
98 return -EINVAL;
100 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
101 if (tty_ldiscs[disc]->refcount)
102 ret = -EBUSY;
103 else
104 tty_ldiscs[disc] = NULL;
105 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
107 return ret;
109 EXPORT_SYMBOL(tty_unregister_ldisc);
111 static struct tty_ldisc_ops *get_ldops(int disc)
113 unsigned long flags;
114 struct tty_ldisc_ops *ldops, *ret;
116 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
117 ret = ERR_PTR(-EINVAL);
118 ldops = tty_ldiscs[disc];
119 if (ldops) {
120 ret = ERR_PTR(-EAGAIN);
121 if (try_module_get(ldops->owner)) {
122 ldops->refcount++;
123 ret = ldops;
126 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
127 return ret;
130 static void put_ldops(struct tty_ldisc_ops *ldops)
132 unsigned long flags;
134 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
135 ldops->refcount--;
136 module_put(ldops->owner);
137 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
141 * tty_ldisc_get - take a reference to an ldisc
142 * @disc: ldisc number
144 * Takes a reference to a line discipline. Deals with refcounts and
145 * module locking counts. Returns NULL if the discipline is not available.
146 * Returns a pointer to the discipline and bumps the ref count if it is
147 * available
149 * Locking:
150 * takes tty_ldiscs_lock to guard against ldisc races
153 static struct tty_ldisc *tty_ldisc_get(struct tty_struct *tty, int disc)
155 struct tty_ldisc *ld;
156 struct tty_ldisc_ops *ldops;
158 if (disc < N_TTY || disc >= NR_LDISCS)
159 return ERR_PTR(-EINVAL);
162 * Get the ldisc ops - we may need to request them to be loaded
163 * dynamically and try again.
165 ldops = get_ldops(disc);
166 if (IS_ERR(ldops)) {
167 request_module("tty-ldisc-%d", disc);
168 ldops = get_ldops(disc);
169 if (IS_ERR(ldops))
170 return ERR_CAST(ldops);
173 ld = kmalloc(sizeof(struct tty_ldisc), GFP_KERNEL);
174 if (ld == NULL) {
175 put_ldops(ldops);
176 return ERR_PTR(-ENOMEM);
179 ld->ops = ldops;
180 ld->tty = tty;
182 return ld;
186 * tty_ldisc_put - release the ldisc
188 * Complement of tty_ldisc_get().
190 static inline void tty_ldisc_put(struct tty_ldisc *ld)
192 if (WARN_ON_ONCE(!ld))
193 return;
195 put_ldops(ld->ops);
196 kfree(ld);
199 static void *tty_ldiscs_seq_start(struct seq_file *m, loff_t *pos)
201 return (*pos < NR_LDISCS) ? pos : NULL;
204 static void *tty_ldiscs_seq_next(struct seq_file *m, void *v, loff_t *pos)
206 (*pos)++;
207 return (*pos < NR_LDISCS) ? pos : NULL;
210 static void tty_ldiscs_seq_stop(struct seq_file *m, void *v)
214 static int tty_ldiscs_seq_show(struct seq_file *m, void *v)
216 int i = *(loff_t *)v;
217 struct tty_ldisc_ops *ldops;
219 ldops = get_ldops(i);
220 if (IS_ERR(ldops))
221 return 0;
222 seq_printf(m, "%-10s %2d\n", ldops->name ? ldops->name : "???", i);
223 put_ldops(ldops);
224 return 0;
227 static const struct seq_operations tty_ldiscs_seq_ops = {
228 .start = tty_ldiscs_seq_start,
229 .next = tty_ldiscs_seq_next,
230 .stop = tty_ldiscs_seq_stop,
231 .show = tty_ldiscs_seq_show,
234 static int proc_tty_ldiscs_open(struct inode *inode, struct file *file)
236 return seq_open(file, &tty_ldiscs_seq_ops);
239 const struct file_operations tty_ldiscs_proc_fops = {
240 .owner = THIS_MODULE,
241 .open = proc_tty_ldiscs_open,
242 .read = seq_read,
243 .llseek = seq_lseek,
244 .release = seq_release,
248 * tty_ldisc_ref_wait - wait for the tty ldisc
249 * @tty: tty device
251 * Dereference the line discipline for the terminal and take a
252 * reference to it. If the line discipline is in flux then
253 * wait patiently until it changes.
255 * Note: Must not be called from an IRQ/timer context. The caller
256 * must also be careful not to hold other locks that will deadlock
257 * against a discipline change, such as an existing ldisc reference
258 * (which we check for)
260 * Note: only callable from a file_operations routine (which
261 * guarantees tty->ldisc != NULL when the lock is acquired).
264 struct tty_ldisc *tty_ldisc_ref_wait(struct tty_struct *tty)
266 ldsem_down_read(&tty->ldisc_sem, MAX_SCHEDULE_TIMEOUT);
267 WARN_ON(!tty->ldisc);
268 return tty->ldisc;
270 EXPORT_SYMBOL_GPL(tty_ldisc_ref_wait);
273 * tty_ldisc_ref - get the tty ldisc
274 * @tty: tty device
276 * Dereference the line discipline for the terminal and take a
277 * reference to it. If the line discipline is in flux then
278 * return NULL. Can be called from IRQ and timer functions.
281 struct tty_ldisc *tty_ldisc_ref(struct tty_struct *tty)
283 struct tty_ldisc *ld = NULL;
285 if (ldsem_down_read_trylock(&tty->ldisc_sem)) {
286 ld = tty->ldisc;
287 if (!ld)
288 ldsem_up_read(&tty->ldisc_sem);
290 return ld;
292 EXPORT_SYMBOL_GPL(tty_ldisc_ref);
295 * tty_ldisc_deref - free a tty ldisc reference
296 * @ld: reference to free up
298 * Undoes the effect of tty_ldisc_ref or tty_ldisc_ref_wait. May
299 * be called in IRQ context.
302 void tty_ldisc_deref(struct tty_ldisc *ld)
304 ldsem_up_read(&ld->tty->ldisc_sem);
306 EXPORT_SYMBOL_GPL(tty_ldisc_deref);
309 static inline int __lockfunc
310 __tty_ldisc_lock(struct tty_struct *tty, unsigned long timeout)
312 return ldsem_down_write(&tty->ldisc_sem, timeout);
315 static inline int __lockfunc
316 __tty_ldisc_lock_nested(struct tty_struct *tty, unsigned long timeout)
318 return ldsem_down_write_nested(&tty->ldisc_sem,
319 LDISC_SEM_OTHER, timeout);
322 static inline void __tty_ldisc_unlock(struct tty_struct *tty)
324 return ldsem_up_write(&tty->ldisc_sem);
327 static int __lockfunc
328 tty_ldisc_lock(struct tty_struct *tty, unsigned long timeout)
330 int ret;
332 ret = __tty_ldisc_lock(tty, timeout);
333 if (!ret)
334 return -EBUSY;
335 set_bit(TTY_LDISC_HALTED, &tty->flags);
336 return 0;
339 static void tty_ldisc_unlock(struct tty_struct *tty)
341 clear_bit(TTY_LDISC_HALTED, &tty->flags);
342 __tty_ldisc_unlock(tty);
345 static int __lockfunc
346 tty_ldisc_lock_pair_timeout(struct tty_struct *tty, struct tty_struct *tty2,
347 unsigned long timeout)
349 int ret;
351 if (tty < tty2) {
352 ret = __tty_ldisc_lock(tty, timeout);
353 if (ret) {
354 ret = __tty_ldisc_lock_nested(tty2, timeout);
355 if (!ret)
356 __tty_ldisc_unlock(tty);
358 } else {
359 /* if this is possible, it has lots of implications */
360 WARN_ON_ONCE(tty == tty2);
361 if (tty2 && tty != tty2) {
362 ret = __tty_ldisc_lock(tty2, timeout);
363 if (ret) {
364 ret = __tty_ldisc_lock_nested(tty, timeout);
365 if (!ret)
366 __tty_ldisc_unlock(tty2);
368 } else
369 ret = __tty_ldisc_lock(tty, timeout);
372 if (!ret)
373 return -EBUSY;
375 set_bit(TTY_LDISC_HALTED, &tty->flags);
376 if (tty2)
377 set_bit(TTY_LDISC_HALTED, &tty2->flags);
378 return 0;
381 static void __lockfunc
382 tty_ldisc_lock_pair(struct tty_struct *tty, struct tty_struct *tty2)
384 tty_ldisc_lock_pair_timeout(tty, tty2, MAX_SCHEDULE_TIMEOUT);
387 static void __lockfunc tty_ldisc_unlock_pair(struct tty_struct *tty,
388 struct tty_struct *tty2)
390 __tty_ldisc_unlock(tty);
391 if (tty2)
392 __tty_ldisc_unlock(tty2);
396 * tty_ldisc_flush - flush line discipline queue
397 * @tty: tty
399 * Flush the line discipline queue (if any) and the tty flip buffers
400 * for this tty.
403 void tty_ldisc_flush(struct tty_struct *tty)
405 struct tty_ldisc *ld = tty_ldisc_ref(tty);
407 tty_buffer_flush(tty, ld);
408 if (ld)
409 tty_ldisc_deref(ld);
411 EXPORT_SYMBOL_GPL(tty_ldisc_flush);
414 * tty_set_termios_ldisc - set ldisc field
415 * @tty: tty structure
416 * @num: line discipline number
418 * This is probably overkill for real world processors but
419 * they are not on hot paths so a little discipline won't do
420 * any harm.
422 * Locking: takes termios_rwsem
425 static void tty_set_termios_ldisc(struct tty_struct *tty, int num)
427 down_write(&tty->termios_rwsem);
428 tty->termios.c_line = num;
429 up_write(&tty->termios_rwsem);
433 * tty_ldisc_open - open a line discipline
434 * @tty: tty we are opening the ldisc on
435 * @ld: discipline to open
437 * A helper opening method. Also a convenient debugging and check
438 * point.
440 * Locking: always called with BTM already held.
443 static int tty_ldisc_open(struct tty_struct *tty, struct tty_ldisc *ld)
445 WARN_ON(test_and_set_bit(TTY_LDISC_OPEN, &tty->flags));
446 if (ld->ops->open) {
447 int ret;
448 /* BTM here locks versus a hangup event */
449 ret = ld->ops->open(tty);
450 if (ret)
451 clear_bit(TTY_LDISC_OPEN, &tty->flags);
452 return ret;
454 return 0;
458 * tty_ldisc_close - close a line discipline
459 * @tty: tty we are opening the ldisc on
460 * @ld: discipline to close
462 * A helper close method. Also a convenient debugging and check
463 * point.
466 static void tty_ldisc_close(struct tty_struct *tty, struct tty_ldisc *ld)
468 WARN_ON(!test_bit(TTY_LDISC_OPEN, &tty->flags));
469 clear_bit(TTY_LDISC_OPEN, &tty->flags);
470 if (ld->ops->close)
471 ld->ops->close(tty);
475 * tty_ldisc_restore - helper for tty ldisc change
476 * @tty: tty to recover
477 * @old: previous ldisc
479 * Restore the previous line discipline or N_TTY when a line discipline
480 * change fails due to an open error
483 static void tty_ldisc_restore(struct tty_struct *tty, struct tty_ldisc *old)
485 struct tty_ldisc *new_ldisc;
486 int r;
488 /* There is an outstanding reference here so this is safe */
489 old = tty_ldisc_get(tty, old->ops->num);
490 WARN_ON(IS_ERR(old));
491 tty->ldisc = old;
492 tty_set_termios_ldisc(tty, old->ops->num);
493 if (tty_ldisc_open(tty, old) < 0) {
494 tty_ldisc_put(old);
495 /* This driver is always present */
496 new_ldisc = tty_ldisc_get(tty, N_TTY);
497 if (IS_ERR(new_ldisc))
498 panic("n_tty: get");
499 tty->ldisc = new_ldisc;
500 tty_set_termios_ldisc(tty, N_TTY);
501 r = tty_ldisc_open(tty, new_ldisc);
502 if (r < 0)
503 panic("Couldn't open N_TTY ldisc for "
504 "%s --- error %d.",
505 tty_name(tty), r);
510 * tty_set_ldisc - set line discipline
511 * @tty: the terminal to set
512 * @ldisc: the line discipline
514 * Set the discipline of a tty line. Must be called from a process
515 * context. The ldisc change logic has to protect itself against any
516 * overlapping ldisc change (including on the other end of pty pairs),
517 * the close of one side of a tty/pty pair, and eventually hangup.
520 int tty_set_ldisc(struct tty_struct *tty, int ldisc)
522 int retval;
523 struct tty_ldisc *old_ldisc, *new_ldisc;
525 new_ldisc = tty_ldisc_get(tty, ldisc);
526 if (IS_ERR(new_ldisc))
527 return PTR_ERR(new_ldisc);
529 tty_lock(tty);
530 retval = tty_ldisc_lock(tty, 5 * HZ);
531 if (retval) {
532 tty_ldisc_put(new_ldisc);
533 tty_unlock(tty);
534 return retval;
538 * Check the no-op case
541 if (tty->ldisc->ops->num == ldisc) {
542 tty_ldisc_unlock(tty);
543 tty_ldisc_put(new_ldisc);
544 tty_unlock(tty);
545 return 0;
548 old_ldisc = tty->ldisc;
550 if (test_bit(TTY_HUPPED, &tty->flags)) {
551 /* We were raced by the hangup method. It will have stomped
552 the ldisc data and closed the ldisc down */
553 tty_ldisc_unlock(tty);
554 tty_ldisc_put(new_ldisc);
555 tty_unlock(tty);
556 return -EIO;
559 /* Shutdown the old discipline. */
560 tty_ldisc_close(tty, old_ldisc);
562 /* Now set up the new line discipline. */
563 tty->ldisc = new_ldisc;
564 tty_set_termios_ldisc(tty, ldisc);
566 retval = tty_ldisc_open(tty, new_ldisc);
567 if (retval < 0) {
568 /* Back to the old one or N_TTY if we can't */
569 tty_ldisc_put(new_ldisc);
570 tty_ldisc_restore(tty, old_ldisc);
573 if (tty->ldisc->ops->num != old_ldisc->ops->num && tty->ops->set_ldisc) {
574 down_read(&tty->termios_rwsem);
575 tty->ops->set_ldisc(tty);
576 up_read(&tty->termios_rwsem);
579 /* At this point we hold a reference to the new ldisc and a
580 reference to the old ldisc, or we hold two references to
581 the old ldisc (if it was restored as part of error cleanup
582 above). In either case, releasing a single reference from
583 the old ldisc is correct. */
585 tty_ldisc_put(old_ldisc);
588 * Allow ldisc referencing to occur again
590 tty_ldisc_unlock(tty);
592 /* Restart the work queue in case no characters kick it off. Safe if
593 already running */
594 schedule_work(&tty->port->buf.work);
596 tty_unlock(tty);
597 return retval;
601 * tty_reset_termios - reset terminal state
602 * @tty: tty to reset
604 * Restore a terminal to the driver default state.
607 static void tty_reset_termios(struct tty_struct *tty)
609 down_write(&tty->termios_rwsem);
610 tty->termios = tty->driver->init_termios;
611 tty->termios.c_ispeed = tty_termios_input_baud_rate(&tty->termios);
612 tty->termios.c_ospeed = tty_termios_baud_rate(&tty->termios);
613 up_write(&tty->termios_rwsem);
618 * tty_ldisc_reinit - reinitialise the tty ldisc
619 * @tty: tty to reinit
620 * @ldisc: line discipline to reinitialize
622 * Switch the tty to a line discipline and leave the ldisc
623 * state closed
626 static int tty_ldisc_reinit(struct tty_struct *tty, int ldisc)
628 struct tty_ldisc *ld = tty_ldisc_get(tty, ldisc);
630 if (IS_ERR(ld))
631 return -1;
633 tty_ldisc_close(tty, tty->ldisc);
634 tty_ldisc_put(tty->ldisc);
636 * Switch the line discipline back
638 tty->ldisc = ld;
639 tty_set_termios_ldisc(tty, ldisc);
641 return 0;
645 * tty_ldisc_hangup - hangup ldisc reset
646 * @tty: tty being hung up
648 * Some tty devices reset their termios when they receive a hangup
649 * event. In that situation we must also switch back to N_TTY properly
650 * before we reset the termios data.
652 * Locking: We can take the ldisc mutex as the rest of the code is
653 * careful to allow for this.
655 * In the pty pair case this occurs in the close() path of the
656 * tty itself so we must be careful about locking rules.
659 void tty_ldisc_hangup(struct tty_struct *tty)
661 struct tty_ldisc *ld;
662 int reset = tty->driver->flags & TTY_DRIVER_RESET_TERMIOS;
663 int err = 0;
665 tty_ldisc_debug(tty, "closing ldisc: %p\n", tty->ldisc);
667 ld = tty_ldisc_ref(tty);
668 if (ld != NULL) {
669 if (ld->ops->flush_buffer)
670 ld->ops->flush_buffer(tty);
671 tty_driver_flush_buffer(tty);
672 if ((test_bit(TTY_DO_WRITE_WAKEUP, &tty->flags)) &&
673 ld->ops->write_wakeup)
674 ld->ops->write_wakeup(tty);
675 if (ld->ops->hangup)
676 ld->ops->hangup(tty);
677 tty_ldisc_deref(ld);
680 wake_up_interruptible_poll(&tty->write_wait, POLLOUT);
681 wake_up_interruptible_poll(&tty->read_wait, POLLIN);
684 * Shutdown the current line discipline, and reset it to
685 * N_TTY if need be.
687 * Avoid racing set_ldisc or tty_ldisc_release
689 tty_ldisc_lock(tty, MAX_SCHEDULE_TIMEOUT);
691 if (tty->ldisc) {
693 /* At this point we have a halted ldisc; we want to close it and
694 reopen a new ldisc. We could defer the reopen to the next
695 open but it means auditing a lot of other paths so this is
696 a FIXME */
697 if (reset == 0) {
699 if (!tty_ldisc_reinit(tty, tty->termios.c_line))
700 err = tty_ldisc_open(tty, tty->ldisc);
701 else
702 err = 1;
704 /* If the re-open fails or we reset then go to N_TTY. The
705 N_TTY open cannot fail */
706 if (reset || err) {
707 BUG_ON(tty_ldisc_reinit(tty, N_TTY));
708 WARN_ON(tty_ldisc_open(tty, tty->ldisc));
711 tty_ldisc_unlock(tty);
712 if (reset)
713 tty_reset_termios(tty);
715 tty_ldisc_debug(tty, "re-opened ldisc: %p\n", tty->ldisc);
719 * tty_ldisc_setup - open line discipline
720 * @tty: tty being shut down
721 * @o_tty: pair tty for pty/tty pairs
723 * Called during the initial open of a tty/pty pair in order to set up the
724 * line disciplines and bind them to the tty. This has no locking issues
725 * as the device isn't yet active.
728 int tty_ldisc_setup(struct tty_struct *tty, struct tty_struct *o_tty)
730 struct tty_ldisc *ld = tty->ldisc;
731 int retval;
733 retval = tty_ldisc_open(tty, ld);
734 if (retval)
735 return retval;
737 if (o_tty) {
738 retval = tty_ldisc_open(o_tty, o_tty->ldisc);
739 if (retval) {
740 tty_ldisc_close(tty, ld);
741 return retval;
744 return 0;
747 static void tty_ldisc_kill(struct tty_struct *tty)
750 * Now kill off the ldisc
752 tty_ldisc_close(tty, tty->ldisc);
753 tty_ldisc_put(tty->ldisc);
754 /* Force an oops if we mess this up */
755 tty->ldisc = NULL;
757 /* Ensure the next open requests the N_TTY ldisc */
758 tty_set_termios_ldisc(tty, N_TTY);
762 * tty_ldisc_release - release line discipline
763 * @tty: tty being shut down (or one end of pty pair)
765 * Called during the final close of a tty or a pty pair in order to shut
766 * down the line discpline layer. On exit, each ldisc assigned is N_TTY and
767 * each ldisc has not been opened.
770 void tty_ldisc_release(struct tty_struct *tty)
772 struct tty_struct *o_tty = tty->link;
775 * Shutdown this line discipline. As this is the final close,
776 * it does not race with the set_ldisc code path.
779 tty_ldisc_debug(tty, "closing ldisc: %p\n", tty->ldisc);
781 tty_ldisc_lock_pair(tty, o_tty);
782 tty_ldisc_kill(tty);
783 if (o_tty)
784 tty_ldisc_kill(o_tty);
785 tty_ldisc_unlock_pair(tty, o_tty);
787 /* And the memory resources remaining (buffers, termios) will be
788 disposed of when the kref hits zero */
790 tty_ldisc_debug(tty, "ldisc closed\n");
794 * tty_ldisc_init - ldisc setup for new tty
795 * @tty: tty being allocated
797 * Set up the line discipline objects for a newly allocated tty. Note that
798 * the tty structure is not completely set up when this call is made.
801 void tty_ldisc_init(struct tty_struct *tty)
803 struct tty_ldisc *ld = tty_ldisc_get(tty, N_TTY);
804 if (IS_ERR(ld))
805 panic("n_tty: init_tty");
806 tty->ldisc = ld;
810 * tty_ldisc_init - ldisc cleanup for new tty
811 * @tty: tty that was allocated recently
813 * The tty structure must not becompletely set up (tty_ldisc_setup) when
814 * this call is made.
816 void tty_ldisc_deinit(struct tty_struct *tty)
818 tty_ldisc_put(tty->ldisc);
819 tty->ldisc = NULL;
822 void tty_ldisc_begin(void)
824 /* Setup the default TTY line discipline. */
825 (void) tty_register_ldisc(N_TTY, &tty_ldisc_N_TTY);