]> git.hungrycats.org Git - linux/commitdiff
Fix off-by-one bug in page cache reading.
authorLinus Torvalds <torvalds@ppc970.osdl.org>
Sat, 11 Sep 2004 01:50:36 +0000 (18:50 -0700)
committerLinus Torvalds <torvalds@ppc970.osdl.org>
Sat, 11 Sep 2004 01:50:36 +0000 (18:50 -0700)
Just test the end case inside the loop, rather than trying to
be clever and getting it wrong.

mm/filemap.c

index 55fb7b4141e4195d5bd575b2c99281d31289fb1b..272c3e0a6fed2b8cf934aad6a2dabd7c5ce71daa 100644 (file)
@@ -732,16 +732,15 @@ void do_generic_mapping_read(struct address_space *mapping,
                goto out;
 
        end_index = (isize - 1) >> PAGE_CACHE_SHIFT;
-       if (index > end_index)
-               goto out;
-
        for (;;) {
                struct page *page;
                unsigned long nr, ret;
 
                /* nr is the maximum number of bytes to copy from this page */
                nr = PAGE_CACHE_SIZE;
-               if (index == end_index) {
+               if (index >= end_index) {
+                       if (index > end_index)
+                               goto out;
                        nr = ((isize - 1) & ~PAGE_CACHE_MASK) + 1;
                        if (nr <= offset) {
                                goto out;