Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0764c76e authored by Roland Dreier's avatar Roland Dreier
Browse files

RDMA/ucma: Convert open-coded equivalent to memdup_user()



Suggested by scripts/coccinelle/api/memdup_user.cocci.

Reported-by: default avatarFengguang Wu <fengguang.wu@intel.com>
Signed-off-by: default avatarRoland Dreier <roland@purestorage.com>
parent 4e289045
Loading
Loading
Loading
Loading
+7 −12
Original line number Original line Diff line number Diff line
@@ -1002,23 +1002,18 @@ static ssize_t ucma_set_option(struct ucma_file *file, const char __user *inbuf,
	if (IS_ERR(ctx))
	if (IS_ERR(ctx))
		return PTR_ERR(ctx);
		return PTR_ERR(ctx);


	optval = kmalloc(cmd.optlen, GFP_KERNEL);
	optval = memdup_user((void __user *) (unsigned long) cmd.optval,
	if (!optval) {
			     cmd.optlen);
		ret = -ENOMEM;
	if (IS_ERR(optval)) {
		goto out1;
		ret = PTR_ERR(optval);
	}
		goto out;

	if (copy_from_user(optval, (void __user *) (unsigned long) cmd.optval,
			   cmd.optlen)) {
		ret = -EFAULT;
		goto out2;
	}
	}


	ret = ucma_set_option_level(ctx, cmd.level, cmd.optname, optval,
	ret = ucma_set_option_level(ctx, cmd.level, cmd.optname, optval,
				    cmd.optlen);
				    cmd.optlen);
out2:
	kfree(optval);
	kfree(optval);
out1:

out:
	ucma_put_ctx(ctx);
	ucma_put_ctx(ctx);
	return ret;
	return ret;
}
}