Skip to content

Commit 0097ff3

Browse files
mfrwdtor
authored andcommitted
Input: tty/vt/keyboard - use memdup_user()
Use memdup_user to duplicate a memory region from user-space to kernel-space, instead of open coding using kmalloc & copy_from_user. Signed-off-by: Muhammad Falak R Wani <[email protected]> Reviewed-by: Samuel Thibault <[email protected]> Signed-off-by: Dmitry Torokhov <[email protected]>
1 parent c1d7b7c commit 0097ff3

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

drivers/tty/vt/keyboard.c

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1745,16 +1745,10 @@ int vt_do_diacrit(unsigned int cmd, void __user *udp, int perm)
17451745
return -EINVAL;
17461746

17471747
if (ct) {
1748-
buf = kmalloc(ct * sizeof(struct kbdiacruc),
1749-
GFP_KERNEL);
1750-
if (buf == NULL)
1751-
return -ENOMEM;
1752-
1753-
if (copy_from_user(buf, a->kbdiacruc,
1754-
ct * sizeof(struct kbdiacruc))) {
1755-
kfree(buf);
1756-
return -EFAULT;
1757-
}
1748+
buf = memdup_user(a->kbdiacruc,
1749+
ct * sizeof(struct kbdiacruc));
1750+
if (IS_ERR(buf))
1751+
return PTR_ERR(buf);
17581752
}
17591753
spin_lock_irqsave(&kbd_event_lock, flags);
17601754
if (ct)

0 commit comments

Comments
 (0)