vhost: don't bother copying iovecs in handle_rx(), kill memcpy_toiovecend()
[firefly-linux-kernel-4.4.55.git] / lib / iovec.c
1 #include <linux/uaccess.h>
2 #include <linux/export.h>
3 #include <linux/uio.h>
4
5 /*
6  *      Copy iovec to kernel. Returns -EFAULT on error.
7  */
8
9 int memcpy_fromiovecend(unsigned char *kdata, const struct iovec *iov,
10                         int offset, int len)
11 {
12         /* No data? Done! */
13         if (len == 0)
14                 return 0;
15
16         /* Skip over the finished iovecs */
17         while (offset >= iov->iov_len) {
18                 offset -= iov->iov_len;
19                 iov++;
20         }
21
22         while (len > 0) {
23                 u8 __user *base = iov->iov_base + offset;
24                 int copy = min_t(unsigned int, len, iov->iov_len - offset);
25
26                 offset = 0;
27                 if (copy_from_user(kdata, base, copy))
28                         return -EFAULT;
29                 len -= copy;
30                 kdata += copy;
31                 iov++;
32         }
33
34         return 0;
35 }
36 EXPORT_SYMBOL(memcpy_fromiovecend);