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;
}
/*