staging: lustre: llite: kzalloc/copy_to_user to memdup_user
authorTobin C Harding <me@tobin.cc>
Mon, 23 May 2016 00:14:22 +0000 (10:14 +1000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 8 Jun 2016 05:38:19 +0000 (22:38 -0700)
kzalloc call followed by copy_to_user can be replaced by call to memdup_user.

Signed-off-by: Tobin C Harding <me@tobin.cc>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/lustre/lustre/llite/dir.c

index 4b00d1ac84fb7b721495ba53f3c11df5f3bf3521..85c50e0d5565b767adefaaf930a118a1074bf0b7 100644 (file)
@@ -1076,17 +1076,11 @@ static int copy_and_ioctl(int cmd, struct obd_export *exp,
        void *copy;
        int rc;
 
-       copy = kzalloc(size, GFP_NOFS);
-       if (!copy)
-               return -ENOMEM;
-
-       if (copy_from_user(copy, data, size)) {
-               rc = -EFAULT;
-               goto out;
-       }
+       copy = memdup_user(data, size);
+       if (IS_ERR(copy))
+               return PTR_ERR(copy);
 
        rc = obd_iocontrol(cmd, exp, size, copy, NULL);
-out:
        kfree(copy);
 
        return rc;