aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/slab.h
diff options
context:
space:
mode:
authorXi Wang <xi.wang@gmail.com>2012-03-05 18:14:41 -0500
committerPekka Enberg <penberg@kernel.org>2012-03-06 04:01:33 -0500
commita8203725dfded5c1f79dca3368a4a273e24b59bb (patch)
tree1b2111e72fc8ccd40a29c0898fe0df58d2204e1a /include/linux/slab.h
parent8028dcea8abbbd51b5156e40ea214c20b559cd01 (diff)
slab: introduce kmalloc_array()
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>
Diffstat (limited to 'include/linux/slab.h')
-rw-r--r--include/linux/slab.h17
1 files changed, 14 insertions, 3 deletions
diff --git a/include/linux/slab.h b/include/linux/slab.h
index 573c809c33d9..a595dce6b0c7 100644
--- a/include/linux/slab.h
+++ b/include/linux/slab.h
@@ -190,7 +190,7 @@ size_t ksize(const void *);
190#endif 190#endif
191 191
192/** 192/**
193 * kcalloc - allocate memory for an array. The memory is set to zero. 193 * kmalloc_array - allocate memory for an array.
194 * @n: number of elements. 194 * @n: number of elements.
195 * @size: element size. 195 * @size: element size.
196 * @flags: the type of memory to allocate. 196 * @flags: the type of memory to allocate.
@@ -240,11 +240,22 @@ size_t ksize(const void *);
240 * for general use, and so are not documented here. For a full list of 240 * for general use, and so are not documented here. For a full list of
241 * potential flags, always refer to linux/gfp.h. 241 * potential flags, always refer to linux/gfp.h.
242 */ 242 */
243static inline void *kcalloc(size_t n, size_t size, gfp_t flags) 243static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
244{ 244{
245 if (size != 0 && n > ULONG_MAX / size) 245 if (size != 0 && n > ULONG_MAX / size)
246 return NULL; 246 return NULL;
247 return __kmalloc(n * size, flags | __GFP_ZERO); 247 return __kmalloc(n * size, flags);
248}
249
250/**
251 * kcalloc - allocate memory for an array. The memory is set to zero.
252 * @n: number of elements.
253 * @size: element size.
254 * @flags: the type of memory to allocate (see kmalloc).
255 */
256static inline void *kcalloc(size_t n, size_t size, gfp_t flags)
257{
258 return kmalloc_array(n, size, flags | __GFP_ZERO);
248} 259}
249 260
250#if !defined(CONFIG_NUMA) && !defined(CONFIG_SLOB) 261#if !defined(CONFIG_NUMA) && !defined(CONFIG_SLOB)