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