aboutsummaryrefslogtreecommitdiffstats
path: root/mm
diff options
context:
space:
mode:
authorSteven Rostedt <rostedt@goodmis.org>2006-02-01 06:05:44 -0500
committerLinus Torvalds <torvalds@g5.osdl.org>2006-02-01 11:53:17 -0500
commit5ec8a847bb8ae2ba6395cfb7cb4bfdc78ada82ed (patch)
tree2ef8bf7484700b49bae1b3c1191e04a80b78b102 /mm
parent18f820f655ce93b1e4d9b48fc6fcafc64157c6bc (diff)
[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: Steven Rostedt <rostedt@goodmis.org> Acked-by: Manfred Spraul <manfred@colorfullife.com> Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'mm')
-rw-r--r--mm/slab.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/mm/slab.c b/mm/slab.c
index bb7a9837b94..613d385519f 100644
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -316,6 +316,8 @@ struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
316 */ 316 */
317static __always_inline int index_of(const size_t size) 317static __always_inline int index_of(const size_t size)
318{ 318{
319 extern void __bad_size(void);
320
319 if (__builtin_constant_p(size)) { 321 if (__builtin_constant_p(size)) {
320 int i = 0; 322 int i = 0;
321 323
@@ -326,12 +328,9 @@ static __always_inline int index_of(const size_t size)
326 i++; 328 i++;
327#include "linux/kmalloc_sizes.h" 329#include "linux/kmalloc_sizes.h"
328#undef CACHE 330#undef CACHE
329 { 331 __bad_size();
330 extern void __bad_size(void);
331 __bad_size();
332 }
333 } else 332 } else
334 BUG(); 333 __bad_size();
335 return 0; 334 return 0;
336} 335}
337 336