forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-09 95099d4622f8cb224d94e314c7a8e0df60b13f87
kernel/drivers/tty/tty_ldisc.c
....@@ -79,7 +79,6 @@
7979 /**
8080 * tty_unregister_ldisc - unload a line discipline
8181 * @disc: ldisc number
82
- * @new_ldisc: pointer to the ldisc object
8382 *
8483 * Remove a line discipline from the kernel providing it is not
8584 * currently in use.
....@@ -156,12 +155,7 @@
156155 * takes tty_ldiscs_lock to guard against ldisc races
157156 */
158157
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);
165159
166160 static struct tty_ldisc *tty_ldisc_get(struct tty_struct *tty, int disc)
167161 {
....@@ -487,6 +481,7 @@
487481
488482 static void tty_ldisc_close(struct tty_struct *tty, struct tty_ldisc *ld)
489483 {
484
+ lockdep_assert_held_write(&tty->ldisc_sem);
490485 WARN_ON(!test_bit(TTY_LDISC_OPEN, &tty->flags));
491486 clear_bit(TTY_LDISC_OPEN, &tty->flags);
492487 if (ld->ops->close)
....@@ -508,6 +503,7 @@
508503 struct tty_ldisc *disc = tty_ldisc_get(tty, ld);
509504 int r;
510505
506
+ lockdep_assert_held_write(&tty->ldisc_sem);
511507 if (IS_ERR(disc))
512508 return PTR_ERR(disc);
513509 tty->ldisc = disc;
....@@ -545,7 +541,7 @@
545541 /**
546542 * tty_set_ldisc - set line discipline
547543 * @tty: the terminal to set
548
- * @ldisc: the line discipline
544
+ * @disc: the line discipline number
549545 *
550546 * Set the discipline of a tty line. Must be called from a process
551547 * context. The ldisc change logic has to protect itself against any
....@@ -631,6 +627,7 @@
631627 */
632628 static void tty_ldisc_kill(struct tty_struct *tty)
633629 {
630
+ lockdep_assert_held_write(&tty->ldisc_sem);
634631 if (!tty->ldisc)
635632 return;
636633 /*
....@@ -678,6 +675,7 @@
678675 struct tty_ldisc *ld;
679676 int retval;
680677
678
+ lockdep_assert_held_write(&tty->ldisc_sem);
681679 ld = tty_ldisc_get(tty, disc);
682680 if (IS_ERR(ld)) {
683681 BUG_ON(disc == N_TTY);
....@@ -776,6 +774,10 @@
776774 return retval;
777775
778776 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
+ */
779781 retval = tty_ldisc_open(o_tty, o_tty->ldisc);
780782 if (retval) {
781783 tty_ldisc_close(tty, tty->ldisc);
....@@ -841,13 +843,12 @@
841843 */
842844 void tty_ldisc_deinit(struct tty_struct *tty)
843845 {
846
+ /* no ldisc_sem, tty is being destroyed */
844847 if (tty->ldisc)
845848 tty_ldisc_put(tty->ldisc);
846849 tty->ldisc = NULL;
847850 }
848851
849
-static int zero;
850
-static int one = 1;
851852 static struct ctl_table tty_table[] = {
852853 {
853854 .procname = "ldisc_autoload",
....@@ -855,8 +856,8 @@
855856 .maxlen = sizeof(tty_ldisc_autoload),
856857 .mode = 0644,
857858 .proc_handler = proc_dointvec,
858
- .extra1 = &zero,
859
- .extra2 = &one,
859
+ .extra1 = SYSCTL_ZERO,
860
+ .extra2 = SYSCTL_ONE,
860861 },
861862 { }
862863 };