From a0b8560687181ffd3eada58e1495b55b0226de29 Mon Sep 17 00:00:00 2001 From: Nick Piggin Date: Mon, 10 Mar 2008 11:43:59 -0700 Subject: [PATCH] --- yaml --- r: 87096 b: refs/heads/master c: f7009264c519603b8ec67c881bd368a56703cfc9 h: refs/heads/master v: v3 --- [refs] | 2 +- trunk/mm/filemap.c | 22 ++++++++++------------ 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/[refs] b/[refs] index 08734c6fef32..e4eb3e31ec96 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: 21bbb39c376ce6beeeb549d155f0d53dc76ed000 +refs/heads/master: f7009264c519603b8ec67c881bd368a56703cfc9 diff --git a/trunk/mm/filemap.c b/trunk/mm/filemap.c index ab98557e228e..df343d1e6345 100644 --- a/trunk/mm/filemap.c +++ b/trunk/mm/filemap.c @@ -1742,21 +1742,27 @@ size_t iov_iter_copy_from_user(struct page *page, } EXPORT_SYMBOL(iov_iter_copy_from_user); -static void __iov_iter_advance_iov(struct iov_iter *i, size_t bytes) +void iov_iter_advance(struct iov_iter *i, size_t bytes) { + BUG_ON(i->count < bytes); + if (likely(i->nr_segs == 1)) { i->iov_offset += bytes; + i->count -= bytes; } else { const struct iovec *iov = i->iov; size_t base = i->iov_offset; /* * The !iov->iov_len check ensures we skip over unlikely - * zero-length segments. + * zero-length segments (without overruning the iovec). */ - while (bytes || !iov->iov_len) { - int copy = min(bytes, iov->iov_len - base); + while (bytes || unlikely(!iov->iov_len && i->count)) { + int copy; + copy = min(bytes, iov->iov_len - base); + BUG_ON(!i->count || i->count < copy); + i->count -= copy; bytes -= copy; base += copy; if (iov->iov_len == base) { @@ -1768,14 +1774,6 @@ static void __iov_iter_advance_iov(struct iov_iter *i, size_t bytes) i->iov_offset = base; } } - -void iov_iter_advance(struct iov_iter *i, size_t bytes) -{ - BUG_ON(i->count < bytes); - - __iov_iter_advance_iov(i, bytes); - i->count -= bytes; -} EXPORT_SYMBOL(iov_iter_advance); /*