Skip to contentSkip to conversation

mm/slab.c: check kmalloc() return value.

PATCH In review Amit Choudhary 4 participants 4 messages Oct 22, 2006 – Oct 23, 2006 Memory management

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm/slab.c: check kmalloc() return value.

Description: Check the return value of kmalloc() in function setup_cpu_cache(), in file mm/slab.c.

mm/slab.c +1 -0
index 84c631f..613ae61 100644
@@ -2021,6 +2021,7 @@ static int setup_cpu_cache(struct kmem_c
 	} 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);
#1 lore raw
Quoted 9 lines · Amit Choudhary

Description: Check the return value of kmalloc() in function setup_cpu_cache(), in file mm/slab.c.

mm/slab.c +0 -0
index 84c631f..613ae61 100644

mm/slab.c static int setup_cpu_cache(struct kmem_c · line 2027

Quoted 7 lines
mm/slab.c +1 -0
@@ -2021,6 +2021,7 @@ static int setup_cpu_cache(struct kmem_c
 	} 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);

Any reason to BUG instead of trying to return as gracefully as possible?

Josef "Jeff" Sipek.

Signature · 2 lines
My public GPG key can be found at
http://www.josefsipek.net/gpg/public-0xC7958FFE.txt
#2 lore raw
Quoted 15 lines · Josef Sipek
Quoted 14 lines · Amit Choudhary

Description: Check the return value of kmalloc() in function setup_cpu_cache(), in file mm/slab.c.

mm/slab.c +1 -0
index 84c631f..613ae61 100644
@@ -2021,6 +2021,7 @@ static int setup_cpu_cache(struct kmem_c
 	} else {
 		cachep->array[smp_processor_id()] =
 			kmalloc(sizeof(struct arraycache_init), GFP_KERNEL);
+		BUG_ON(!cachep->array[smp_processor_id()]);
 
Quoted 4 lines

mm/slab.c static int setup_cpu_cache(struct kmem_c · line 2027

Quoted 2 lines
mm/slab.c +0 -0
 		if (g_cpucache_up == PARTIAL_AC) {
 			set_up_list3s(cachep, SIZE_L3);

Any reason to BUG instead of trying to return as gracefully as possible?

If we fail to allocate memory this early in boot, we're hosed anyway.

Dave

Signature · 1 line
http://www.codemonkey.org.uk
#3 lore raw
In reply to Amit Choudhary

mm/slab.c static int setup_cpu_cache(struct kmem_c · line 2027

Quoted 12 lines · Amit Choudhary
mm/slab.c +1 -0
index 84c631f..613ae61 100644
@@ -2021,6 +2021,7 @@ static int setup_cpu_cache(struct kmem_c
        } 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);

Looks good. You might want to send this to [email protected] directly.