Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 12c71c4

Browse files
committed
Merge branch 'vm_ioremap_memory-examples'
I'm going to do an -rc8, so I'm just going to do this rather than delay it any further. They are arguably stable material anyway. * vm_ioremap_memory-examples: mtdchar: remove no-longer-used vma helpers vm: convert snd_pcm_lib_mmap_iomem() to vm_iomap_memory() helper vm: convert fb_mmap to vm_iomap_memory() helper vm: convert mtdchar mmap to vm_iomap_memory() helper vm: convert HPET mmap to vm_iomap_memory() helper
2 parents 830ac85 + f86b11f commit 12c71c4

File tree

4 files changed

+19
-105
lines changed

4 files changed

+19
-105
lines changed

drivers/char/hpet.c

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -373,26 +373,14 @@ static int hpet_mmap(struct file *file, struct vm_area_struct *vma)
373373
struct hpet_dev *devp;
374374
unsigned long addr;
375375

376-
if (((vma->vm_end - vma->vm_start) != PAGE_SIZE) || vma->vm_pgoff)
377-
return -EINVAL;
378-
379376
devp = file->private_data;
380377
addr = devp->hd_hpets->hp_hpet_phys;
381378

382379
if (addr & (PAGE_SIZE - 1))
383380
return -ENOSYS;
384381

385-
vma->vm_flags |= VM_IO;
386382
vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
387-
388-
if (io_remap_pfn_range(vma, vma->vm_start, addr >> PAGE_SHIFT,
389-
PAGE_SIZE, vma->vm_page_prot)) {
390-
printk(KERN_ERR "%s: io_remap_pfn_range failed\n",
391-
__func__);
392-
return -EAGAIN;
393-
}
394-
395-
return 0;
383+
return vm_iomap_memory(vma, addr, PAGE_SIZE);
396384
#else
397385
return -ENOSYS;
398386
#endif

drivers/mtd/mtdchar.c

Lines changed: 2 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,33 +1123,6 @@ static unsigned long mtdchar_get_unmapped_area(struct file *file,
11231123
}
11241124
#endif
11251125

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-
11531126
/*
11541127
* set up a mapping for shared memory segments
11551128
*/
@@ -1159,45 +1132,17 @@ static int mtdchar_mmap(struct file *file, struct vm_area_struct *vma)
11591132
struct mtd_file_info *mfi = file->private_data;
11601133
struct mtd_info *mtd = mfi->mtd;
11611134
struct map_info *map = mtd->priv;
1162-
resource_size_t start, off;
1163-
unsigned long len, vma_len;
11641135

11651136
/* This is broken because it assumes the MTD device is map-based
11661137
and that mtd->priv is a valid struct map_info. It should be
11671138
replaced with something that uses the mtd_get_unmapped_area()
11681139
operation properly. */
11691140
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-
11911141
#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))
11931143
vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
11941144
#endif
1195-
if (io_remap_pfn_range(vma, vma->vm_start, off >> PAGE_SHIFT,
1196-
vma->vm_end - vma->vm_start,
1197-
vma->vm_page_prot))
1198-
return -EAGAIN;
1199-
1200-
return 0;
1145+
return vm_iomap_memory(vma, map->phys, map->size);
12011146
}
12021147
return -ENOSYS;
12031148
#else

drivers/video/fbmem.c

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1373,15 +1373,12 @@ fb_mmap(struct file *file, struct vm_area_struct * vma)
13731373
{
13741374
struct fb_info *info = file_fb_info(file);
13751375
struct fb_ops *fb;
1376-
unsigned long off;
1376+
unsigned long mmio_pgoff;
13771377
unsigned long start;
13781378
u32 len;
13791379

13801380
if (!info)
13811381
return -ENODEV;
1382-
if (vma->vm_pgoff > (~0UL >> PAGE_SHIFT))
1383-
return -EINVAL;
1384-
off = vma->vm_pgoff << PAGE_SHIFT;
13851382
fb = info->fbops;
13861383
if (!fb)
13871384
return -ENODEV;
@@ -1393,32 +1390,24 @@ fb_mmap(struct file *file, struct vm_area_struct * vma)
13931390
return res;
13941391
}
13951392

1396-
/* frame buffer memory */
1393+
/*
1394+
* Ugh. This can be either the frame buffer mapping, or
1395+
* if pgoff points past it, the mmio mapping.
1396+
*/
13971397
start = info->fix.smem_start;
1398-
len = PAGE_ALIGN((start & ~PAGE_MASK) + info->fix.smem_len);
1399-
if (off >= len) {
1400-
/* memory mapped io */
1401-
off -= len;
1402-
if (info->var.accel_flags) {
1403-
mutex_unlock(&info->mm_lock);
1404-
return -EINVAL;
1405-
}
1398+
len = info->fix.smem_len;
1399+
mmio_pgoff = PAGE_ALIGN((start & ~PAGE_MASK) + len) >> PAGE_SHIFT;
1400+
if (vma->vm_pgoff >= mmio_pgoff) {
1401+
vma->vm_pgoff -= mmio_pgoff;
14061402
start = info->fix.mmio_start;
1407-
len = PAGE_ALIGN((start & ~PAGE_MASK) + info->fix.mmio_len);
1403+
len = info->fix.mmio_len;
14081404
}
14091405
mutex_unlock(&info->mm_lock);
1410-
start &= PAGE_MASK;
1411-
if ((vma->vm_end - vma->vm_start + off) > len)
1412-
return -EINVAL;
1413-
off += start;
1414-
vma->vm_pgoff = off >> PAGE_SHIFT;
1415-
/* VM_IO | VM_DONTEXPAND | VM_DONTDUMP are set by io_remap_pfn_range()*/
1406+
14161407
vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
1417-
fb_pgprotect(file, vma, off);
1418-
if (io_remap_pfn_range(vma, vma->vm_start, off >> PAGE_SHIFT,
1419-
vma->vm_end - vma->vm_start, vma->vm_page_prot))
1420-
return -EAGAIN;
1421-
return 0;
1408+
fb_pgprotect(file, vma, start);
1409+
1410+
return vm_iomap_memory(vma, start, len);
14221411
}
14231412

14241413
static int

sound/core/pcm_native.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3222,18 +3222,10 @@ EXPORT_SYMBOL_GPL(snd_pcm_lib_default_mmap);
32223222
int snd_pcm_lib_mmap_iomem(struct snd_pcm_substream *substream,
32233223
struct vm_area_struct *area)
32243224
{
3225-
long size;
3226-
unsigned long offset;
3225+
struct snd_pcm_runtime *runtime = substream->runtime;;
32273226

32283227
area->vm_page_prot = pgprot_noncached(area->vm_page_prot);
3229-
area->vm_flags |= VM_IO;
3230-
size = area->vm_end - area->vm_start;
3231-
offset = area->vm_pgoff << PAGE_SHIFT;
3232-
if (io_remap_pfn_range(area, area->vm_start,
3233-
(substream->runtime->dma_addr + offset) >> PAGE_SHIFT,
3234-
size, area->vm_page_prot))
3235-
return -EAGAIN;
3236-
return 0;
3228+
return vm_iomap_memory(area, runtime->dma_addr, runtime->dma_bytes);
32373229
}
32383230

32393231
EXPORT_SYMBOL(snd_pcm_lib_mmap_iomem);

0 commit comments

Comments
 (0)