Commit 38a6e557 authored by Jason Gunthorpe's avatar Jason Gunthorpe
Browse files

RDMA: Use copy_struct_from_user() instead of open coding

This entire function is just open coding copy_struct_from_user(), call it
directly, it is faster anyhow.

Link: https://patch.msgid.link/r/1-v3-bd56dd443069+49-bnxt_re_uapi_jgg@nvidia.com


Signed-off-by: default avatarJason Gunthorpe <jgg@nvidia.com>
parent 75b864f0
Loading
Loading
Loading
Loading
+6 −18
Original line number Diff line number Diff line
@@ -83,28 +83,16 @@ static int uverbs_response(struct uverbs_attr_bundle *attrs, const void *resp,
	return 0;
}

/*
 * Copy a request from userspace. If the provided 'req' is larger than the
 * user buffer then the user buffer is zero extended into the 'req'. If 'req'
 * is smaller than the user buffer then the uncopied bytes in the user buffer
 * must be zero.
 */
static int uverbs_request(struct uverbs_attr_bundle *attrs, void *req,
			  size_t req_len)
{
	if (copy_from_user(req, attrs->ucore.inbuf,
			   min(attrs->ucore.inlen, req_len)))
		return -EFAULT;
	int ret;

	if (attrs->ucore.inlen < req_len) {
		memset(req + attrs->ucore.inlen, 0,
		       req_len - attrs->ucore.inlen);
	} else if (attrs->ucore.inlen > req_len) {
		if (!ib_is_buffer_cleared(attrs->ucore.inbuf + req_len,
					  attrs->ucore.inlen - req_len))
			return -EOPNOTSUPP;
	}
	return 0;
	ret = copy_struct_from_user(req, req_len, attrs->ucore.inbuf,
				    attrs->ucore.inlen);
	if (ret == -E2BIG)
		ret = -EOPNOTSUPP;
	return ret;
}

/*