tty/vt/keyboard: use memdup_user().
authorMuhammad Falak R Wani <falakreyaz@gmail.com>
Fri, 20 May 2016 12:23:28 +0000 (17:53 +0530)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 25 Jun 2016 17:40:33 +0000 (10:40 -0700)
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 <falakreyaz@gmail.com>
Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/tty/vt/keyboard.c

index cd08c103eb47b6117b3208996a6f5b3ee8d56ca3..89a7ab007ff4008f5b29b350589e8a845fec1320 100644 (file)
@@ -1745,16 +1745,10 @@ int vt_do_diacrit(unsigned int cmd, void __user *udp, int perm)
                        return -EINVAL;
 
                if (ct) {
-                       buf = kmalloc(ct * sizeof(struct kbdiacruc),
-                                                               GFP_KERNEL);
-                       if (buf == NULL)
-                               return -ENOMEM;
-
-                       if (copy_from_user(buf, a->kbdiacruc,
-                                       ct * sizeof(struct kbdiacruc))) {
-                               kfree(buf);
-                               return -EFAULT;
-                       }
+                       buf = memdup_user(a->kbdiacruc,
+                                         ct * sizeof(struct kbdiacruc));
+                       if (IS_ERR(buf))
+                               return PTR_ERR(buf);
                } 
                spin_lock_irqsave(&kbd_event_lock, flags);
                if (ct)