Skip to content

Commit f6f8ed4

Browse files
WANG Chaotorvalds
authored andcommitted
mm/vmalloc.c: clean up map_vm_area third argument
Currently map_vm_area() takes (struct page *** pages) as third argument, and after mapping, it moves (*pages) to point to (*pages + nr_mappped_pages). It looks like this kind of increment is useless to its caller these days. The callers don't care about the increments and actually they're trying to avoid this by passing another copy to map_vm_area(). The caller can always guarantee all the pages can be mapped into vm_area as specified in first argument and the caller only cares about whether map_vm_area() fails or not. This patch cleans up the pointer movement in map_vm_area() and updates its callers accordingly. Signed-off-by: WANG Chao <chaowang@redhat.com> Cc: Zhang Yanfei <zhangyanfei@cn.fujitsu.com> Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: Minchan Kim <minchan@kernel.org> Cc: Nitin Gupta <ngupta@vflare.org> Cc: Rusty Russell <rusty@rustcorp.com.au> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 21bda26 commit f6f8ed4

6 files changed

Lines changed: 11 additions & 20 deletions

File tree

‎arch/tile/kernel/module.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ void *module_alloc(unsigned long size)
5858
area->nr_pages = npages;
5959
area->pages = pages;
6060

61-
if (map_vm_area(area, prot_rwx, &pages)) {
61+
if (map_vm_area(area, prot_rwx, pages)) {
6262
vunmap(area->addr);
6363
goto error;
6464
}

‎drivers/lguest/core.c‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ DEFINE_MUTEX(lguest_lock);
4242
static __init int map_switcher(void)
4343
{
4444
int i, err;
45-
struct page **pagep;
4645

4746
/*
4847
* Map the Switcher in to high memory.
@@ -110,11 +109,9 @@ static __init int map_switcher(void)
110109
* This code actually sets up the pages we've allocated to appear at
111110
* switcher_addr. map_vm_area() takes the vma we allocated above, the
112111
* kind of pages we're mapping (kernel pages), and a pointer to our
113-
* array of struct pages. It increments that pointer, but we don't
114-
* care.
112+
* array of struct pages.
115113
*/
116-
pagep = lg_switcher_pages;
117-
err = map_vm_area(switcher_vma, PAGE_KERNEL_EXEC, &pagep);
114+
err = map_vm_area(switcher_vma, PAGE_KERNEL_EXEC, lg_switcher_pages);
118115
if (err) {
119116
printk("lguest: map_vm_area failed: %i\n", err);
120117
goto free_vma;

‎drivers/staging/android/binder.c‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,6 @@ static int binder_update_page_range(struct binder_proc *proc, int allocate,
585585

586586
for (page_addr = start; page_addr < end; page_addr += PAGE_SIZE) {
587587
int ret;
588-
struct page **page_array_ptr;
589588

590589
page = &proc->pages[(page_addr - proc->buffer) / PAGE_SIZE];
591590

@@ -598,8 +597,7 @@ static int binder_update_page_range(struct binder_proc *proc, int allocate,
598597
}
599598
tmp_area.addr = page_addr;
600599
tmp_area.size = PAGE_SIZE + PAGE_SIZE /* guard page? */;
601-
page_array_ptr = page;
602-
ret = map_vm_area(&tmp_area, PAGE_KERNEL, &page_array_ptr);
600+
ret = map_vm_area(&tmp_area, PAGE_KERNEL, page);
603601
if (ret) {
604602
pr_err("%d: binder_alloc_buf failed to map page at %p in kernel\n",
605603
proc->pid, page_addr);

‎include/linux/vmalloc.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ extern struct vm_struct *remove_vm_area(const void *addr);
113113
extern struct vm_struct *find_vm_area(const void *addr);
114114

115115
extern int map_vm_area(struct vm_struct *area, pgprot_t prot,
116-
struct page ***pages);
116+
struct page **pages);
117117
#ifdef CONFIG_MMU
118118
extern int map_kernel_range_noflush(unsigned long start, unsigned long size,
119119
pgprot_t prot, struct page **pages);

‎mm/vmalloc.c‎

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,19 +1270,15 @@ void unmap_kernel_range(unsigned long addr, unsigned long size)
12701270
}
12711271
EXPORT_SYMBOL_GPL(unmap_kernel_range);
12721272

1273-
int map_vm_area(struct vm_struct *area, pgprot_t prot, struct page ***pages)
1273+
int map_vm_area(struct vm_struct *area, pgprot_t prot, struct page **pages)
12741274
{
12751275
unsigned long addr = (unsigned long)area->addr;
12761276
unsigned long end = addr + get_vm_area_size(area);
12771277
int err;
12781278

1279-
err = vmap_page_range(addr, end, prot, *pages);
1280-
if (err > 0) {
1281-
*pages += err;
1282-
err = 0;
1283-
}
1279+
err = vmap_page_range(addr, end, prot, pages);
12841280

1285-
return err;
1281+
return err > 0 ? 0 : err;
12861282
}
12871283
EXPORT_SYMBOL_GPL(map_vm_area);
12881284

@@ -1548,7 +1544,7 @@ void *vmap(struct page **pages, unsigned int count,
15481544
if (!area)
15491545
return NULL;
15501546

1551-
if (map_vm_area(area, prot, &pages)) {
1547+
if (map_vm_area(area, prot, pages)) {
15521548
vunmap(area->addr);
15531549
return NULL;
15541550
}
@@ -1606,7 +1602,7 @@ static void *__vmalloc_area_node(struct vm_struct *area, gfp_t gfp_mask,
16061602
cond_resched();
16071603
}
16081604

1609-
if (map_vm_area(area, prot, &pages))
1605+
if (map_vm_area(area, prot, pages))
16101606
goto fail;
16111607
return area->addr;
16121608

‎mm/zsmalloc.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ static inline void __zs_cpu_down(struct mapping_area *area)
690690
static inline void *__zs_map_object(struct mapping_area *area,
691691
struct page *pages[2], int off, int size)
692692
{
693-
BUG_ON(map_vm_area(area->vm, PAGE_KERNEL, &pages));
693+
BUG_ON(map_vm_area(area->vm, PAGE_KERNEL, pages));
694694
area->vm_addr = area->vm->addr;
695695
return area->vm_addr + off;
696696
}

0 commit comments

Comments
 (0)