Skip to content

Commit

Permalink
[PATCH] slab: have index_of bug at compile time
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Steven Rostedt authored and Linus Torvalds committed Feb 1, 2006
1 parent 18f820f commit 5ec8a84
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions mm/slab.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,8 @@ struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
*/
static __always_inline int index_of(const size_t size)
{
extern void __bad_size(void);

if (__builtin_constant_p(size)) {
int i = 0;

Expand All @@ -326,12 +328,9 @@ static __always_inline int index_of(const size_t size)
i++;
#include "linux/kmalloc_sizes.h"
#undef CACHE
{
extern void __bad_size(void);
__bad_size();
}
__bad_size();
} else
BUG();
__bad_size();
return 0;
}

Expand Down

0 comments on commit 5ec8a84

Please sign in to comment.