2006-08-13 10:17:01

by Akinobu Mita

[permalink] [raw]
Subject: [PATCH] check return value of kmalloc() in setup_cpu_cache()

This patch makes crash happen when allocation of cpucache data fails
in setup_cpu_cache(). It is a bit better than getting kernel NULL
pointer dereference later.

CC: Pekka Enberg <[email protected]>
Signed-off-by: Akinobu Mita <[email protected]>

mm/slab.c | 1 +
1 file changed, 1 insertion(+)

Index: work-failmalloc/mm/slab.c
===================================================================
--- work-failmalloc.orig/mm/slab.c
+++ work-failmalloc/mm/slab.c
@@ -1932,6 +1932,7 @@ static void setup_cpu_cache(struct kmem_
} else {
cachep->array[smp_processor_id()] =
kmalloc(sizeof(struct arraycache_init), GFP_KERNEL);
+ BUG_ON(!cachep->array[smp_processor_id()]);

if (g_cpucache_up == PARTIAL_AC) {
set_up_list3s(cachep, SIZE_L3);


2006-08-14 23:08:35

by Andrew Morton

[permalink] [raw]
Subject: Re: [PATCH] check return value of kmalloc() in setup_cpu_cache()

On Sun, 13 Aug 2006 18:16:54 +0800
Akinobu Mita <[email protected]> wrote:

> This patch makes crash happen when allocation of cpucache data fails
> in setup_cpu_cache(). It is a bit better than getting kernel NULL
> pointer dereference later.

This code is called on the kmem_cache_create() path. We should back out
and return -ENOMEM from kmem_cache_create().