hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/tty/tty_ldisc.c
....@@ -19,6 +19,7 @@
1919 #include <linux/seq_file.h>
2020 #include <linux/uaccess.h>
2121 #include <linux/ratelimit.h>
22
+#include "tty.h"
2223
2324 #undef LDISC_DEBUG_HANGUP
2425
....@@ -79,7 +80,6 @@
7980 /**
8081 * tty_unregister_ldisc - unload a line discipline
8182 * @disc: ldisc number
82
- * @new_ldisc: pointer to the ldisc object
8383 *
8484 * Remove a line discipline from the kernel providing it is not
8585 * currently in use.
....@@ -156,12 +156,7 @@
156156 * takes tty_ldiscs_lock to guard against ldisc races
157157 */
158158
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);
165160
166161 static struct tty_ldisc *tty_ldisc_get(struct tty_struct *tty, int disc)
167162 {
....@@ -487,6 +482,7 @@
487482
488483 static void tty_ldisc_close(struct tty_struct *tty, struct tty_ldisc *ld)
489484 {
485
+ lockdep_assert_held_write(&tty->ldisc_sem);
490486 WARN_ON(!test_bit(TTY_LDISC_OPEN, &tty->flags));
491487 clear_bit(TTY_LDISC_OPEN, &tty->flags);
492488 if (ld->ops->close)
....@@ -508,6 +504,7 @@
508504 struct tty_ldisc *disc = tty_ldisc_get(tty, ld);
509505 int r;
510506
507
+ lockdep_assert_held_write(&tty->ldisc_sem);
511508 if (IS_ERR(disc))
512509 return PTR_ERR(disc);
513510 tty->ldisc = disc;
....@@ -545,7 +542,7 @@
545542 /**
546543 * tty_set_ldisc - set line discipline
547544 * @tty: the terminal to set
548
- * @ldisc: the line discipline
545
+ * @disc: the line discipline number
549546 *
550547 * Set the discipline of a tty line. Must be called from a process
551548 * context. The ldisc change logic has to protect itself against any
....@@ -631,6 +628,7 @@
631628 */
632629 static void tty_ldisc_kill(struct tty_struct *tty)
633630 {
631
+ lockdep_assert_held_write(&tty->ldisc_sem);
634632 if (!tty->ldisc)
635633 return;
636634 /*
....@@ -678,6 +676,7 @@
678676 struct tty_ldisc *ld;
679677 int retval;
680678
679
+ lockdep_assert_held_write(&tty->ldisc_sem);
681680 ld = tty_ldisc_get(tty, disc);
682681 if (IS_ERR(ld)) {
683682 BUG_ON(disc == N_TTY);
....@@ -776,6 +775,10 @@
776775 return retval;
777776
778777 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
+ */
779782 retval = tty_ldisc_open(o_tty, o_tty->ldisc);
780783 if (retval) {
781784 tty_ldisc_close(tty, tty->ldisc);
....@@ -841,13 +844,12 @@
841844 */
842845 void tty_ldisc_deinit(struct tty_struct *tty)
843846 {
847
+ /* no ldisc_sem, tty is being destroyed */
844848 if (tty->ldisc)
845849 tty_ldisc_put(tty->ldisc);
846850 tty->ldisc = NULL;
847851 }
848852
849
-static int zero;
850
-static int one = 1;
851853 static struct ctl_table tty_table[] = {
852854 {
853855 .procname = "ldisc_autoload",
....@@ -855,8 +857,8 @@
855857 .maxlen = sizeof(tty_ldisc_autoload),
856858 .mode = 0644,
857859 .proc_handler = proc_dointvec,
858
- .extra1 = &zero,
859
- .extra2 = &one,
860
+ .extra1 = SYSCTL_ZERO,
861
+ .extra2 = SYSCTL_ONE,
860862 },
861863 { }
862864 };