Commit e1f40fc0 authored by Arjan van de Ven's avatar Arjan van de Ven Committed by Linus Torvalds

[PATCH] vmalloc_to_page helper

After William did the remap_pfn_range change, a very common pattern became:
	page = page_to_pfn(vmalloc_to_page((void *)pos));
	if (remap_pfn_range(vma, start, page, PAGE_SIZE, PAGE_SHARED)) {

the patch below adds a very simple helper, vmalloc_to_pfn() to simplify this
a bit.
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 0e507913
......@@ -3781,7 +3781,7 @@ static int cpia_mmap(struct file *file, struct vm_area_struct *vma)
pos = (unsigned long)(cam->frame_buf);
while (size > 0) {
page = page_to_pfn(vmalloc_to_page((void *)pos));
page = vmalloc_to_pfn((void *)pos);
if (remap_pfn_range(vma, start, page, PAGE_SIZE, PAGE_SHARED)) {
up(&cam->busy_lock);
return -EAGAIN;
......
......@@ -1188,7 +1188,7 @@ static int meye_mmap(struct file *file, struct vm_area_struct *vma) {
pos = (unsigned long)meye.grab_fbuffer;
while (size > 0) {
page = page_to_pfn(vmalloc_to_page((void *)pos));
page = vmalloc_to_pfn((void *)pos);
if (remap_pfn_range(vma, start, page, PAGE_SIZE, PAGE_SHARED)) {
up(&meye.lock);
return -EAGAIN;
......
......@@ -4756,7 +4756,7 @@ ov51x_v4l1_mmap(struct file *file, struct vm_area_struct *vma)
pos = (unsigned long)ov->fbuf;
while (size > 0) {
page = page_to_pfn(vmalloc_to_page((void *)pos));
page = vmalloc_to_pfn((void *)pos);
if (remap_pfn_range(vma, start, page, PAGE_SIZE, PAGE_SHARED)) {
up(&ov->lock);
return -EAGAIN;
......
......@@ -1168,7 +1168,7 @@ static int se401_mmap(struct file *file, struct vm_area_struct *vma)
}
pos = (unsigned long)se401->fbuf;
while (size > 0) {
page = page_to_pfn(vmalloc_to_page((void *)pos));
page = vmalloc_to_pfn((void *)pos);
if (remap_pfn_range(vma, start, page, PAGE_SIZE, PAGE_SHARED)) {
up(&se401->lock);
return -EAGAIN;
......
......@@ -1555,7 +1555,7 @@ static int sn9c102_mmap(struct file* filp, struct vm_area_struct *vma)
pos = (unsigned long)cam->frame[i].bufmem;
while (size > 0) { /* size is page-aligned */
page = page_to_pfn(vmalloc_to_page((void *)pos));
page = vmalloc_to_pfn((void *)pos);
if (remap_pfn_range(vma, start, page, PAGE_SIZE,
vma->vm_page_prot)) {
up(&cam->fileop_sem);
......
......@@ -1277,7 +1277,7 @@ static int stv680_mmap (struct file *file, struct vm_area_struct *vma)
}
pos = (unsigned long) stv680->fbuf;
while (size > 0) {
page = page_to_pfn(vmalloc_to_page((void *)pos));
page = vmalloc_to_pfn((void *)pos);
if (remap_pfn_range(vma, start, page, PAGE_SIZE, PAGE_SHARED)) {
up (&stv680->lock);
return -EAGAIN;
......
......@@ -1153,7 +1153,7 @@ static int usbvideo_v4l_mmap(struct file *file, struct vm_area_struct *vma)
pos = (unsigned long) uvd->fbuf;
while (size > 0) {
page = page_to_pfn(vmalloc_to_page((void *)pos));
page = vmalloc_to_pfn((void *)pos);
if (remap_pfn_range(vma, start, page, PAGE_SIZE, PAGE_SHARED))
return -EAGAIN;
......
......@@ -1045,7 +1045,7 @@ vicam_mmap(struct file *file, struct vm_area_struct *vma)
pos = (unsigned long)cam->framebuf;
while (size > 0) {
page = page_to_pfn(vmalloc_to_page((void *)pos));
page = vmalloc_to_pfn((void *)pos);
if (remap_pfn_range(vma, start, page, PAGE_SIZE, PAGE_SHARED))
return -EAGAIN;
......
......@@ -2904,7 +2904,7 @@ static int w9968cf_mmap(struct file* filp, struct vm_area_struct *vma)
return -EINVAL;
while (vsize > 0) {
page = page_to_pfn(vmalloc_to_page((void *)pos));
page = vmalloc_to_pfn((void *)pos);
if (remap_pfn_range(vma, start, page + vma->vm_pgoff,
PAGE_SIZE, vma->vm_page_prot))
return -EAGAIN;
......
......@@ -758,6 +758,7 @@ static inline unsigned long vma_pages(struct vm_area_struct *vma)
extern struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr);
extern struct page * vmalloc_to_page(void *addr);
extern unsigned long vmalloc_to_pfn(void *addr);
extern struct page * follow_page(struct mm_struct *mm, unsigned long address,
int write);
int remap_pfn_range(struct vm_area_struct *, unsigned long,
......
......@@ -1805,6 +1805,16 @@ struct page * vmalloc_to_page(void * vmalloc_addr)
EXPORT_SYMBOL(vmalloc_to_page);
/*
* Map a vmalloc()-space virtual address to the physical page frame number.
*/
unsigned long vmalloc_to_pfn(void * vmalloc_addr)
{
return page_to_pfn(vmalloc_to_page(vmalloc_addr));
}
EXPORT_SYMBOL(vmalloc_to_pfn);
#if !defined(CONFIG_ARCH_GATE_AREA)
#if defined(AT_SYSINFO_EHDR)
......
......@@ -144,6 +144,12 @@ struct page * vmalloc_to_page(void *addr)
return virt_to_page(addr);
}
unsigned long vmalloc_to_pfn(void *addr)
{
return page_to_pfn(virt_to_page(addr));
}
long vread(char *buf, char *addr, unsigned long count)
{
memcpy(buf, addr, count);
......
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