[PATCH] Catch kmalloc() failure in kmem_cache_init()

From: Johannes Weiner
Date: Mon Apr 02 2007 - 06:18:36 EST


Hi,

This patch makes kmem_cache_init() trigger a BUG when the calls to
kmalloc() fail. Altough the kernel would not boot anyway on failure,
this adds some clarity to the code.

Signed-off-by: Johannes Weiner <hannes-kernel@xxxxxxxxxxxx>

diff --git a/mm/slab.c b/mm/slab.c
index 57f7aa4..6d7e486 100644
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -1512,6 +1512,7 @@ void __init kmem_cache_init(void)
struct array_cache *ptr;

ptr = kmalloc(sizeof(struct arraycache_init), GFP_KERNEL);
+ BUG_ON(!ptr);

local_irq_disable();
BUG_ON(cpu_cache_get(&cache_cache) != &initarray_cache.cache);
@@ -1526,6 +1527,7 @@ void __init kmem_cache_init(void)
local_irq_enable();

ptr = kmalloc(sizeof(struct arraycache_init), GFP_KERNEL);
+ BUG_ON(!ptr);

local_irq_disable();
BUG_ON(cpu_cache_get(malloc_sizes[INDEX_AC].cs_cachep)