1 #include <linux/slab.h>
2 #include <linux/string.h>
3 #include <linux/module.h>
5 #include <asm/uaccess.h>
8 * __kzalloc - allocate memory. The memory is set to zero.
9 * @size: how many bytes of memory are required.
10 * @flags: the type of memory to allocate.
12 void *__kzalloc(size_t size, gfp_t flags)
14 void *ret = ____kmalloc(size, flags);
19 EXPORT_SYMBOL(__kzalloc);
22 * kstrdup - allocate space for and copy an existing string
24 * @s: the string to duplicate
25 * @gfp: the GFP mask used in the kmalloc() call when allocating memory
27 char *kstrdup(const char *s, gfp_t gfp)
36 buf = ____kmalloc(len, gfp);
41 EXPORT_SYMBOL(kstrdup);
44 * strndup_user - duplicate an existing string from user space
46 * @s: The string to duplicate
47 * @n: Maximum number of bytes to copy, including the trailing NUL.
49 char *strndup_user(const char __user *s, long n)
54 length = strnlen_user(s, n);
57 return ERR_PTR(-EFAULT);
60 return ERR_PTR(-EINVAL);
62 p = kmalloc(length, GFP_KERNEL);
65 return ERR_PTR(-ENOMEM);
67 if (copy_from_user(p, s, length)) {
69 return ERR_PTR(-EFAULT);
76 EXPORT_SYMBOL(strndup_user);