diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2013-05-22 10:16:49 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2013-05-22 10:16:49 -0400 |
commit | 94f1be9798c88b030256bdeb533008c3d55ec2c6 (patch) | |
tree | e73baba68b700e50cab2a22025f85c0455df5470 /lib | |
parent | 519fe2ecb755b875d9814cdda19778c2e88c6901 (diff) | |
parent | 6407d75afd08545f2252bb39806ffd3f10c7faac (diff) |
Merge tag 'fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux
Pull virtio fixes from Rusty Russell:
"A build fix and a uapi exposure fix. The build fix is later than I
liked, but my first version broke linux-next due to overzealous header
clean."
* tag 'fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux:
virtio_console: fix uapi header
Hoist memcpy_fromiovec/memcpy_toiovec into lib/
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Makefile | 2 | ||||
-rw-r--r-- | lib/iovec.c | 53 |
2 files changed, 54 insertions, 1 deletions
diff --git a/lib/Makefile b/lib/Makefile index e9c52e1b853a..237721165035 100644 --- a/lib/Makefile +++ b/lib/Makefile | |||
@@ -9,7 +9,7 @@ endif | |||
9 | 9 | ||
10 | lib-y := ctype.o string.o vsprintf.o cmdline.o \ | 10 | lib-y := ctype.o string.o vsprintf.o cmdline.o \ |
11 | rbtree.o radix-tree.o dump_stack.o timerqueue.o\ | 11 | rbtree.o radix-tree.o dump_stack.o timerqueue.o\ |
12 | idr.o int_sqrt.o extable.o \ | 12 | idr.o int_sqrt.o extable.o iovec.o \ |
13 | sha1.o md5.o irq_regs.o reciprocal_div.o argv_split.o \ | 13 | sha1.o md5.o irq_regs.o reciprocal_div.o argv_split.o \ |
14 | proportions.o flex_proportions.o prio_heap.o ratelimit.o show_mem.o \ | 14 | proportions.o flex_proportions.o prio_heap.o ratelimit.o show_mem.o \ |
15 | is_single_threaded.o plist.o decompress.o kobject_uevent.o \ | 15 | is_single_threaded.o plist.o decompress.o kobject_uevent.o \ |
diff --git a/lib/iovec.c b/lib/iovec.c new file mode 100644 index 000000000000..454baa88bf27 --- /dev/null +++ b/lib/iovec.c | |||
@@ -0,0 +1,53 @@ | |||
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 | * Note: this modifies the original iovec. | ||
9 | */ | ||
10 | |||
11 | int memcpy_fromiovec(unsigned char *kdata, struct iovec *iov, int len) | ||
12 | { | ||
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; | ||
22 | } | ||
23 | iov++; | ||
24 | } | ||
25 | |||
26 | return 0; | ||
27 | } | ||
28 | EXPORT_SYMBOL(memcpy_fromiovec); | ||
29 | |||
30 | /* | ||
31 | * Copy kernel to iovec. Returns -EFAULT on error. | ||
32 | * | ||
33 | * Note: this modifies the original iovec. | ||
34 | */ | ||
35 | |||
36 | int memcpy_toiovec(struct iovec *iov, unsigned char *kdata, int len) | ||
37 | { | ||
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; | ||
47 | } | ||
48 | iov++; | ||
49 | } | ||
50 | |||
51 | return 0; | ||
52 | } | ||
53 | EXPORT_SYMBOL(memcpy_toiovec); | ||