1 #include <linux/uaccess.h>
2 #include <linux/export.h>
6 * Copy iovec to kernel. Returns -EFAULT on error.
8 * Note: this modifies the original iovec.
11 int memcpy_fromiovec(unsigned char *kdata, struct iovec *iov, int len)
15 int copy = min_t(unsigned int, len, iov->iov_len);
16 if (copy_from_user(kdata, iov->iov_base, copy))
20 iov->iov_base += copy;
28 EXPORT_SYMBOL(memcpy_fromiovec);
31 * Copy kernel to iovec. Returns -EFAULT on error.
34 int memcpy_toiovecend(const struct iovec *iov, unsigned char *kdata,
38 for (; len > 0; ++iov) {
39 /* Skip over the finished iovecs */
40 if (unlikely(offset >= iov->iov_len)) {
41 offset -= iov->iov_len;
44 copy = min_t(unsigned int, iov->iov_len - offset, len);
45 if (copy_to_user(iov->iov_base + offset, kdata, copy))
54 EXPORT_SYMBOL(memcpy_toiovecend);
57 * Copy iovec to kernel. Returns -EFAULT on error.
60 int memcpy_fromiovecend(unsigned char *kdata, const struct iovec *iov,
67 /* Skip over the finished iovecs */
68 while (offset >= iov->iov_len) {
69 offset -= iov->iov_len;
74 u8 __user *base = iov->iov_base + offset;
75 int copy = min_t(unsigned int, len, iov->iov_len - offset);
78 if (copy_from_user(kdata, base, copy))
87 EXPORT_SYMBOL(memcpy_fromiovecend);