From: Saurabh Sengar Date: Wed, 28 Oct 2015 06:26:44 +0000 (+0530) Subject: tty/vt/keyboard: use memdup_user to simplify code X-Git-Tag: next-20160210~21^2~10 X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=1051937d465665e3360ea7d9a3d2adfd86f47dd4;p=karo-tx-linux.git tty/vt/keyboard: use memdup_user to simplify code use memdup_user rather than duplicating implementation. found by coccinelle Signed-off-by: Saurabh Sengar Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c index 6f0336fff501..f973bfce5d08 100644 --- a/drivers/tty/vt/keyboard.c +++ b/drivers/tty/vt/keyboard.c @@ -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);