Commit 8558e4a2 authored by Linus Torvalds's avatar Linus Torvalds

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 9c603e53
("mtdchar: fix offset overflow detection").
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 2323036d
...@@ -1159,45 +1159,17 @@ static int mtdchar_mmap(struct file *file, struct vm_area_struct *vma) ...@@ -1159,45 +1159,17 @@ static int mtdchar_mmap(struct file *file, struct vm_area_struct *vma)
struct mtd_file_info *mfi = file->private_data; struct mtd_file_info *mfi = file->private_data;
struct mtd_info *mtd = mfi->mtd; struct mtd_info *mtd = mfi->mtd;
struct map_info *map = mtd->priv; struct map_info *map = mtd->priv;
resource_size_t start, off;
unsigned long len, vma_len;
/* This is broken because it assumes the MTD device is map-based /* This is broken because it assumes the MTD device is map-based
and that mtd->priv is a valid struct map_info. It should be and that mtd->priv is a valid struct map_info. It should be
replaced with something that uses the mtd_get_unmapped_area() replaced with something that uses the mtd_get_unmapped_area()
operation properly. */ operation properly. */
if (0 /*mtd->type == MTD_RAM || mtd->type == MTD_ROM*/) { if (0 /*mtd->type == MTD_RAM || mtd->type == MTD_ROM*/) {
off = get_vm_offset(vma);
start = map->phys;
len = PAGE_ALIGN((start & ~PAGE_MASK) + map->size);
start &= PAGE_MASK;
vma_len = get_vm_size(vma);
/* Overflow in off+len? */
if (vma_len + off < off)
return -EINVAL;
/* Does it fit in the mapping? */
if (vma_len + off > len)
return -EINVAL;
off += start;
/* Did that overflow? */
if (off < start)
return -EINVAL;
if (set_vm_offset(vma, off) < 0)
return -EINVAL;
vma->vm_flags |= VM_IO | VM_DONTEXPAND | VM_DONTDUMP;
#ifdef pgprot_noncached #ifdef pgprot_noncached
if (file->f_flags & O_DSYNC || off >= __pa(high_memory)) if (file->f_flags & O_DSYNC || map->phys >= __pa(high_memory))
vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
#endif #endif
if (io_remap_pfn_range(vma, vma->vm_start, off >> PAGE_SHIFT, return vm_iomap_memory(vma, map->phys, map->size);
vma->vm_end - vma->vm_start,
vma->vm_page_prot))
return -EAGAIN;
return 0;
} }
return -ENOSYS; return -ENOSYS;
#else #else
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment