public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] slab: Adds missing kmalloc() checks.
@ 2006-01-06 15:12 Luiz Fernando Capitulino
  2006-01-06 15:24 ` Arjan van de Ven
  0 siblings, 1 reply; 5+ messages in thread
From: Luiz Fernando Capitulino @ 2006-01-06 15:12 UTC (permalink / raw)
  To: akpm; +Cc: penberg, lkml


 Adds two missing kmalloc() checks in kmem_cache_init(). Note that if the
allocation fails, there is nothing to do, so we panic(); and the __LINE__
is used because is good to know which allocation has failed.

Signed-off-by: Luiz Capitulino <lcapitulino@mandriva.com.br>

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

diff --git a/mm/slab.c b/mm/slab.c
index e5ec26e..3f23ad2 100644
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -1115,6 +1115,8 @@ void __init kmem_cache_init(void)
 		void * ptr;
 
 		ptr = kmalloc(sizeof(struct arraycache_init), GFP_KERNEL);
+		if (!ptr)
+			panic("%s at %d: Could not allocate memory.\n", __FUNCTION__, __LINE__);
 
 		local_irq_disable();
 		BUG_ON(ac_data(&cache_cache) != &initarray_cache.cache);
@@ -1124,6 +1126,8 @@ void __init kmem_cache_init(void)
 		local_irq_enable();
 
 		ptr = kmalloc(sizeof(struct arraycache_init), GFP_KERNEL);
+		if (!ptr)
+			panic("%s at %d: Could not allocate memory.\n", __FUNCTION__, __LINE__);
 
 		local_irq_disable();
 		BUG_ON(ac_data(malloc_sizes[INDEX_AC].cs_cachep)


-- 
Luiz Fernando N. Capitulino

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] slab: Adds missing kmalloc() checks.
  2006-01-06 15:12 [PATCH] slab: Adds missing kmalloc() checks Luiz Fernando Capitulino
@ 2006-01-06 15:24 ` Arjan van de Ven
  2006-01-06 15:30   ` Luiz Fernando Capitulino
  0 siblings, 1 reply; 5+ messages in thread
From: Arjan van de Ven @ 2006-01-06 15:24 UTC (permalink / raw)
  To: Luiz Fernando Capitulino; +Cc: akpm, penberg, lkml

On Fri, 2006-01-06 at 13:12 -0200, Luiz Fernando Capitulino wrote:
>  Adds two missing kmalloc() checks in kmem_cache_init(). Note that if the
> allocation fails, there is nothing to do, so we panic();

ok so what good does this do? if you die this early.. you are in deeper
problems, and can't boot. while this makes the code bigger...



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] slab: Adds missing kmalloc() checks.
  2006-01-06 15:24 ` Arjan van de Ven
@ 2006-01-06 15:30   ` Luiz Fernando Capitulino
  2006-01-07  2:12     ` Pekka Enberg
  0 siblings, 1 reply; 5+ messages in thread
From: Luiz Fernando Capitulino @ 2006-01-06 15:30 UTC (permalink / raw)
  To: Arjan van de Ven; +Cc: akpm, penberg, linux-kernel

On Fri, 06 Jan 2006 16:24:47 +0100
Arjan van de Ven <arjan@infradead.org> wrote:

| On Fri, 2006-01-06 at 13:12 -0200, Luiz Fernando Capitulino wrote:
| >  Adds two missing kmalloc() checks in kmem_cache_init(). Note that if the
| > allocation fails, there is nothing to do, so we panic();
| 
| ok so what good does this do? if you die this early.. you are in deeper
| problems, and can't boot. while this makes the code bigger...

 Well, you'll get a panic with a message saying you have no memory to
boot, instead of a OOPS with a kernel NULL pointer derefecence, which
will make you look for a bug.

-- 
Luiz Fernando N. Capitulino

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] slab: Adds missing kmalloc() checks.
  2006-01-06 15:30   ` Luiz Fernando Capitulino
@ 2006-01-07  2:12     ` Pekka Enberg
  2006-01-09 12:44       ` Luiz Fernando Capitulino
  0 siblings, 1 reply; 5+ messages in thread
From: Pekka Enberg @ 2006-01-07  2:12 UTC (permalink / raw)
  To: Luiz Fernando Capitulino; +Cc: Arjan van de Ven, akpm, linux-kernel

Hi,

On Fri, 2006-01-06 at 13:12 -0200, Luiz Fernando Capitulino wrote:
> | >  Adds two missing kmalloc() checks in kmem_cache_init(). Note that if the
> | > allocation fails, there is nothing to do, so we panic();

On Fri, 06 Jan 2006 16:24:47 +0100
Arjan van de Ven <arjan@infradead.org> wrote:
> | ok so what good does this do? if you die this early.. you are in deeper
> | problems, and can't boot. while this makes the code bigger...

On Fri, 2006-01-06 at 13:30 -0200, Luiz Fernando Capitulino wrote:
>  Well, you'll get a panic with a message saying you have no memory to
> boot, instead of a OOPS with a kernel NULL pointer derefecence, which
> will make you look for a bug.

The code is in init section so I don't think size is an issue. A plain
BUG_ON would be better though as it can be disabled by the embedded
folk.

			Pekka


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] slab: Adds missing kmalloc() checks.
  2006-01-07  2:12     ` Pekka Enberg
@ 2006-01-09 12:44       ` Luiz Fernando Capitulino
  0 siblings, 0 replies; 5+ messages in thread
From: Luiz Fernando Capitulino @ 2006-01-09 12:44 UTC (permalink / raw)
  To: Pekka Enberg; +Cc: arjan, akpm, linux-kernel


 Hi Pekka,

On Sat, 07 Jan 2006 04:12:50 +0200
Pekka Enberg <penberg@cs.helsinki.fi> wrote:

| Hi,
| 
| On Fri, 2006-01-06 at 13:12 -0200, Luiz Fernando Capitulino wrote:
| > | >  Adds two missing kmalloc() checks in kmem_cache_init(). Note that if the
| > | > allocation fails, there is nothing to do, so we panic();
| 
| On Fri, 06 Jan 2006 16:24:47 +0100
| Arjan van de Ven <arjan@infradead.org> wrote:
| > | ok so what good does this do? if you die this early.. you are in deeper
| > | problems, and can't boot. while this makes the code bigger...
| 
| On Fri, 2006-01-06 at 13:30 -0200, Luiz Fernando Capitulino wrote:
| >  Well, you'll get a panic with a message saying you have no memory to
| > boot, instead of a OOPS with a kernel NULL pointer derefecence, which
| > will make you look for a bug.
| 
| The code is in init section so I don't think size is an issue. A plain
| BUG_ON would be better though as it can be disabled by the embedded
| folk.

 Okay, but a quick look at the initialization functions called from
'init/main.c' shows that some of them does the same thing (test an
error condition, and panic() if necessary).

 Should they be changed to call BUG_ON() instead?

PS: I'm asking becuase I also found several untested returns, I'll
send patches for they too.

-- 
Luiz Fernando N. Capitulino

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2006-01-09 12:45 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-01-06 15:12 [PATCH] slab: Adds missing kmalloc() checks Luiz Fernando Capitulino
2006-01-06 15:24 ` Arjan van de Ven
2006-01-06 15:30   ` Luiz Fernando Capitulino
2006-01-07  2:12     ` Pekka Enberg
2006-01-09 12:44       ` Luiz Fernando Capitulino

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox