aboutsummaryrefslogtreecommitdiffstats
path: root/mm
diff options
context:
space:
mode:
authorPekka J Enberg <penberg@cs.Helsinki.FI>2005-09-06 18:18:31 -0400
committerLinus Torvalds <torvalds@g5.osdl.org>2005-09-07 19:57:45 -0400
commitdd3927105b6f65afb7dac17682172cdfb86d3f00 (patch)
tree5cf282aff500cad23b9d7e13dc19b2b2d31e1ce6 /mm
parent640e803376b9c4072f69fec42e304c974a631298 (diff)
[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 <penberg@cs.helsinki.fi> Signed-off-by: Adrian Bunk <bunk@stusta.de> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'mm')
-rw-r--r--mm/slab.c18
1 files changed, 6 insertions, 12 deletions
diff --git a/mm/slab.c b/mm/slab.c
index a9ff4f7f9860..d7c4443991fe 100644
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -2558,24 +2558,18 @@ void kmem_cache_free(kmem_cache_t *cachep, void *objp)
2558EXPORT_SYMBOL(kmem_cache_free); 2558EXPORT_SYMBOL(kmem_cache_free);
2559 2559
2560/** 2560/**
2561 * kcalloc - allocate memory for an array. The memory is set to zero. 2561 * kzalloc - allocate memory. The memory is set to zero.
2562 * @n: number of elements. 2562 * @size: how many bytes of memory are required.
2563 * @size: element size.
2564 * @flags: the type of memory to allocate. 2563 * @flags: the type of memory to allocate.
2565 */ 2564 */
2566void *kcalloc(size_t n, size_t size, unsigned int __nocast flags) 2565void *kzalloc(size_t size, unsigned int __nocast flags)
2567{ 2566{
2568 void *ret = NULL; 2567 void *ret = kmalloc(size, flags);
2569
2570 if (n != 0 && size > INT_MAX / n)
2571 return ret;
2572
2573 ret = kmalloc(n * size, flags);
2574 if (ret) 2568 if (ret)
2575 memset(ret, 0, n * size); 2569 memset(ret, 0, size);
2576 return ret; 2570 return ret;
2577} 2571}
2578EXPORT_SYMBOL(kcalloc); 2572EXPORT_SYMBOL(kzalloc);
2579 2573
2580/** 2574/**
2581 * kfree - free previously allocated memory 2575 * kfree - free previously allocated memory