Skip to contentSkip to conversation

slab: have index_of bug at compile time

PATCH In review Pekka Enberg 1 participant 1 message Jan 3, 2006 Memory management

lore
Share & tools
lore
#0 lore raw

PATCH 3/9 slab: have index_of bug at compile time

From: Steven Rostedt <[email protected]>

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).

---

 mm/slab.c |    9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
mm/slab.c +4 -5
Index: 2.6/mm/slab.c
===================================================================
@@ -315,6 +315,8 @@ struct kmem_list3 __initdata initkmem_li
  */
 static __always_inline int index_of(const size_t size)
 {
+	extern void __bad_size(void);
+
 	if (__builtin_constant_p(size)) {
 		int i = 0;
 
@@ -325,12 +327,9 @@ static __always_inline int index_of(cons
 		i++;
 #include "linux/kmalloc_sizes.h"
 #undef CACHE
-		{
-			extern void __bad_size(void);
-			__bad_size();
-		}
+		__bad_size();
 	} else
-		BUG();
+		__bad_size();
 	return 0;
 }
 

--