RDMA/uverbs: Optimize clearing of extra bytes in response
authorLeon Romanovsky <leonro@mellanox.com>
Tue, 11 Dec 2018 09:41:05 +0000 (11:41 +0200)
committerJason Gunthorpe <jgg@mellanox.com>
Tue, 11 Dec 2018 21:38:17 +0000 (14:38 -0700)
Clear extra bytes in response in batch manner instead
of doing it per-byte.

Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
Reviewed-by: Yuval Shaia <yuval.shaia@oracle.com>
Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
drivers/infiniband/core/uverbs_cmd.c

index b707495..7f10ead 100644 (file)
 static int uverbs_response(struct uverbs_attr_bundle *attrs, const void *resp,
                           size_t resp_len)
 {
-       u8 __user *cur = attrs->ucore.outbuf + resp_len;
-       u8 __user *end = attrs->ucore.outbuf + attrs->ucore.outlen;
        int ret;
 
        if (copy_to_user(attrs->ucore.outbuf, resp,
                         min(attrs->ucore.outlen, resp_len)))
                return -EFAULT;
 
-       /* Zero fill any extra memory that user space might have provided */
-       for (; cur < end; cur++) {
-               ret = put_user(0, cur);
+       if (resp_len < attrs->ucore.outlen) {
+               /*
+                * Zero fill any extra memory that user
+                * space might have provided.
+                */
+               ret = clear_user(attrs->ucore.outbuf + resp_len,
+                                attrs->ucore.outlen - resp_len);
                if (ret)
-                       return ret;
+                       return -EFAULT;
        }
 
        return 0;