[PATCH v2 01/13] RDMA: Use copy_struct_from_user() instead of open coding

Jason Gunthorpe
2026-02-27T01:36:11Z

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

Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
drivers/infiniband/core/uverbs_cmd.c | 24 ++++++------------------
1 file changed, 6 insertions(+), 18 deletions(-)

diff --git a/drivers/infiniband/core/uverbs_cmd.c b/drivers/infiniband/core/uverbs_cmd.c
index 758ed4ae5f7a85..5e5f049c3845a3 100644
--- a/drivers/infiniband/core/uverbs_cmd.c
+++ b/drivers/infiniband/core/uverbs_cmd.c
@@ -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;
}

/*
--
2.43.0