]> Pileus Git - ~andy/linux/blobdiff - fs/romfs/mmap-nommu.c
Merge git://git.kernel.org/pub/scm/linux/kernel/git/nab/target-pending
[~andy/linux] / fs / romfs / mmap-nommu.c
index eed99428f1046d6a3dbd6191340d9d70e18b7ce0..f373bde8f545da481ba0a7caa873271dd599b30d 100644 (file)
@@ -28,9 +28,10 @@ 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, maxpages, lpages;
+       int ret;
 
        if (!mtd)
-               goto cant_map_directly;
+               return (unsigned long) -ENOSYS;
 
        /* the mapping mustn't extend beyond the EOF */
        lpages = (len + PAGE_SIZE - 1) >> PAGE_SHIFT;
@@ -41,23 +42,23 @@ static unsigned long romfs_get_unmapped_area(struct file *file,
        if ((pgoff >= maxpages) || (maxpages - pgoff < lpages))
                return (unsigned long) -EINVAL;
 
-       /* we need to call down to the MTD layer to do the actual mapping */
-       if (mtd->get_unmapped_area) {
-               if (addr != 0)
-                       return (unsigned long) -EINVAL;
-
-               if (len > mtd->size || pgoff >= (mtd->size >> PAGE_SHIFT))
-                       return (unsigned long) -EINVAL;
+       if (addr != 0)
+               return (unsigned long) -EINVAL;
 
-               offset += ROMFS_I(inode)->i_dataoffset;
-               if (offset > mtd->size - len)
-                       return (unsigned long) -EINVAL;
+       if (len > mtd->size || pgoff >= (mtd->size >> PAGE_SHIFT))
+               return (unsigned long) -EINVAL;
 
-               return mtd->get_unmapped_area(mtd, len, offset, flags);
-       }
+       offset += ROMFS_I(inode)->i_dataoffset;
+       if (offset >= mtd->size)
+               return (unsigned long) -EINVAL;
+       /* the mapping mustn't extend beyond the EOF */
+       if ((offset + len) > mtd->size)
+               len = mtd->size - offset;
 
-cant_map_directly:
-       return (unsigned long) -ENOSYS;
+       ret = mtd_get_unmapped_area(mtd, len, offset, flags);
+       if (ret == -EOPNOTSUPP)
+               ret = -ENOSYS;
+       return (unsigned long) ret;
 }
 
 /*