From: Ram Pai This patch corrects the errorneous end_index computation in one other place in do_generic_mapping_read(). Signed-off-by: Andrew Morton --- 25-akpm/mm/filemap.c | 12 ++++++++---- 1 files changed, 8 insertions(+), 4 deletions(-) diff -puN mm/filemap.c~re-fix-pagecache-reading-off-by-one mm/filemap.c --- 25/mm/filemap.c~re-fix-pagecache-reading-off-by-one Tue Aug 24 15:39:34 2004 +++ 25-akpm/mm/filemap.c Tue Aug 24 15:39:34 2004 @@ -722,14 +722,18 @@ void do_generic_mapping_read(struct addr offset = *ppos & ~PAGE_CACHE_MASK; isize = i_size_read(inode); - end_index = isize >> PAGE_CACHE_SHIFT; - if (index > end_index) + if (!isize) goto out; + end_index = (isize - 1) >> PAGE_CACHE_SHIFT; + for (;;) { struct page *page; unsigned long nr, ret; + if (index > end_index) + goto out; + cond_resched(); page_cache_readahead(mapping, &ra, filp, index); @@ -827,8 +831,8 @@ readpage: * another truncate extends the file - this is desired though). */ isize = i_size_read(inode); - end_index = isize >> PAGE_CACHE_SHIFT; - if (index > end_index) { + if ( !isize || index > + (end_index = (isize - 1) >> PAGE_CACHE_SHIFT) ) { page_cache_release(page); goto out; } _