]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
RDMA: Use copy_struct_from_user() instead of open coding
authorJason Gunthorpe <jgg@nvidia.com>
Tue, 3 Mar 2026 19:49:58 +0000 (15:49 -0400)
committerJason Gunthorpe <jgg@nvidia.com>
Sun, 8 Mar 2026 10:20:24 +0000 (06:20 -0400)
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: Jason Gunthorpe <jgg@nvidia.com>
drivers/infiniband/core/uverbs_cmd.c

index 0bfb16cbc6fab45a90d0d4a0a32380e0daafeec9..f31650ef7bc34d87aa7f162abf2f3075a2fe44d3 100644 (file)
@@ -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;
 }
 
 /*