Skip to content

Commit

Permalink
romfs: fix romfs_get_unmapped_area() argument check
Browse files Browse the repository at this point in the history
romfs_get_unmapped_area() checks argument `len' without considering
PAGE_ALIGN which will cause do_mmap_pgoff() return -EINVAL error after
commit f67d9b1 ("nommu: add page_align to mmap").

Fix the check by changing it in same way ramfs_nommu_get_unmapped_area()
was changed in ramfs/file-nommu.c.

Signed-off-by: Bob Liu <[email protected]>
Cc: David Howells <[email protected]>
Cc: Paul Mundt <[email protected]>
Acked-by: Greg Ungerer <[email protected]>
Cc: Geert Uytterhoeven <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
aet00 authored and torvalds committed Jun 28, 2011
1 parent 8c95aa6 commit 2b4b248
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions fs/romfs/mmap-nommu.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,18 @@ static unsigned long romfs_get_unmapped_area(struct file *file,
{
struct inode *inode = file->f_mapping->host;
struct mtd_info *mtd = inode->i_sb->s_mtd;
unsigned long isize, offset;
unsigned long isize, offset, maxpages, lpages;

if (!mtd)
goto cant_map_directly;

/* the mapping mustn't extend beyond the EOF */
lpages = (len + PAGE_SIZE - 1) >> PAGE_SHIFT;
isize = i_size_read(inode);
offset = pgoff << PAGE_SHIFT;
if (offset > isize || len > isize || offset > isize - len)

maxpages = (isize + PAGE_SIZE - 1) >> PAGE_SHIFT;
if ((pgoff >= maxpages) || (maxpages - pgoff < lpages))
return (unsigned long) -EINVAL;

/* we need to call down to the MTD layer to do the actual mapping */
Expand Down

0 comments on commit 2b4b248

Please sign in to comment.