kimage_file_prepare_segments(): don't open-code memdup_user()
authorAl Viro <viro@zeniv.linux.org.uk>
Sat, 13 May 2017 22:39:01 +0000 (18:39 -0400)
committerAl Viro <viro@zeniv.linux.org.uk>
Fri, 30 Jun 2017 06:04:10 +0000 (02:04 -0400)
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
kernel/kexec_file.c

index b118735fea9da471a15ba627c87af523b891bafa..766e7e4d3ad91d99a7b3cb90bc6f84511d76c72d 100644 (file)
@@ -162,16 +162,10 @@ kimage_file_prepare_segments(struct kimage *image, int kernel_fd, int initrd_fd,
        }
 
        if (cmdline_len) {
-               image->cmdline_buf = kzalloc(cmdline_len, GFP_KERNEL);
-               if (!image->cmdline_buf) {
-                       ret = -ENOMEM;
-                       goto out;
-               }
-
-               ret = copy_from_user(image->cmdline_buf, cmdline_ptr,
-                                    cmdline_len);
-               if (ret) {
-                       ret = -EFAULT;
+               image->cmdline_buf = memdup_user(cmdline_ptr, cmdline_len);
+               if (IS_ERR(image->cmdline_buf)) {
+                       ret = PTR_ERR(image->cmdline_buf);
+                       image->cmdline_buf = NULL;
                        goto out;
                }