Commit 5ec8a847 authored by Steven Rostedt's avatar Steven Rostedt Committed by Linus Torvalds

[PATCH] slab: have index_of bug at compile time

I noticed the code for index_of is a creative way of finding the cache
index using the compiler to optimize to a single hard coded number.  But
I couldn't help noticing that it uses two methods to let you know that
someone used it wrong.  One is at compile time (the correct way), and
the other is at run time (not good).
Signed-off-by: default avatarSteven Rostedt <rostedt@goodmis.org>
Acked-by: default avatarManfred Spraul <manfred@colorfullife.com>
Signed-off-by: default avatarPekka Enberg <penberg@cs.helsinki.fi>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 18f820f6
...@@ -316,6 +316,8 @@ struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS]; ...@@ -316,6 +316,8 @@ struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
*/ */
static __always_inline int index_of(const size_t size) static __always_inline int index_of(const size_t size)
{ {
extern void __bad_size(void);
if (__builtin_constant_p(size)) { if (__builtin_constant_p(size)) {
int i = 0; int i = 0;
...@@ -326,12 +328,9 @@ static __always_inline int index_of(const size_t size) ...@@ -326,12 +328,9 @@ static __always_inline int index_of(const size_t size)
i++; i++;
#include "linux/kmalloc_sizes.h" #include "linux/kmalloc_sizes.h"
#undef CACHE #undef CACHE
{ __bad_size();
extern void __bad_size(void);
__bad_size();
}
} else } else
BUG(); __bad_size();
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment