summaryrefslogtreecommitdiffstats
path: root/mm/slab.c
diff options
context:
space:
mode:
authorPaulo Marques <pmarques@grupopie.com>2005-06-23 00:09:02 -0700
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-06-23 09:45:18 -0700
commit543537bd922692bc978e2e356fcd8bfc9c2ee7d5 (patch)
tree0089e3907e7d6c17c01cffc6ea4a8962ed053079 /mm/slab.c
parent991114c6fa6a21d1fa4d544abe78592352860c82 (diff)
downloadlinux-543537bd922692bc978e2e356fcd8bfc9c2ee7d5.tar.gz
linux-543537bd922692bc978e2e356fcd8bfc9c2ee7d5.tar.bz2
linux-543537bd922692bc978e2e356fcd8bfc9c2ee7d5.zip
[PATCH] create a kstrdup library function
This patch creates a new kstrdup library function and changes the "local" implementations in several places to use this function. Most of the changes come from the sound and net subsystems. The sound part had already been acknowledged by Takashi Iwai and the net part by David S. Miller. I left UML alone for now because I would need more time to read the code carefully before making changes there. Signed-off-by: Paulo Marques <pmarques@grupopie.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'mm/slab.c')
-rw-r--r--mm/slab.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/mm/slab.c b/mm/slab.c
index 93cbbbb39f42..122d031baab2 100644
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -92,6 +92,7 @@
#include <linux/sysctl.h>
#include <linux/module.h>
#include <linux/rcupdate.h>
+#include <linux/string.h>
#include <asm/uaccess.h>
#include <asm/cacheflush.h>
@@ -3082,3 +3083,26 @@ unsigned int ksize(const void *objp)
return size;
}
+
+
+/*
+ * kstrdup - allocate space for and copy an existing string
+ *
+ * @s: the string to duplicate
+ * @gfp: the GFP mask used in the kmalloc() call when allocating memory
+ */
+char *kstrdup(const char *s, int gfp)
+{
+ size_t len;
+ char *buf;
+
+ if (!s)
+ return NULL;
+
+ len = strlen(s) + 1;
+ buf = kmalloc(len, gfp);
+ if (buf)
+ memcpy(buf, s, len);
+ return buf;
+}
+EXPORT_SYMBOL(kstrdup);