aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mm/Makefile2
-rw-r--r--mm/slab.c37
-rw-r--r--mm/util.c39
3 files changed, 40 insertions, 38 deletions
diff --git a/mm/Makefile b/mm/Makefile
index 2fa6d2ca9f28..74c85ddc9176 100644
--- a/mm/Makefile
+++ b/mm/Makefile
@@ -10,7 +10,7 @@ mmu-$(CONFIG_MMU) := fremap.o highmem.o madvise.o memory.o mincore.o \
10obj-y := bootmem.o filemap.o mempool.o oom_kill.o fadvise.o \ 10obj-y := bootmem.o filemap.o mempool.o oom_kill.o fadvise.o \
11 page_alloc.o page-writeback.o pdflush.o \ 11 page_alloc.o page-writeback.o pdflush.o \
12 readahead.o slab.o swap.o truncate.o vmscan.o \ 12 readahead.o slab.o swap.o truncate.o vmscan.o \
13 prio_tree.o $(mmu-y) 13 prio_tree.o util.o $(mmu-y)
14 14
15obj-$(CONFIG_SWAP) += page_io.o swap_state.o swapfile.o thrash.o 15obj-$(CONFIG_SWAP) += page_io.o swap_state.o swapfile.o thrash.o
16obj-$(CONFIG_HUGETLBFS) += hugetlb.o 16obj-$(CONFIG_HUGETLBFS) += hugetlb.o
diff --git a/mm/slab.c b/mm/slab.c
index 76b092bd0bf7..1c46c6383552 100644
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -3053,20 +3053,6 @@ void kmem_cache_free(kmem_cache_t *cachep, void *objp)
3053EXPORT_SYMBOL(kmem_cache_free); 3053EXPORT_SYMBOL(kmem_cache_free);
3054 3054
3055/** 3055/**
3056 * kzalloc - allocate memory. The memory is set to zero.
3057 * @size: how many bytes of memory are required.
3058 * @flags: the type of memory to allocate.
3059 */
3060void *kzalloc(size_t size, gfp_t flags)
3061{
3062 void *ret = kmalloc(size, flags);
3063 if (ret)
3064 memset(ret, 0, size);
3065 return ret;
3066}
3067EXPORT_SYMBOL(kzalloc);
3068
3069/**
3070 * kfree - free previously allocated memory 3056 * kfree - free previously allocated memory
3071 * @objp: pointer returned by kmalloc. 3057 * @objp: pointer returned by kmalloc.
3072 * 3058 *
@@ -3659,26 +3645,3 @@ unsigned int ksize(const void *objp)
3659 3645
3660 return obj_reallen(page_get_cache(virt_to_page(objp))); 3646 return obj_reallen(page_get_cache(virt_to_page(objp)));
3661} 3647}
3662
3663
3664/*
3665 * kstrdup - allocate space for and copy an existing string
3666 *
3667 * @s: the string to duplicate
3668 * @gfp: the GFP mask used in the kmalloc() call when allocating memory
3669 */
3670char *kstrdup(const char *s, gfp_t gfp)
3671{
3672 size_t len;
3673 char *buf;
3674
3675 if (!s)
3676 return NULL;
3677
3678 len = strlen(s) + 1;
3679 buf = kmalloc(len, gfp);
3680 if (buf)
3681 memcpy(buf, s, len);
3682 return buf;
3683}
3684EXPORT_SYMBOL(kstrdup);
diff --git a/mm/util.c b/mm/util.c
new file mode 100644
index 000000000000..5f4bb59da63c
--- /dev/null
+++ b/mm/util.c
@@ -0,0 +1,39 @@
1#include <linux/slab.h>
2#include <linux/string.h>
3#include <linux/module.h>
4
5/**
6 * kzalloc - allocate memory. The memory is set to zero.
7 * @size: how many bytes of memory are required.
8 * @flags: the type of memory to allocate.
9 */
10void *kzalloc(size_t size, gfp_t flags)
11{
12 void *ret = kmalloc(size, flags);
13 if (ret)
14 memset(ret, 0, size);
15 return ret;
16}
17EXPORT_SYMBOL(kzalloc);
18
19/*
20 * kstrdup - allocate space for and copy an existing string
21 *
22 * @s: the string to duplicate
23 * @gfp: the GFP mask used in the kmalloc() call when allocating memory
24 */
25char *kstrdup(const char *s, gfp_t gfp)
26{
27 size_t len;
28 char *buf;
29
30 if (!s)
31 return NULL;
32
33 len = strlen(s) + 1;
34 buf = kmalloc(len, gfp);
35 if (buf)
36 memcpy(buf, s, len);
37 return buf;
38}
39EXPORT_SYMBOL(kstrdup);