| .. | .. |
|---|
| 19 | 19 | #include <linux/seq_file.h> |
|---|
| 20 | 20 | #include <linux/uaccess.h> |
|---|
| 21 | 21 | #include <linux/ratelimit.h> |
|---|
| 22 | +#include "tty.h" |
|---|
| 22 | 23 | |
|---|
| 23 | 24 | #undef LDISC_DEBUG_HANGUP |
|---|
| 24 | 25 | |
|---|
| .. | .. |
|---|
| 79 | 80 | /** |
|---|
| 80 | 81 | * tty_unregister_ldisc - unload a line discipline |
|---|
| 81 | 82 | * @disc: ldisc number |
|---|
| 82 | | - * @new_ldisc: pointer to the ldisc object |
|---|
| 83 | 83 | * |
|---|
| 84 | 84 | * Remove a line discipline from the kernel providing it is not |
|---|
| 85 | 85 | * currently in use. |
|---|
| .. | .. |
|---|
| 156 | 156 | * takes tty_ldiscs_lock to guard against ldisc races |
|---|
| 157 | 157 | */ |
|---|
| 158 | 158 | |
|---|
| 159 | | -#if defined(CONFIG_LDISC_AUTOLOAD) |
|---|
| 160 | | - #define INITIAL_AUTOLOAD_STATE 1 |
|---|
| 161 | | -#else |
|---|
| 162 | | - #define INITIAL_AUTOLOAD_STATE 0 |
|---|
| 163 | | -#endif |
|---|
| 164 | | -static int tty_ldisc_autoload = INITIAL_AUTOLOAD_STATE; |
|---|
| 159 | +static int tty_ldisc_autoload = IS_BUILTIN(CONFIG_LDISC_AUTOLOAD); |
|---|
| 165 | 160 | |
|---|
| 166 | 161 | static struct tty_ldisc *tty_ldisc_get(struct tty_struct *tty, int disc) |
|---|
| 167 | 162 | { |
|---|
| .. | .. |
|---|
| 487 | 482 | |
|---|
| 488 | 483 | static void tty_ldisc_close(struct tty_struct *tty, struct tty_ldisc *ld) |
|---|
| 489 | 484 | { |
|---|
| 485 | + lockdep_assert_held_write(&tty->ldisc_sem); |
|---|
| 490 | 486 | WARN_ON(!test_bit(TTY_LDISC_OPEN, &tty->flags)); |
|---|
| 491 | 487 | clear_bit(TTY_LDISC_OPEN, &tty->flags); |
|---|
| 492 | 488 | if (ld->ops->close) |
|---|
| .. | .. |
|---|
| 508 | 504 | struct tty_ldisc *disc = tty_ldisc_get(tty, ld); |
|---|
| 509 | 505 | int r; |
|---|
| 510 | 506 | |
|---|
| 507 | + lockdep_assert_held_write(&tty->ldisc_sem); |
|---|
| 511 | 508 | if (IS_ERR(disc)) |
|---|
| 512 | 509 | return PTR_ERR(disc); |
|---|
| 513 | 510 | tty->ldisc = disc; |
|---|
| .. | .. |
|---|
| 545 | 542 | /** |
|---|
| 546 | 543 | * tty_set_ldisc - set line discipline |
|---|
| 547 | 544 | * @tty: the terminal to set |
|---|
| 548 | | - * @ldisc: the line discipline |
|---|
| 545 | + * @disc: the line discipline number |
|---|
| 549 | 546 | * |
|---|
| 550 | 547 | * Set the discipline of a tty line. Must be called from a process |
|---|
| 551 | 548 | * context. The ldisc change logic has to protect itself against any |
|---|
| .. | .. |
|---|
| 631 | 628 | */ |
|---|
| 632 | 629 | static void tty_ldisc_kill(struct tty_struct *tty) |
|---|
| 633 | 630 | { |
|---|
| 631 | + lockdep_assert_held_write(&tty->ldisc_sem); |
|---|
| 634 | 632 | if (!tty->ldisc) |
|---|
| 635 | 633 | return; |
|---|
| 636 | 634 | /* |
|---|
| .. | .. |
|---|
| 678 | 676 | struct tty_ldisc *ld; |
|---|
| 679 | 677 | int retval; |
|---|
| 680 | 678 | |
|---|
| 679 | + lockdep_assert_held_write(&tty->ldisc_sem); |
|---|
| 681 | 680 | ld = tty_ldisc_get(tty, disc); |
|---|
| 682 | 681 | if (IS_ERR(ld)) { |
|---|
| 683 | 682 | BUG_ON(disc == N_TTY); |
|---|
| .. | .. |
|---|
| 776 | 775 | return retval; |
|---|
| 777 | 776 | |
|---|
| 778 | 777 | if (o_tty) { |
|---|
| 778 | + /* |
|---|
| 779 | + * Called without o_tty->ldisc_sem held, as o_tty has been |
|---|
| 780 | + * just allocated and no one has a reference to it. |
|---|
| 781 | + */ |
|---|
| 779 | 782 | retval = tty_ldisc_open(o_tty, o_tty->ldisc); |
|---|
| 780 | 783 | if (retval) { |
|---|
| 781 | 784 | tty_ldisc_close(tty, tty->ldisc); |
|---|
| .. | .. |
|---|
| 841 | 844 | */ |
|---|
| 842 | 845 | void tty_ldisc_deinit(struct tty_struct *tty) |
|---|
| 843 | 846 | { |
|---|
| 847 | + /* no ldisc_sem, tty is being destroyed */ |
|---|
| 844 | 848 | if (tty->ldisc) |
|---|
| 845 | 849 | tty_ldisc_put(tty->ldisc); |
|---|
| 846 | 850 | tty->ldisc = NULL; |
|---|
| 847 | 851 | } |
|---|
| 848 | 852 | |
|---|
| 849 | | -static int zero; |
|---|
| 850 | | -static int one = 1; |
|---|
| 851 | 853 | static struct ctl_table tty_table[] = { |
|---|
| 852 | 854 | { |
|---|
| 853 | 855 | .procname = "ldisc_autoload", |
|---|
| .. | .. |
|---|
| 855 | 857 | .maxlen = sizeof(tty_ldisc_autoload), |
|---|
| 856 | 858 | .mode = 0644, |
|---|
| 857 | 859 | .proc_handler = proc_dointvec, |
|---|
| 858 | | - .extra1 = &zero, |
|---|
| 859 | | - .extra2 = &one, |
|---|
| 860 | + .extra1 = SYSCTL_ZERO, |
|---|
| 861 | + .extra2 = SYSCTL_ONE, |
|---|
| 860 | 862 | }, |
|---|
| 861 | 863 | { } |
|---|
| 862 | 864 | }; |
|---|