Skip to content

Commit 4991e72

Browse files
dedekindDavid Woodhouse
authored andcommitted
romfs: do not use mtd->get_unmapped_area directly
Remove direct usage of mtd->get_unmapped_area. Instead, just call 'mtd_get_unmapped_area()' which will return -EOPNOTSUPP if the function is not implemented, and then test for this code. We also translate -EOPNOTSUPP to -ENOSYS because this return code is probably part of the kernel ABI which we do not want to break. Cc: linux-fsdevel@vger.kernel.org Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com> Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
1 parent cd62127 commit 4991e72

1 file changed

Lines changed: 13 additions & 15 deletions

File tree

‎fs/romfs/mmap-nommu.c‎

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@ static unsigned long romfs_get_unmapped_area(struct file *file,
2828
struct inode *inode = file->f_mapping->host;
2929
struct mtd_info *mtd = inode->i_sb->s_mtd;
3030
unsigned long isize, offset, maxpages, lpages;
31+
int ret;
3132

3233
if (!mtd)
33-
goto cant_map_directly;
34+
return (unsigned long) -ENOSYS;
3435

3536
/* the mapping mustn't extend beyond the EOF */
3637
lpages = (len + PAGE_SIZE - 1) >> PAGE_SHIFT;
@@ -41,23 +42,20 @@ static unsigned long romfs_get_unmapped_area(struct file *file,
4142
if ((pgoff >= maxpages) || (maxpages - pgoff < lpages))
4243
return (unsigned long) -EINVAL;
4344

44-
/* we need to call down to the MTD layer to do the actual mapping */
45-
if (mtd->get_unmapped_area) {
46-
if (addr != 0)
47-
return (unsigned long) -EINVAL;
48-
49-
if (len > mtd->size || pgoff >= (mtd->size >> PAGE_SHIFT))
50-
return (unsigned long) -EINVAL;
45+
if (addr != 0)
46+
return (unsigned long) -EINVAL;
5147

52-
offset += ROMFS_I(inode)->i_dataoffset;
53-
if (offset > mtd->size - len)
54-
return (unsigned long) -EINVAL;
48+
if (len > mtd->size || pgoff >= (mtd->size >> PAGE_SHIFT))
49+
return (unsigned long) -EINVAL;
5550

56-
return mtd_get_unmapped_area(mtd, len, offset, flags);
57-
}
51+
offset += ROMFS_I(inode)->i_dataoffset;
52+
if (offset > mtd->size - len)
53+
return (unsigned long) -EINVAL;
5854

59-
cant_map_directly:
60-
return (unsigned long) -ENOSYS;
55+
ret = mtd_get_unmapped_area(mtd, len, offset, flags);
56+
if (ret == -EOPNOTSUPP)
57+
ret = -ENOSYS;
58+
return (unsigned long) ret;
6159
}
6260

6361
/*

0 commit comments

Comments
 (0)