]> git.kernelconcepts.de Git - karo-tx-linux.git/blobdiff - drivers/s390/char/keyboard.c
Merge branch 'for-4.8/core' of git://git.kernel.dk/linux-block
[karo-tx-linux.git] / drivers / s390 / char / keyboard.c
index ef04a9f7a70494bea94032b7b4eb896eb11553a7..7b9c50aa4cc922973cb2cd758244f264b81849d1 100644 (file)
@@ -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;