mirror of
https://github.com/Fishwaldo/linux-bl808.git
synced 2025-06-17 20:25:19 +00:00
mm: unify module_alloc code for vmalloc
Four architectures (arm, mips, sparc, x86) use __vmalloc_area() for module_init(). Much of the code is duplicated and can be generalized in a globally accessible function, __vmalloc_node_range(). __vmalloc_node() now calls into __vmalloc_node_range() with a range of [VMALLOC_START, VMALLOC_END) for functionally equivalent behavior. Each architecture may then use __vmalloc_node_range() directly to remove the duplication of code. Signed-off-by: David Rientjes <rientjes@google.com> Cc: Christoph Lameter <cl@linux.com> Cc: Russell King <linux@arm.linux.org.uk> Cc: Ralf Baechle <ralf@linux-mips.org> Cc: "David S. Miller" <davem@davemloft.net> Cc: Ingo Molnar <mingo@redhat.com> Cc: "H. Peter Anvin" <hpa@zytor.com> Cc: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
ec3f64fc9c
commit
d0a21265df
6 changed files with 53 additions and 75 deletions
64
mm/vmalloc.c
64
mm/vmalloc.c
|
@ -1530,17 +1530,47 @@ fail:
|
|||
return NULL;
|
||||
}
|
||||
|
||||
void *__vmalloc_area(struct vm_struct *area, gfp_t gfp_mask, pgprot_t prot)
|
||||
/**
|
||||
* __vmalloc_node_range - allocate virtually contiguous memory
|
||||
* @size: allocation size
|
||||
* @align: desired alignment
|
||||
* @start: vm area range start
|
||||
* @end: vm area range end
|
||||
* @gfp_mask: flags for the page level allocator
|
||||
* @prot: protection mask for the allocated pages
|
||||
* @node: node to use for allocation or -1
|
||||
* @caller: caller's return address
|
||||
*
|
||||
* Allocate enough pages to cover @size from the page level
|
||||
* allocator with @gfp_mask flags. Map them into contiguous
|
||||
* kernel virtual space, using a pagetable protection of @prot.
|
||||
*/
|
||||
void *__vmalloc_node_range(unsigned long size, unsigned long align,
|
||||
unsigned long start, unsigned long end, gfp_t gfp_mask,
|
||||
pgprot_t prot, int node, void *caller)
|
||||
{
|
||||
void *addr = __vmalloc_area_node(area, gfp_mask, prot, -1,
|
||||
__builtin_return_address(0));
|
||||
struct vm_struct *area;
|
||||
void *addr;
|
||||
unsigned long real_size = size;
|
||||
|
||||
size = PAGE_ALIGN(size);
|
||||
if (!size || (size >> PAGE_SHIFT) > totalram_pages)
|
||||
return NULL;
|
||||
|
||||
area = __get_vm_area_node(size, align, VM_ALLOC, start, end, node,
|
||||
gfp_mask, caller);
|
||||
|
||||
if (!area)
|
||||
return NULL;
|
||||
|
||||
addr = __vmalloc_area_node(area, gfp_mask, prot, node, caller);
|
||||
|
||||
/*
|
||||
* A ref_count = 3 is needed because the vm_struct and vmap_area
|
||||
* structures allocated in the __get_vm_area_node() function contain
|
||||
* references to the virtual address of the vmalloc'ed block.
|
||||
*/
|
||||
kmemleak_alloc(addr, area->size - PAGE_SIZE, 3, gfp_mask);
|
||||
kmemleak_alloc(addr, real_size, 3, gfp_mask);
|
||||
|
||||
return addr;
|
||||
}
|
||||
|
@ -1562,30 +1592,8 @@ static void *__vmalloc_node(unsigned long size, unsigned long align,
|
|||
gfp_t gfp_mask, pgprot_t prot,
|
||||
int node, void *caller)
|
||||
{
|
||||
struct vm_struct *area;
|
||||
void *addr;
|
||||
unsigned long real_size = size;
|
||||
|
||||
size = PAGE_ALIGN(size);
|
||||
if (!size || (size >> PAGE_SHIFT) > totalram_pages)
|
||||
return NULL;
|
||||
|
||||
area = __get_vm_area_node(size, align, VM_ALLOC, VMALLOC_START,
|
||||
VMALLOC_END, node, gfp_mask, caller);
|
||||
|
||||
if (!area)
|
||||
return NULL;
|
||||
|
||||
addr = __vmalloc_area_node(area, gfp_mask, prot, node, caller);
|
||||
|
||||
/*
|
||||
* A ref_count = 3 is needed because the vm_struct and vmap_area
|
||||
* structures allocated in the __get_vm_area_node() function contain
|
||||
* references to the virtual address of the vmalloc'ed block.
|
||||
*/
|
||||
kmemleak_alloc(addr, real_size, 3, gfp_mask);
|
||||
|
||||
return addr;
|
||||
return __vmalloc_node_range(size, align, VMALLOC_START, VMALLOC_END,
|
||||
gfp_mask, prot, node, caller);
|
||||
}
|
||||
|
||||
void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue