diff options
author | Xi Wang <xi.wang@gmail.com> | 2012-03-05 15:14:41 -0800 |
---|---|---|
committer | Ben Hutchings <ben@decadent.org.uk> | 2013-09-10 01:57:09 +0100 |
commit | 433b06a8f4b04e560c3ad8e13bf60b1fa6186341 (patch) | |
tree | aa8e94abfe5cbdfedd71829a2edf1904ae0ae302 /include/linux/slab.h | |
parent | 0aaf4c42a31301cc59177aa3246fdd7b20b570fa (diff) | |
download | kernel_samsung_smdk4412-433b06a8f4b04e560c3ad8e13bf60b1fa6186341.zip kernel_samsung_smdk4412-433b06a8f4b04e560c3ad8e13bf60b1fa6186341.tar.gz kernel_samsung_smdk4412-433b06a8f4b04e560c3ad8e13bf60b1fa6186341.tar.bz2 |
slab: introduce kmalloc_array()
commit a8203725dfded5c1f79dca3368a4a273e24b59bb upstream.
Introduce a kmalloc_array() wrapper that performs integer overflow
checking without zeroing the memory.
Suggested-by: Andrew Morton <akpm@linux-foundation.org>
Suggested-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Xi Wang <xi.wang@gmail.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: David Rientjes <rientjes@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
Diffstat (limited to 'include/linux/slab.h')
-rw-r--r-- | include/linux/slab.h | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/include/linux/slab.h b/include/linux/slab.h index 573c809..a595dce 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -190,7 +190,7 @@ size_t ksize(const void *); #endif /** - * kcalloc - allocate memory for an array. The memory is set to zero. + * kmalloc_array - allocate memory for an array. * @n: number of elements. * @size: element size. * @flags: the type of memory to allocate. @@ -240,11 +240,22 @@ size_t ksize(const void *); * for general use, and so are not documented here. For a full list of * potential flags, always refer to linux/gfp.h. */ -static inline void *kcalloc(size_t n, size_t size, gfp_t flags) +static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags) { if (size != 0 && n > ULONG_MAX / size) return NULL; - return __kmalloc(n * size, flags | __GFP_ZERO); + return __kmalloc(n * size, flags); +} + +/** + * kcalloc - allocate memory for an array. The memory is set to zero. + * @n: number of elements. + * @size: element size. + * @flags: the type of memory to allocate (see kmalloc). + */ +static inline void *kcalloc(size_t n, size_t size, gfp_t flags) +{ + return kmalloc_array(n, size, flags | __GFP_ZERO); } #if !defined(CONFIG_NUMA) && !defined(CONFIG_SLOB) |