scripts/gen_initramfs_list.sh: fix flags for initramfs LZ4 compression
[linux/fpc-iii.git] / lib / iovec.c
blob454baa88bf27dd18aa896be8930652f75e3ddad9
1 #include <linux/uaccess.h>
2 #include <linux/export.h>
3 #include <linux/uio.h>
5 /*
6 * Copy iovec to kernel. Returns -EFAULT on error.
8 * Note: this modifies the original iovec.
9 */
11 int memcpy_fromiovec(unsigned char *kdata, struct iovec *iov, int len)
13 while (len > 0) {
14 if (iov->iov_len) {
15 int copy = min_t(unsigned int, len, iov->iov_len);
16 if (copy_from_user(kdata, iov->iov_base, copy))
17 return -EFAULT;
18 len -= copy;
19 kdata += copy;
20 iov->iov_base += copy;
21 iov->iov_len -= copy;
23 iov++;
26 return 0;
28 EXPORT_SYMBOL(memcpy_fromiovec);
31 * Copy kernel to iovec. Returns -EFAULT on error.
33 * Note: this modifies the original iovec.
36 int memcpy_toiovec(struct iovec *iov, unsigned char *kdata, int len)
38 while (len > 0) {
39 if (iov->iov_len) {
40 int copy = min_t(unsigned int, iov->iov_len, len);
41 if (copy_to_user(iov->iov_base, kdata, copy))
42 return -EFAULT;
43 kdata += copy;
44 len -= copy;
45 iov->iov_len -= copy;
46 iov->iov_base += copy;
48 iov++;
51 return 0;
53 EXPORT_SYMBOL(memcpy_toiovec);