staging: lustre: use memdup_user to allocate memory and copy from user
authorDafna Hirschfeld <dafna3@gmail.com>
Mon, 19 Feb 2018 19:57:37 +0000 (21:57 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 20 Feb 2018 08:03:42 +0000 (09:03 +0100)
Replace a call to kmalloc and a call to copy_from_user with a
call to memdup_user to simplify the code.
Issue found with coccicheck.

Signed-off-by: Dafna Hirschfeld <dafna3@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/lustre/lnet/selftest/conctl.c

index 34ba440b3c028ac62894f777722558f9c3421b52..3c919a536e91b02beaf61538eeb2375a8685c9d5 100644 (file)
@@ -648,12 +648,10 @@ static int lst_test_add_ioctl(struct lstio_test_args *args)
                return -EINVAL;
 
        if (args->lstio_tes_param) {
-               param = kmalloc(args->lstio_tes_param_len, GFP_KERNEL);
-               if (!param)
-                       goto out;
-               if (copy_from_user(param, args->lstio_tes_param,
-                                  args->lstio_tes_param_len)) {
-                       rc = -EFAULT;
+               param = memdup_user(args->lstio_tes_param,
+                                   args->lstio_tes_param_len);
+               if (IS_ERR(param)) {
+                       rc = PTR_ERR(param);
                        goto out;
                }
        }