aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd/mtdchar.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2013-04-19 12:53:07 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2013-04-19 12:53:07 -0400
commit8558e4a26b00225efeb085725bc319f91201b239 (patch)
treeb8f19b7aff84734b7e2e8f912de5227ea436a49a /drivers/mtd/mtdchar.c
parent2323036dfec8ce3ce6e1c86a49a31b039f3300d1 (diff)
vm: convert mtdchar mmap to vm_iomap_memory() helper
This is my example conversion of a few existing mmap users. The mtdchar case is actually disabled right now (and stays disabled), but I did it because it showed up on my "git grep", and I was familiar with the code due to fixing an overflow problem in the code in commit 9c603e53d380 ("mtdchar: fix offset overflow detection"). Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/mtd/mtdchar.c')
-rw-r--r--drivers/mtd/mtdchar.c32
1 files changed, 2 insertions, 30 deletions
diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
index 92ab30ab00dc..61a1b22c05e7 100644
--- a/drivers/mtd/mtdchar.c
+++ b/drivers/mtd/mtdchar.c
@@ -1159,45 +1159,17 @@ static int mtdchar_mmap(struct file *file, struct vm_area_struct *vma)
1159 struct mtd_file_info *mfi = file->private_data; 1159 struct mtd_file_info *mfi = file->private_data;
1160 struct mtd_info *mtd = mfi->mtd; 1160 struct mtd_info *mtd = mfi->mtd;
1161 struct map_info *map = mtd->priv; 1161 struct map_info *map = mtd->priv;
1162 resource_size_t start, off;
1163 unsigned long len, vma_len;
1164 1162
1165 /* This is broken because it assumes the MTD device is map-based 1163 /* This is broken because it assumes the MTD device is map-based
1166 and that mtd->priv is a valid struct map_info. It should be 1164 and that mtd->priv is a valid struct map_info. It should be
1167 replaced with something that uses the mtd_get_unmapped_area() 1165 replaced with something that uses the mtd_get_unmapped_area()
1168 operation properly. */ 1166 operation properly. */
1169 if (0 /*mtd->type == MTD_RAM || mtd->type == MTD_ROM*/) { 1167 if (0 /*mtd->type == MTD_RAM || mtd->type == MTD_ROM*/) {
1170 off = get_vm_offset(vma);
1171 start = map->phys;
1172 len = PAGE_ALIGN((start & ~PAGE_MASK) + map->size);
1173 start &= PAGE_MASK;
1174 vma_len = get_vm_size(vma);
1175
1176 /* Overflow in off+len? */
1177 if (vma_len + off < off)
1178 return -EINVAL;
1179 /* Does it fit in the mapping? */
1180 if (vma_len + off > len)
1181 return -EINVAL;
1182
1183 off += start;
1184 /* Did that overflow? */
1185 if (off < start)
1186 return -EINVAL;
1187 if (set_vm_offset(vma, off) < 0)
1188 return -EINVAL;
1189 vma->vm_flags |= VM_IO | VM_DONTEXPAND | VM_DONTDUMP;
1190
1191#ifdef pgprot_noncached 1168#ifdef pgprot_noncached
1192 if (file->f_flags & O_DSYNC || off >= __pa(high_memory)) 1169 if (file->f_flags & O_DSYNC || map->phys >= __pa(high_memory))
1193 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); 1170 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
1194#endif 1171#endif
1195 if (io_remap_pfn_range(vma, vma->vm_start, off >> PAGE_SHIFT, 1172 return vm_iomap_memory(vma, map->phys, map->size);
1196 vma->vm_end - vma->vm_start,
1197 vma->vm_page_prot))
1198 return -EAGAIN;
1199
1200 return 0;
1201 } 1173 }
1202 return -ENOSYS; 1174 return -ENOSYS;
1203#else 1175#else