RDMA/ucma: Convert open-coded equivalent to memdup_user()
authorRoland Dreier <roland@purestorage.com>
Fri, 27 Jul 2012 20:27:45 +0000 (13:27 -0700)
committerRoland Dreier <roland@purestorage.com>
Fri, 27 Jul 2012 20:27:45 +0000 (13:27 -0700)
Suggested by scripts/coccinelle/api/memdup_user.cocci.

Reported-by: Fengguang Wu <fengguang.wu@intel.com>
Signed-off-by: Roland Dreier <roland@purestorage.com>
drivers/infiniband/core/ucma.c

index 893cb879462cfe584ea26c314b838bdcd3e3a41f..6bf8504228957eb8341342c16cfa9b88a234c8bd 100644 (file)
@@ -1002,23 +1002,18 @@ static ssize_t ucma_set_option(struct ucma_file *file, const char __user *inbuf,
        if (IS_ERR(ctx))
                return PTR_ERR(ctx);
 
-       optval = kmalloc(cmd.optlen, GFP_KERNEL);
-       if (!optval) {
-               ret = -ENOMEM;
-               goto out1;
-       }
-
-       if (copy_from_user(optval, (void __user *) (unsigned long) cmd.optval,
-                          cmd.optlen)) {
-               ret = -EFAULT;
-               goto out2;
+       optval = memdup_user((void __user *) (unsigned long) cmd.optval,
+                            cmd.optlen);
+       if (IS_ERR(optval)) {
+               ret = PTR_ERR(optval);
+               goto out;
        }
 
        ret = ucma_set_option_level(ctx, cmd.level, cmd.optname, optval,
                                    cmd.optlen);
-out2:
        kfree(optval);
-out1:
+
+out:
        ucma_put_ctx(ctx);
        return ret;
 }