aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/slab_def.h
diff options
context:
space:
mode:
authorChristoph Lameter <clameter@sgi.com>2007-07-17 07:03:22 -0400
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-07-17 13:23:01 -0400
commit6cb8f91320d3e720351c21741da795fed580b21b (patch)
treec9f73c8b82cd0f6c534939b8b9f36e8615b0ab2d /include/linux/slab_def.h
parentef2ad80c7d255ed0449eda947c2d700635b7e0f5 (diff)
Slab allocators: consistent ZERO_SIZE_PTR support and NULL result semantics
Define ZERO_OR_NULL_PTR macro to be able to remove the checks from the allocators. Move ZERO_SIZE_PTR related stuff into slab.h. Make ZERO_SIZE_PTR work for all slab allocators and get rid of the WARN_ON_ONCE(size == 0) that is still remaining in SLAB. Make slub return NULL like the other allocators if a too large memory segment is requested via __kmalloc. Signed-off-by: Christoph Lameter <clameter@sgi.com> Acked-by: Pekka Enberg <penberg@cs.helsinki.fi> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'include/linux/slab_def.h')
-rw-r--r--include/linux/slab_def.h12
1 files changed, 12 insertions, 0 deletions
diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
index 365d036c454a..16e814ffab8d 100644
--- a/include/linux/slab_def.h
+++ b/include/linux/slab_def.h
@@ -32,6 +32,10 @@ static inline void *kmalloc(size_t size, gfp_t flags)
32{ 32{
33 if (__builtin_constant_p(size)) { 33 if (__builtin_constant_p(size)) {
34 int i = 0; 34 int i = 0;
35
36 if (!size)
37 return ZERO_SIZE_PTR;
38
35#define CACHE(x) \ 39#define CACHE(x) \
36 if (size <= x) \ 40 if (size <= x) \
37 goto found; \ 41 goto found; \
@@ -58,6 +62,10 @@ static inline void *kzalloc(size_t size, gfp_t flags)
58{ 62{
59 if (__builtin_constant_p(size)) { 63 if (__builtin_constant_p(size)) {
60 int i = 0; 64 int i = 0;
65
66 if (!size)
67 return ZERO_SIZE_PTR;
68
61#define CACHE(x) \ 69#define CACHE(x) \
62 if (size <= x) \ 70 if (size <= x) \
63 goto found; \ 71 goto found; \
@@ -88,6 +96,10 @@ static inline void *kmalloc_node(size_t size, gfp_t flags, int node)
88{ 96{
89 if (__builtin_constant_p(size)) { 97 if (__builtin_constant_p(size)) {
90 int i = 0; 98 int i = 0;
99
100 if (!size)
101 return ZERO_SIZE_PTR;
102
91#define CACHE(x) \ 103#define CACHE(x) \
92 if (size <= x) \ 104 if (size <= x) \
93 goto found; \ 105 goto found; \