aboutsummaryrefslogtreecommitdiffstats
path: root/mm
diff options
context:
space:
mode:
Diffstat (limited to 'mm')
-rw-r--r--mm/util.c26
-rw-r--r--mm/vmalloc.c53
2 files changed, 77 insertions, 2 deletions
diff --git a/mm/util.c b/mm/util.c
index 78f3783bdcc8..bf340d806868 100644
--- a/mm/util.c
+++ b/mm/util.c
@@ -6,7 +6,6 @@
6 6
7/** 7/**
8 * kstrdup - allocate space for and copy an existing string 8 * kstrdup - allocate space for and copy an existing string
9 *
10 * @s: the string to duplicate 9 * @s: the string to duplicate
11 * @gfp: the GFP mask used in the kmalloc() call when allocating memory 10 * @gfp: the GFP mask used in the kmalloc() call when allocating memory
12 */ 11 */
@@ -27,6 +26,30 @@ char *kstrdup(const char *s, gfp_t gfp)
27EXPORT_SYMBOL(kstrdup); 26EXPORT_SYMBOL(kstrdup);
28 27
29/** 28/**
29 * kstrndup - allocate space for and copy an existing string
30 * @s: the string to duplicate
31 * @max: read at most @max chars from @s
32 * @gfp: the GFP mask used in the kmalloc() call when allocating memory
33 */
34char *kstrndup(const char *s, size_t max, gfp_t gfp)
35{
36 size_t len;
37 char *buf;
38
39 if (!s)
40 return NULL;
41
42 len = strnlen(s, max);
43 buf = kmalloc_track_caller(len+1, gfp);
44 if (buf) {
45 memcpy(buf, s, len);
46 buf[len] = '\0';
47 }
48 return buf;
49}
50EXPORT_SYMBOL(kstrndup);
51
52/**
30 * kmemdup - duplicate region of memory 53 * kmemdup - duplicate region of memory
31 * 54 *
32 * @src: memory region to duplicate 55 * @src: memory region to duplicate
@@ -80,7 +103,6 @@ EXPORT_SYMBOL(krealloc);
80 103
81/* 104/*
82 * strndup_user - duplicate an existing string from user space 105 * strndup_user - duplicate an existing string from user space
83 *
84 * @s: The string to duplicate 106 * @s: The string to duplicate
85 * @n: Maximum number of bytes to copy, including the trailing NUL. 107 * @n: Maximum number of bytes to copy, including the trailing NUL.
86 */ 108 */
diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index 8e05a11155c9..3130c343088f 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -767,3 +767,56 @@ EXPORT_SYMBOL(remap_vmalloc_range);
767void __attribute__((weak)) vmalloc_sync_all(void) 767void __attribute__((weak)) vmalloc_sync_all(void)
768{ 768{
769} 769}
770
771
772static int f(pte_t *pte, struct page *pmd_page, unsigned long addr, void *data)
773{
774 /* apply_to_page_range() does all the hard work. */
775 return 0;
776}
777
778/**
779 * alloc_vm_area - allocate a range of kernel address space
780 * @size: size of the area
781 * @returns: NULL on failure, vm_struct on success
782 *
783 * This function reserves a range of kernel address space, and
784 * allocates pagetables to map that range. No actual mappings
785 * are created. If the kernel address space is not shared
786 * between processes, it syncs the pagetable across all
787 * processes.
788 */
789struct vm_struct *alloc_vm_area(size_t size)
790{
791 struct vm_struct *area;
792
793 area = get_vm_area(size, VM_IOREMAP);
794 if (area == NULL)
795 return NULL;
796
797 /*
798 * This ensures that page tables are constructed for this region
799 * of kernel virtual address space and mapped into init_mm.
800 */
801 if (apply_to_page_range(&init_mm, (unsigned long)area->addr,
802 area->size, f, NULL)) {
803 free_vm_area(area);
804 return NULL;
805 }
806
807 /* Make sure the pagetables are constructed in process kernel
808 mappings */
809 vmalloc_sync_all();
810
811 return area;
812}
813EXPORT_SYMBOL_GPL(alloc_vm_area);
814
815void free_vm_area(struct vm_struct *area)
816{
817 struct vm_struct *ret;
818 ret = remove_vm_area(area->addr);
819 BUG_ON(ret != area);
820 kfree(area);
821}
822EXPORT_SYMBOL_GPL(free_vm_area);