tty: vt/keyboard: simplify returns from vt_do_kbkeycode_ioctl()

Return immediately when something goes wrong in vt_do_kbkeycode_ioctl().
This makes the code flow more obvious.

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
Link: https://patch.msgid.link/20251119100140.830761-8-jirislaby@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Jiri Slaby (SUSE)
2025-11-19 11:01:37 +01:00
committed by Greg Kroah-Hartman
parent bfb24564b5
commit d139b31f86

View File

@@ -1879,27 +1879,27 @@ int vt_do_kdskbmeta(unsigned int console, unsigned int arg)
return ret; return ret;
} }
int vt_do_kbkeycode_ioctl(int cmd, struct kbkeycode __user *user_kbkc, int vt_do_kbkeycode_ioctl(int cmd, struct kbkeycode __user *user_kbkc, int perm)
int perm)
{ {
struct kbkeycode tmp; struct kbkeycode tmp;
int kc = 0; int kc;
if (copy_from_user(&tmp, user_kbkc, sizeof(struct kbkeycode))) if (copy_from_user(&tmp, user_kbkc, sizeof(struct kbkeycode)))
return -EFAULT; return -EFAULT;
switch (cmd) { switch (cmd) {
case KDGETKEYCODE: case KDGETKEYCODE:
kc = getkeycode(tmp.scancode); kc = getkeycode(tmp.scancode);
if (kc >= 0) if (kc < 0)
kc = put_user(kc, &user_kbkc->keycode); return kc;
break; return put_user(kc, &user_kbkc->keycode);
case KDSETKEYCODE: case KDSETKEYCODE:
if (!perm) if (!perm)
return -EPERM; return -EPERM;
kc = setkeycode(tmp.scancode, tmp.keycode); return setkeycode(tmp.scancode, tmp.keycode);
break;
} }
return kc;
return 0;
} }
static unsigned short vt_kdgkbent(unsigned char kbdmode, unsigned char idx, static unsigned short vt_kdgkbent(unsigned char kbdmode, unsigned char idx,