summaryrefslogtreecommitdiffstats
path: root/drivers/tty/vt
diff options
context:
space:
mode:
authorJiri Slaby <jslaby@suse.cz>2020-06-15 09:49:04 +0200
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2020-06-24 17:08:34 +0200
commitbfbbdfa4de133ed235359693dae8468c1dc98cf1 (patch)
tree4e78395ef5fb1af22d787505ed91b913399151ac /drivers/tty/vt
parentvt_ioctl: move K* ioctls to a separate function (diff)
downloadlinux-bfbbdfa4de133ed235359693dae8468c1dc98cf1.tar.xz
linux-bfbbdfa4de133ed235359693dae8468c1dc98cf1.zip
vt_ioctl: move io ioctls to a separate function
We create a new vt_io_ioctl here and move there all the IO ioctls. This makes vt_ioctl significantly smaller. Signed-off-by: Jiri Slaby <jslaby@suse.cz> Link: https://lore.kernel.org/r/20200615074910.19267-32-jslaby@suse.cz Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/tty/vt')
-rw-r--r--drivers/tty/vt/vt_ioctl.c177
1 files changed, 98 insertions, 79 deletions
diff --git a/drivers/tty/vt/vt_ioctl.c b/drivers/tty/vt/vt_ioctl.c
index 1b423bdc488e..978c33ad6619 100644
--- a/drivers/tty/vt/vt_ioctl.c
+++ b/drivers/tty/vt/vt_ioctl.c
@@ -539,6 +539,100 @@ static inline int do_unimap_ioctl(int cmd, struct unimapdesc __user *user_ud,
return 0;
}
+static int vt_io_ioctl(struct vc_data *vc, unsigned int cmd, void __user *up,
+ bool perm)
+{
+ struct console_font_op op; /* used in multiple places here */
+
+ switch (cmd) {
+ case PIO_FONT:
+ if (!perm)
+ return -EPERM;
+ op.op = KD_FONT_OP_SET;
+ op.flags = KD_FONT_FLAG_OLD | KD_FONT_FLAG_DONT_RECALC; /* Compatibility */
+ op.width = 8;
+ op.height = 0;
+ op.charcount = 256;
+ op.data = up;
+ return con_font_op(vc_cons[fg_console].d, &op);
+
+ case GIO_FONT:
+ op.op = KD_FONT_OP_GET;
+ op.flags = KD_FONT_FLAG_OLD;
+ op.width = 8;
+ op.height = 32;
+ op.charcount = 256;
+ op.data = up;
+ return con_font_op(vc_cons[fg_console].d, &op);
+
+ case PIO_CMAP:
+ if (!perm)
+ return -EPERM;
+ return con_set_cmap(up);
+
+ case GIO_CMAP:
+ return con_get_cmap(up);
+
+ case PIO_FONTX:
+ case GIO_FONTX:
+ return do_fontx_ioctl(cmd, up, perm, &op);
+
+ case PIO_FONTRESET:
+ if (!perm)
+ return -EPERM;
+
+#ifdef BROKEN_GRAPHICS_PROGRAMS
+ /* With BROKEN_GRAPHICS_PROGRAMS defined, the default
+ font is not saved. */
+ return -ENOSYS;
+#else
+ {
+ int ret;
+ op.op = KD_FONT_OP_SET_DEFAULT;
+ op.data = NULL;
+ ret = con_font_op(vc_cons[fg_console].d, &op);
+ if (ret)
+ return ret;
+ console_lock();
+ con_set_default_unimap(vc_cons[fg_console].d);
+ console_unlock();
+ break;
+ }
+#endif
+
+ case PIO_SCRNMAP:
+ if (!perm)
+ return -EPERM;
+ return con_set_trans_old(up);
+
+ case GIO_SCRNMAP:
+ return con_get_trans_old(up);
+
+ case PIO_UNISCRNMAP:
+ if (!perm)
+ return -EPERM;
+ return con_set_trans_new(up);
+
+ case GIO_UNISCRNMAP:
+ return con_get_trans_new(up);
+
+ case PIO_UNIMAPCLR:
+ if (!perm)
+ return -EPERM;
+ con_clear_unimap(vc);
+ break;
+
+ case PIO_UNIMAP:
+ case GIO_UNIMAP:
+ return do_unimap_ioctl(cmd, up, perm, vc);
+
+ default:
+ return -ENOIOCTLCMD;
+ }
+
+ return 0;
+}
+
/* deallocate a single console, if possible (leave 0) */
static int vt_disallocate(unsigned int vc_num)
{
@@ -586,7 +680,6 @@ int vt_ioctl(struct tty_struct *tty,
unsigned int cmd, unsigned long arg)
{
struct vc_data *vc = tty->driver_data;
- struct console_font_op op; /* used in multiple places here */
void __user *up = (void __user *)arg;
int i, perm;
int ret;
@@ -603,6 +696,10 @@ int vt_ioctl(struct tty_struct *tty,
if (ret != -ENOIOCTLCMD)
return ret;
+ ret = vt_io_ioctl(vc, cmd, up, perm);
+ if (ret != -ENOIOCTLCMD)
+ return ret;
+
switch (cmd) {
case TIOCLINUX:
return tioclinux(tty, arg);
@@ -903,84 +1000,6 @@ int vt_ioctl(struct tty_struct *tty,
break;
}
- case PIO_FONT:
- if (!perm)
- return -EPERM;
- op.op = KD_FONT_OP_SET;
- op.flags = KD_FONT_FLAG_OLD | KD_FONT_FLAG_DONT_RECALC; /* Compatibility */
- op.width = 8;
- op.height = 0;
- op.charcount = 256;
- op.data = up;
- return con_font_op(vc_cons[fg_console].d, &op);
-
- case GIO_FONT:
- op.op = KD_FONT_OP_GET;
- op.flags = KD_FONT_FLAG_OLD;
- op.width = 8;
- op.height = 32;
- op.charcount = 256;
- op.data = up;
- return con_font_op(vc_cons[fg_console].d, &op);
-
- case PIO_CMAP:
- if (!perm)
- return -EPERM;
- return con_set_cmap(up);
-
- case GIO_CMAP:
- return con_get_cmap(up);
-
- case PIO_FONTX:
- case GIO_FONTX:
- return do_fontx_ioctl(cmd, up, perm, &op);
-
- case PIO_FONTRESET:
- if (!perm)
- return -EPERM;
-
-#ifdef BROKEN_GRAPHICS_PROGRAMS
- /* With BROKEN_GRAPHICS_PROGRAMS defined, the default
- font is not saved. */
- return -ENOSYS;
-#else
- op.op = KD_FONT_OP_SET_DEFAULT;
- op.data = NULL;
- ret = con_font_op(vc_cons[fg_console].d, &op);
- if (ret)
- return ret;
- console_lock();
- con_set_default_unimap(vc_cons[fg_console].d);
- console_unlock();
- break;
-#endif
-
- case PIO_SCRNMAP:
- if (!perm)
- return -EPERM;
- return con_set_trans_old(up);
-
- case GIO_SCRNMAP:
- return con_get_trans_old(up);
-
- case PIO_UNISCRNMAP:
- if (!perm)
- return -EPERM;
- return con_set_trans_new(up);
-
- case GIO_UNISCRNMAP:
- return con_get_trans_new(up);
-
- case PIO_UNIMAPCLR:
- if (!perm)
- return -EPERM;
- con_clear_unimap(vc);
- break;
-
- case PIO_UNIMAP:
- case GIO_UNIMAP:
- return do_unimap_ioctl(cmd, up, perm, vc);
-
case VT_LOCKSWITCH:
if (!capable(CAP_SYS_TTY_CONFIG))
return -EPERM;