]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
tty/vt/keyboard: use memdup_user to simplify code
authorSaurabh Sengar <saurabh.truth@gmail.com>
Wed, 28 Oct 2015 06:26:44 +0000 (11:56 +0530)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 7 Feb 2016 07:27:46 +0000 (23:27 -0800)
use memdup_user rather than duplicating implementation.
found by coccinelle

Signed-off-by: Saurabh Sengar <saurabh.truth@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/tty/vt/keyboard.c

index 6f0336fff5011046cbb2d5d0642228b00b34307c..f973bfce5d089256086b945fb37148fffebf902d 100644 (file)
@@ -1706,16 +1706,12 @@ int vt_do_diacrit(unsigned int cmd, void __user *udp, int perm)
                        return -EINVAL;
 
                if (ct) {
-                       dia = kmalloc(sizeof(struct kbdiacr) * ct,
-                                                               GFP_KERNEL);
-                       if (!dia)
-                               return -ENOMEM;
 
-                       if (copy_from_user(dia, a->kbdiacr,
-                                       sizeof(struct kbdiacr) * ct)) {
-                               kfree(dia);
-                               return -EFAULT;
-                       }
+                       dia = memdup_user(a->kbdiacr,
+                                       sizeof(struct kbdiacr) * ct);
+                       if (IS_ERR(dia))
+                               return PTR_ERR(dia);
+
                }
 
                spin_lock_irqsave(&kbd_event_lock, flags);