-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PATCH] slob: introduce mm/util.c for shared functions
Add mm/util.c for functions common between SLAB and SLOB. Signed-off-by: Matt Mackall <mpm@selenic.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
- Loading branch information
Matt Mackall
authored and
Linus Torvalds
committed
Jan 9, 2006
1 parent
50dd26b
commit 30992c9
Showing
3 changed files
with
40 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#include <linux/slab.h> | ||
#include <linux/string.h> | ||
#include <linux/module.h> | ||
|
||
/** | ||
* kzalloc - allocate memory. The memory is set to zero. | ||
* @size: how many bytes of memory are required. | ||
* @flags: the type of memory to allocate. | ||
*/ | ||
void *kzalloc(size_t size, gfp_t flags) | ||
{ | ||
void *ret = kmalloc(size, flags); | ||
if (ret) | ||
memset(ret, 0, size); | ||
return ret; | ||
} | ||
EXPORT_SYMBOL(kzalloc); | ||
|
||
/* | ||
* 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, gfp_t 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); |