tty: Move sysctl setup into "core" tty logic
authorKees Cook <keescook@chromium.org>
Sat, 22 Oct 2022 18:29:48 +0000 (11:29 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 3 Nov 2022 00:58:03 +0000 (01:58 +0100)
In preparation for adding another sysctl to the tty subsystem, move the
tty setup code into the "core" tty code, which contains tty_init() itself.

Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Jiri Slaby <jirislaby@kernel.org>
Signed-off-by: Kees Cook <keescook@chromium.org>
Link: https://lore.kernel.org/r/20221022182949.2684794-1-keescook@chromium.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/tty/tty.h
drivers/tty/tty_io.c
drivers/tty/tty_ldisc.c

index 1c08c9b..f45cd68 100644 (file)
@@ -93,7 +93,7 @@ void tty_ldisc_release(struct tty_struct *tty);
 int __must_check tty_ldisc_init(struct tty_struct *tty);
 void tty_ldisc_deinit(struct tty_struct *tty);
 
-void tty_sysctl_init(void);
+extern int tty_ldisc_autoload;
 
 /* tty_audit.c */
 #ifdef CONFIG_AUDIT
index de06c3c..fe77a3d 100644 (file)
@@ -3572,13 +3572,44 @@ void console_sysfs_notify(void)
                sysfs_notify(&consdev->kobj, NULL, "active");
 }
 
+static struct ctl_table tty_table[] = {
+       {
+               .procname       = "ldisc_autoload",
+               .data           = &tty_ldisc_autoload,
+               .maxlen         = sizeof(tty_ldisc_autoload),
+               .mode           = 0644,
+               .proc_handler   = proc_dointvec,
+               .extra1         = SYSCTL_ZERO,
+               .extra2         = SYSCTL_ONE,
+       },
+       { }
+};
+
+static struct ctl_table tty_dir_table[] = {
+       {
+               .procname       = "tty",
+               .mode           = 0555,
+               .child          = tty_table,
+       },
+       { }
+};
+
+static struct ctl_table tty_root_table[] = {
+       {
+               .procname       = "dev",
+               .mode           = 0555,
+               .child          = tty_dir_table,
+       },
+       { }
+};
+
 /*
  * Ok, now we can initialize the rest of the tty devices and can count
  * on memory allocations, interrupts etc..
  */
 int __init tty_init(void)
 {
-       tty_sysctl_init();
+       register_sysctl_table(tty_root_table);
        cdev_init(&tty_cdev, &tty_fops);
        if (cdev_add(&tty_cdev, MKDEV(TTYAUX_MAJOR, 0), 1) ||
            register_chrdev_region(MKDEV(TTYAUX_MAJOR, 0), 1, "/dev/tty") < 0)
@@ -3600,4 +3631,3 @@ int __init tty_init(void)
 #endif
        return 0;
 }
-
index 776d8a6..e758f44 100644 (file)
@@ -117,7 +117,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
        raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
 }
 
-static int tty_ldisc_autoload = IS_BUILTIN(CONFIG_LDISC_AUTOLOAD);
+int tty_ldisc_autoload = IS_BUILTIN(CONFIG_LDISC_AUTOLOAD);
 
 /**
  * tty_ldisc_get       -       take a reference to an ldisc
@@ -817,39 +817,3 @@ void tty_ldisc_deinit(struct tty_struct *tty)
                tty_ldisc_put(tty->ldisc);
        tty->ldisc = NULL;
 }
-
-static struct ctl_table tty_table[] = {
-       {
-               .procname       = "ldisc_autoload",
-               .data           = &tty_ldisc_autoload,
-               .maxlen         = sizeof(tty_ldisc_autoload),
-               .mode           = 0644,
-               .proc_handler   = proc_dointvec,
-               .extra1         = SYSCTL_ZERO,
-               .extra2         = SYSCTL_ONE,
-       },
-       { }
-};
-
-static struct ctl_table tty_dir_table[] = {
-       {
-               .procname       = "tty",
-               .mode           = 0555,
-               .child          = tty_table,
-       },
-       { }
-};
-
-static struct ctl_table tty_root_table[] = {
-       {
-               .procname       = "dev",
-               .mode           = 0555,
-               .child          = tty_dir_table,
-       },
-       { }
-};
-
-void tty_sysctl_init(void)
-{
-       register_sysctl_table(tty_root_table);
-}