summaryrefslogtreecommitdiffstats
path: root/drivers/s390/char/keyboard.c
diff options
context:
space:
mode:
authorMuhammad Falak R Wani <falakreyaz@gmail.com>2016-05-20 18:51:20 +0530
committerMartin Schwidefsky <schwidefsky@de.ibm.com>2016-06-13 15:58:12 +0200
commitfd346c9dae6b266f8c3f62df20237059a3a90312 (patch)
tree33658f9b194c4737d949e7a9e75b3d3181418679 /drivers/s390/char/keyboard.c
parent1c343f7b0e177e8ca7f4d4a5dd1fa790f85abbcc (diff)
downloadlinux-fd346c9dae6b266f8c3f62df20237059a3a90312.tar.gz
linux-fd346c9dae6b266f8c3f62df20237059a3a90312.tar.bz2
linux-fd346c9dae6b266f8c3f62df20237059a3a90312.zip
s390/keyboard: use memdup_user_nul()
Use memdup_user_nul to duplicate a memory region from user-space to kernel-space and terminate with a NULL, instead of open coding using kmalloc + copy_from_user and explicitly NULL terminating. Signed-off-by: Muhammad Falak R Wani <falakreyaz@gmail.com> [heiko.carstens@de.ibm.com: remove comment] Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com> Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
Diffstat (limited to 'drivers/s390/char/keyboard.c')
-rw-r--r--drivers/s390/char/keyboard.c15
1 files changed, 3 insertions, 12 deletions
diff --git a/drivers/s390/char/keyboard.c b/drivers/s390/char/keyboard.c
index ef04a9f7a704..7b9c50aa4cc9 100644
--- a/drivers/s390/char/keyboard.c
+++ b/drivers/s390/char/keyboard.c
@@ -438,18 +438,9 @@ do_kdgkb_ioctl(struct kbd_data *kbd, struct kbsentry __user *u_kbs,
return -EFAULT;
if (len > sizeof(u_kbs->kb_string))
return -EINVAL;
- p = kmalloc(len, GFP_KERNEL);
- if (!p)
- return -ENOMEM;
- if (copy_from_user(p, u_kbs->kb_string, len)) {
- kfree(p);
- return -EFAULT;
- }
- /*
- * Make sure the string is terminated by 0. User could have
- * modified it between us running strnlen_user() and copying it.
- */
- p[len - 1] = 0;
+ p = memdup_user_nul(u_kbs->kb_string, len);
+ if (IS_ERR(p))
+ return PTR_ERR(p);
kfree(kbd->func_table[kb_func]);
kbd->func_table[kb_func] = p;
break;