diff options
author | Christoph Lameter <clameter@sgi.com> | 2007-07-17 07:03:22 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-07-17 13:23:01 -0400 |
commit | 6cb8f91320d3e720351c21741da795fed580b21b (patch) | |
tree | c9f73c8b82cd0f6c534939b8b9f36e8615b0ab2d /include/linux/slab.h | |
parent | ef2ad80c7d255ed0449eda947c2d700635b7e0f5 (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.h')
-rw-r--r-- | include/linux/slab.h | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/include/linux/slab.h b/include/linux/slab.h index 27402fea9b79..0289ec89300a 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h | |||
@@ -31,6 +31,19 @@ | |||
31 | #define SLAB_TRACE 0x00200000UL /* Trace allocations and frees */ | 31 | #define SLAB_TRACE 0x00200000UL /* Trace allocations and frees */ |
32 | 32 | ||
33 | /* | 33 | /* |
34 | * ZERO_SIZE_PTR will be returned for zero sized kmalloc requests. | ||
35 | * | ||
36 | * Dereferencing ZERO_SIZE_PTR will lead to a distinct access fault. | ||
37 | * | ||
38 | * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can. | ||
39 | * Both make kfree a no-op. | ||
40 | */ | ||
41 | #define ZERO_SIZE_PTR ((void *)16) | ||
42 | |||
43 | #define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) < \ | ||
44 | (unsigned long)ZERO_SIZE_PTR) | ||
45 | |||
46 | /* | ||
34 | * struct kmem_cache related prototypes | 47 | * struct kmem_cache related prototypes |
35 | */ | 48 | */ |
36 | void __init kmem_cache_init(void); | 49 | void __init kmem_cache_init(void); |