vt_ioctl: move vt_reldisp out of vt_ioctl
authorJiri Slaby <jslaby@suse.cz>
Mon, 15 Jun 2020 07:49:06 +0000 (09:49 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 24 Jun 2020 15:08:34 +0000 (17:08 +0200)
It's too long to be inlined.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Link: https://lore.kernel.org/r/20200615074910.19267-34-jslaby@suse.cz
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/tty/vt/vt_ioctl.c

index e8bcfcd..cdb7f03 100644 (file)
@@ -633,6 +633,42 @@ static int vt_io_ioctl(struct vc_data *vc, unsigned int cmd, void __user *up,
        return 0;
 }
 
+static int vt_reldisp(struct vc_data *vc, unsigned int swtch)
+{
+       int newvt, ret;
+
+       if (vc->vt_mode.mode != VT_PROCESS)
+               return -EINVAL;
+
+       /* Switched-to response */
+       if (vc->vt_newvt < 0) {
+                /* If it's just an ACK, ignore it */
+               return swtch == VT_ACKACQ ? 0 : -EINVAL;
+       }
+
+       /* Switching-from response */
+       if (swtch == 0) {
+               /* Switch disallowed, so forget we were trying to do it. */
+               vc->vt_newvt = -1;
+               return 0;
+       }
+
+       /* The current vt has been released, so complete the switch. */
+       newvt = vc->vt_newvt;
+       vc->vt_newvt = -1;
+       ret = vc_allocate(newvt);
+       if (ret)
+               return ret;
+
+       /*
+        * When we actually do the console switch, make sure we are atomic with
+        * respect to other console switches..
+        */
+       complete_change_console(vc_cons[newvt].d);
+
+       return 0;
+}
+
 static int vt_setactivate(struct vt_setactivate __user *sa)
 {
        struct vt_setactivate vsa;
@@ -865,55 +901,11 @@ int vt_ioctl(struct tty_struct *tty,
                        return -EPERM;
 
                console_lock();
-               if (vc->vt_mode.mode != VT_PROCESS) {
-                       console_unlock();
-                       return -EINVAL;
-               }
-               /*
-                * Switching-from response
-                */
-               if (vc->vt_newvt >= 0) {
-                       if (arg == 0)
-                               /*
-                                * Switch disallowed, so forget we were trying
-                                * to do it.
-                                */
-                               vc->vt_newvt = -1;
-
-                       else {
-                               /*
-                                * The current vt has been released, so
-                                * complete the switch.
-                                */
-                               int newvt;
-                               newvt = vc->vt_newvt;
-                               vc->vt_newvt = -1;
-                               ret = vc_allocate(newvt);
-                               if (ret) {
-                                       console_unlock();
-                                       return ret;
-                               }
-                               /*
-                                * When we actually do the console switch,
-                                * make sure we are atomic with respect to
-                                * other console switches..
-                                */
-                               complete_change_console(vc_cons[newvt].d);
-                       }
-               } else {
-                       /*
-                        * Switched-to response
-                        */
-                       /*
-                        * If it's just an ACK, ignore it
-                        */
-                       if (arg != VT_ACKACQ) {
-                               console_unlock();
-                               return -EINVAL;
-                       }
-               }
+               ret = vt_reldisp(vc, arg);
                console_unlock();
-               break;
+
+               return ret;
+
 
         /*
          * Disallocate memory associated to VT (but leave VT1)