Skip to contentSkip to conversation

Bug fix in slab.c:alloc_arraycache

PATCH Chen, Kenneth W 1 participant 1 message Mar 9, 2005 Memory management

lore
Share & tools
lore
#0 lore raw

Kmem_cache_alloc_node is not capable of handling a null cachep pointer as its input argument.

If I try to increase a slab limit by echoing a very large number into /proc/slabinfo, kernel will panic from alloc_arraycache() because Kmem_find_general_cachep() can actually return a NULL pointer if the size argument is sufficiently large.

mm/slab.c +4 -2
@@ -643,8 +645,10 @@
 	struct array_cache *nc = NULL;
 
 	if (cpu != -1) {
-		nc = kmem_cache_alloc_node(kmem_find_general_cachep(memsize,
-					GFP_KERNEL), cpu_to_node(cpu));
+		kmem_cache_t * cachep;
+		cachep = kmem_find_general_cachep(memsize, GFP_KERNEL);
+		if (cachep)
+			nc = kmem_cache_alloc_node(cachep, cpu_to_node(cpu));
 	}
 	if (!nc)
 		nc = kmalloc(memsize, GFP_KERNEL);