Linux Headquarters
[ Register ]
[ About us ] [ Home Page ]

Advertisement
[ Kernel ] [ Documentation ] [ Links ] [ Books ]

Advertisement

Kernel v2.6.24.4 /mm/filemap.c

Filename:/mm/filemap.c
Lines Added:14
Lines Deleted:12
Also changed in: (Previous) 2.6.24.4-rc3  2.6.24.4-rc2  2.6.24.4-rc1  2.6.24.2  2.6.24-git22  2.6.24-git21 
(Following) 2.6.24.5  2.6.24.6  2.6.24.7  2.6.25-rc6-git8  2.6.25-rc7  2.6.25-rc8 

Location
[  2.6.24.4
  [  mm
     o  filemap.c

Patch

diff --git a/mm/filemap.c b/mm/filemap.c
index f4d0cde..76b036f 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -1725,17 +1725,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;
 
-      while (bytes) {
-         int copy = min(bytes, iov->iov_len - base);
+      /*
+       * The !iov->iov_len check ensures we skip over unlikely
+       * zero-length segments (without overruning the iovec).
+       */
+      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) {
@@ -1747,14 +1757,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);
 
 /*
@@ -2251,6 +2253,7 @@ again:
 
       cond_resched();
 
+      iov_iter_advance(i, copied);
       if (unlikely(copied == 0)) {
          /*
           * If we were unable to copy any data at all, we must
@@ -2264,7 +2267,6 @@ again:
                   iov_iter_single_seg_count(i));
          goto again;
       }
-      iov_iter_advance(i, copied);
       pos += copied;
       written += copied;
 


Comments: webmaster (at) linuxhq.com.
Advertising: banners (at) linuxhq.com.
Compilation ©1998-2008 Linux Headquarters, Inc.