mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-28 10:41:38 -04:00
[PATCH] introduce and use kzalloc
This patch introduces a kzalloc wrapper and converts kernel/ to use it. It saves a little program text. Signed-off-by: Pekka Enberg <[email protected]> Signed-off-by: Adrian Bunk <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
This commit is contained in:
parent
640e803376
commit
dd3927105b
7 changed files with 27 additions and 23 deletions
18
mm/slab.c
18
mm/slab.c
|
|
@ -2558,24 +2558,18 @@ void kmem_cache_free(kmem_cache_t *cachep, void *objp)
|
|||
EXPORT_SYMBOL(kmem_cache_free);
|
||||
|
||||
/**
|
||||
* kcalloc - allocate memory for an array. The memory is set to zero.
|
||||
* @n: number of elements.
|
||||
* @size: element size.
|
||||
* 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 *kcalloc(size_t n, size_t size, unsigned int __nocast flags)
|
||||
void *kzalloc(size_t size, unsigned int __nocast flags)
|
||||
{
|
||||
void *ret = NULL;
|
||||
|
||||
if (n != 0 && size > INT_MAX / n)
|
||||
return ret;
|
||||
|
||||
ret = kmalloc(n * size, flags);
|
||||
void *ret = kmalloc(size, flags);
|
||||
if (ret)
|
||||
memset(ret, 0, n * size);
|
||||
memset(ret, 0, size);
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL(kcalloc);
|
||||
EXPORT_SYMBOL(kzalloc);
|
||||
|
||||
/**
|
||||
* kfree - free previously allocated memory
|
||||
|
|
|
|||
Loading…
Reference in a new issue