aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fs/romfs/mmap-nommu.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/fs/romfs/mmap-nommu.c b/fs/romfs/mmap-nommu.c
index f0511e816967..eed99428f104 100644
--- a/fs/romfs/mmap-nommu.c
+++ b/fs/romfs/mmap-nommu.c
@@ -27,14 +27,18 @@ static unsigned long romfs_get_unmapped_area(struct file *file,
27{ 27{
28 struct inode *inode = file->f_mapping->host; 28 struct inode *inode = file->f_mapping->host;
29 struct mtd_info *mtd = inode->i_sb->s_mtd; 29 struct mtd_info *mtd = inode->i_sb->s_mtd;
30 unsigned long isize, offset; 30 unsigned long isize, offset, maxpages, lpages;
31 31
32 if (!mtd) 32 if (!mtd)
33 goto cant_map_directly; 33 goto cant_map_directly;
34 34
35 /* the mapping mustn't extend beyond the EOF */
36 lpages = (len + PAGE_SIZE - 1) >> PAGE_SHIFT;
35 isize = i_size_read(inode); 37 isize = i_size_read(inode);
36 offset = pgoff << PAGE_SHIFT; 38 offset = pgoff << PAGE_SHIFT;
37 if (offset > isize || len > isize || offset > isize - len) 39
40 maxpages = (isize + PAGE_SIZE - 1) >> PAGE_SHIFT;
41 if ((pgoff >= maxpages) || (maxpages - pgoff < lpages))
38 return (unsigned long) -EINVAL; 42 return (unsigned long) -EINVAL;
39 43
40 /* we need to call down to the MTD layer to do the actual mapping */ 44 /* we need to call down to the MTD layer to do the actual mapping */