diff options
Diffstat (limited to 'drivers/mtd/mtdchar.c')
-rw-r--r-- | drivers/mtd/mtdchar.c | 59 |
1 files changed, 2 insertions, 57 deletions
diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c index 92ab30ab00dc..dc571ebc1aa0 100644 --- a/drivers/mtd/mtdchar.c +++ b/drivers/mtd/mtdchar.c | |||
@@ -1123,33 +1123,6 @@ static unsigned long mtdchar_get_unmapped_area(struct file *file, | |||
1123 | } | 1123 | } |
1124 | #endif | 1124 | #endif |
1125 | 1125 | ||
1126 | static inline unsigned long get_vm_size(struct vm_area_struct *vma) | ||
1127 | { | ||
1128 | return vma->vm_end - vma->vm_start; | ||
1129 | } | ||
1130 | |||
1131 | static inline resource_size_t get_vm_offset(struct vm_area_struct *vma) | ||
1132 | { | ||
1133 | return (resource_size_t) vma->vm_pgoff << PAGE_SHIFT; | ||
1134 | } | ||
1135 | |||
1136 | /* | ||
1137 | * Set a new vm offset. | ||
1138 | * | ||
1139 | * Verify that the incoming offset really works as a page offset, | ||
1140 | * and that the offset and size fit in a resource_size_t. | ||
1141 | */ | ||
1142 | static inline int set_vm_offset(struct vm_area_struct *vma, resource_size_t off) | ||
1143 | { | ||
1144 | pgoff_t pgoff = off >> PAGE_SHIFT; | ||
1145 | if (off != (resource_size_t) pgoff << PAGE_SHIFT) | ||
1146 | return -EINVAL; | ||
1147 | if (off + get_vm_size(vma) - 1 < off) | ||
1148 | return -EINVAL; | ||
1149 | vma->vm_pgoff = pgoff; | ||
1150 | return 0; | ||
1151 | } | ||
1152 | |||
1153 | /* | 1126 | /* |
1154 | * set up a mapping for shared memory segments | 1127 | * set up a mapping for shared memory segments |
1155 | */ | 1128 | */ |
@@ -1159,45 +1132,17 @@ static int mtdchar_mmap(struct file *file, struct vm_area_struct *vma) | |||
1159 | struct mtd_file_info *mfi = file->private_data; | 1132 | struct mtd_file_info *mfi = file->private_data; |
1160 | struct mtd_info *mtd = mfi->mtd; | 1133 | struct mtd_info *mtd = mfi->mtd; |
1161 | struct map_info *map = mtd->priv; | 1134 | struct map_info *map = mtd->priv; |
1162 | resource_size_t start, off; | ||
1163 | unsigned long len, vma_len; | ||
1164 | 1135 | ||
1165 | /* This is broken because it assumes the MTD device is map-based | 1136 | /* 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 | 1137 | and that mtd->priv is a valid struct map_info. It should be |
1167 | replaced with something that uses the mtd_get_unmapped_area() | 1138 | replaced with something that uses the mtd_get_unmapped_area() |
1168 | operation properly. */ | 1139 | operation properly. */ |
1169 | if (0 /*mtd->type == MTD_RAM || mtd->type == MTD_ROM*/) { | 1140 | 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 | 1141 | #ifdef pgprot_noncached |
1192 | if (file->f_flags & O_DSYNC || off >= __pa(high_memory)) | 1142 | if (file->f_flags & O_DSYNC || map->phys >= __pa(high_memory)) |
1193 | vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); | 1143 | vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); |
1194 | #endif | 1144 | #endif |
1195 | if (io_remap_pfn_range(vma, vma->vm_start, off >> PAGE_SHIFT, | 1145 | 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 | } | 1146 | } |
1202 | return -ENOSYS; | 1147 | return -ENOSYS; |
1203 | #else | 1148 | #else |