Skip to content

Commit 0dbca9a

Browse files
author
Al Viro
committed
iov_iter.c: convert copy_from_iter() to iterate_and_advance
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent d271524 commit 0dbca9a

File tree

1 file changed

+15
-91
lines changed

1 file changed

+15
-91
lines changed

mm/iov_iter.c

Lines changed: 15 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -142,51 +142,6 @@ static size_t copy_to_iter_iovec(void *from, size_t bytes, struct iov_iter *i)
142142
return wanted - bytes;
143143
}
144144

145-
static size_t copy_from_iter_iovec(void *to, size_t bytes, struct iov_iter *i)
146-
{
147-
size_t skip, copy, left, wanted;
148-
const struct iovec *iov;
149-
char __user *buf;
150-
151-
if (unlikely(bytes > i->count))
152-
bytes = i->count;
153-
154-
if (unlikely(!bytes))
155-
return 0;
156-
157-
wanted = bytes;
158-
iov = i->iov;
159-
skip = i->iov_offset;
160-
buf = iov->iov_base + skip;
161-
copy = min(bytes, iov->iov_len - skip);
162-
163-
left = __copy_from_user(to, buf, copy);
164-
copy -= left;
165-
skip += copy;
166-
to += copy;
167-
bytes -= copy;
168-
while (unlikely(!left && bytes)) {
169-
iov++;
170-
buf = iov->iov_base;
171-
copy = min(bytes, iov->iov_len);
172-
left = __copy_from_user(to, buf, copy);
173-
copy -= left;
174-
skip = copy;
175-
to += copy;
176-
bytes -= copy;
177-
}
178-
179-
if (skip == iov->iov_len) {
180-
iov++;
181-
skip = 0;
182-
}
183-
i->count -= wanted - bytes;
184-
i->nr_segs -= iov - i->iov;
185-
i->iov = iov;
186-
i->iov_offset = skip;
187-
return wanted - bytes;
188-
}
189-
190145
static size_t copy_page_to_iter_iovec(struct page *page, size_t offset, size_t bytes,
191146
struct iov_iter *i)
192147
{
@@ -444,48 +399,6 @@ static size_t copy_to_iter_bvec(void *from, size_t bytes, struct iov_iter *i)
444399
return wanted - bytes;
445400
}
446401

447-
static size_t copy_from_iter_bvec(void *to, size_t bytes, struct iov_iter *i)
448-
{
449-
size_t skip, copy, wanted;
450-
const struct bio_vec *bvec;
451-
452-
if (unlikely(bytes > i->count))
453-
bytes = i->count;
454-
455-
if (unlikely(!bytes))
456-
return 0;
457-
458-
wanted = bytes;
459-
bvec = i->bvec;
460-
skip = i->iov_offset;
461-
462-
copy = min(bytes, bvec->bv_len - skip);
463-
464-
memcpy_from_page(to, bvec->bv_page, bvec->bv_offset + skip, copy);
465-
466-
to += copy;
467-
skip += copy;
468-
bytes -= copy;
469-
470-
while (bytes) {
471-
bvec++;
472-
copy = min(bytes, (size_t)bvec->bv_len);
473-
memcpy_from_page(to, bvec->bv_page, bvec->bv_offset, copy);
474-
skip = copy;
475-
to += copy;
476-
bytes -= copy;
477-
}
478-
if (skip == bvec->bv_len) {
479-
bvec++;
480-
skip = 0;
481-
}
482-
i->count -= wanted;
483-
i->nr_segs -= bvec - i->bvec;
484-
i->bvec = bvec;
485-
i->iov_offset = skip;
486-
return wanted;
487-
}
488-
489402
size_t copy_to_iter(void *addr, size_t bytes, struct iov_iter *i)
490403
{
491404
if (i->type & ITER_BVEC)
@@ -497,10 +410,21 @@ EXPORT_SYMBOL(copy_to_iter);
497410

498411
size_t copy_from_iter(void *addr, size_t bytes, struct iov_iter *i)
499412
{
500-
if (i->type & ITER_BVEC)
501-
return copy_from_iter_bvec(addr, bytes, i);
502-
else
503-
return copy_from_iter_iovec(addr, bytes, i);
413+
char *to = addr;
414+
if (unlikely(bytes > i->count))
415+
bytes = i->count;
416+
417+
if (unlikely(!bytes))
418+
return 0;
419+
420+
iterate_and_advance(i, bytes, v,
421+
__copy_from_user((to += v.iov_len) - v.iov_len, v.iov_base,
422+
v.iov_len),
423+
memcpy_from_page((to += v.bv_len) - v.bv_len, v.bv_page,
424+
v.bv_offset, v.bv_len)
425+
)
426+
427+
return bytes;
504428
}
505429
EXPORT_SYMBOL(copy_from_iter);
506430

0 commit comments

Comments
 (0)