Skip to content

Commit 7314e61

Browse files
committed
Fix a few incorrectly checked [io_]remap_pfn_range() calls
Nico Golde reports a few straggling uses of [io_]remap_pfn_range() that really should use the vm_iomap_memory() helper. This trivially converts two of them to the helper, and comments about why the third one really needs to continue to use remap_pfn_range(), and adds the missing size check. Reported-by: Nico Golde <[email protected]> Cc: [email protected] Signed-off-by: Linus Torvalds <[email protected].
1 parent f9ec2e6 commit 7314e61

File tree

3 files changed

+17
-49
lines changed

3 files changed

+17
-49
lines changed

drivers/uio/uio.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -642,16 +642,29 @@ static int uio_mmap_physical(struct vm_area_struct *vma)
642642
{
643643
struct uio_device *idev = vma->vm_private_data;
644644
int mi = uio_find_mem_index(vma);
645+
struct uio_mem *mem;
645646
if (mi < 0)
646647
return -EINVAL;
648+
mem = idev->info->mem + mi;
647649

648-
vma->vm_ops = &uio_physical_vm_ops;
650+
if (vma->vm_end - vma->vm_start > mem->size)
651+
return -EINVAL;
649652

653+
vma->vm_ops = &uio_physical_vm_ops;
650654
vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
651655

656+
/*
657+
* We cannot use the vm_iomap_memory() helper here,
658+
* because vma->vm_pgoff is the map index we looked
659+
* up above in uio_find_mem_index(), rather than an
660+
* actual page offset into the mmap.
661+
*
662+
* So we just do the physical mmap without a page
663+
* offset.
664+
*/
652665
return remap_pfn_range(vma,
653666
vma->vm_start,
654-
idev->info->mem[mi].addr >> PAGE_SHIFT,
667+
mem->addr >> PAGE_SHIFT,
655668
vma->vm_end - vma->vm_start,
656669
vma->vm_page_prot);
657670
}

drivers/video/au1100fb.c

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -361,37 +361,13 @@ void au1100fb_fb_rotate(struct fb_info *fbi, int angle)
361361
int au1100fb_fb_mmap(struct fb_info *fbi, struct vm_area_struct *vma)
362362
{
363363
struct au1100fb_device *fbdev;
364-
unsigned int len;
365-
unsigned long start=0, off;
366364

367365
fbdev = to_au1100fb_device(fbi);
368366

369-
if (vma->vm_pgoff > (~0UL >> PAGE_SHIFT)) {
370-
return -EINVAL;
371-
}
372-
373-
start = fbdev->fb_phys & PAGE_MASK;
374-
len = PAGE_ALIGN((start & ~PAGE_MASK) + fbdev->fb_len);
375-
376-
off = vma->vm_pgoff << PAGE_SHIFT;
377-
378-
if ((vma->vm_end - vma->vm_start + off) > len) {
379-
return -EINVAL;
380-
}
381-
382-
off += start;
383-
vma->vm_pgoff = off >> PAGE_SHIFT;
384-
385367
vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
386368
pgprot_val(vma->vm_page_prot) |= (6 << 9); //CCA=6
387369

388-
if (io_remap_pfn_range(vma, vma->vm_start, off >> PAGE_SHIFT,
389-
vma->vm_end - vma->vm_start,
390-
vma->vm_page_prot)) {
391-
return -EAGAIN;
392-
}
393-
394-
return 0;
370+
return vm_iomap_memory(vma, fbdev->fb_phys, fbdev->fb_len);
395371
}
396372

397373
static struct fb_ops au1100fb_ops =

drivers/video/au1200fb.c

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,34 +1233,13 @@ static int au1200fb_fb_blank(int blank_mode, struct fb_info *fbi)
12331233
* method mainly to allow the use of the TLB streaming flag (CCA=6)
12341234
*/
12351235
static int au1200fb_fb_mmap(struct fb_info *info, struct vm_area_struct *vma)
1236-
12371236
{
1238-
unsigned int len;
1239-
unsigned long start=0, off;
12401237
struct au1200fb_device *fbdev = info->par;
12411238

1242-
if (vma->vm_pgoff > (~0UL >> PAGE_SHIFT)) {
1243-
return -EINVAL;
1244-
}
1245-
1246-
start = fbdev->fb_phys & PAGE_MASK;
1247-
len = PAGE_ALIGN((start & ~PAGE_MASK) + fbdev->fb_len);
1248-
1249-
off = vma->vm_pgoff << PAGE_SHIFT;
1250-
1251-
if ((vma->vm_end - vma->vm_start + off) > len) {
1252-
return -EINVAL;
1253-
}
1254-
1255-
off += start;
1256-
vma->vm_pgoff = off >> PAGE_SHIFT;
1257-
12581239
vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
12591240
pgprot_val(vma->vm_page_prot) |= _CACHE_MASK; /* CCA=7 */
12601241

1261-
return io_remap_pfn_range(vma, vma->vm_start, off >> PAGE_SHIFT,
1262-
vma->vm_end - vma->vm_start,
1263-
vma->vm_page_prot);
1242+
return vm_iomap_memory(vma, fbdev->fb_phys, fbdev->fb_len);
12641243
}
12651244

12661245
static void set_global(u_int cmd, struct au1200_lcd_global_regs_t *pdata)

0 commit comments

Comments
 (0)