All of lore.kernel.org
 help / color / mirror / Atom feed
* [QUESTION] check for mem in slab
@ 2007-03-29 16:04 Cyrill Gorcunov
  2007-03-30  6:56 ` Heiko Carstens
  2007-04-02 10:18 ` [PATCH] Catch kmalloc() failure in kmem_cache_init() Johannes Weiner
  0 siblings, 2 replies; 7+ messages in thread
From: Cyrill Gorcunov @ 2007-03-29 16:04 UTC (permalink / raw)
  To: linux-kernel-list

Hi list,

in file mm/slab.c and routine kmem_cache_init() I found there
is no checking for allocated memory on line:

	/* 4) Replace the bootstrap head arrays */
	{
		struct array_cache *ptr;

		ptr = kmalloc(sizeof(struct arraycache_init), GFP_KERNEL);

--> no check for ptr == NULL <--

		local_irq_disable();
		BUG_ON(cpu_cache_get(&cache_cache) != &initarray_cache.cache);
		memcpy(ptr, cpu_cache_get(&cache_cache),
		       sizeof(struct arraycache_init));

		...

is that OK? or it's a bug?

		Cyrill


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

* Re: [QUESTION] check for mem in slab
  2007-03-29 16:04 [QUESTION] check for mem in slab Cyrill Gorcunov
@ 2007-03-30  6:56 ` Heiko Carstens
  2007-03-30 11:55   ` Pekka Enberg
  2007-04-02 10:18 ` [PATCH] Catch kmalloc() failure in kmem_cache_init() Johannes Weiner
  1 sibling, 1 reply; 7+ messages in thread
From: Heiko Carstens @ 2007-03-30  6:56 UTC (permalink / raw)
  To: Cyrill Gorcunov; +Cc: linux-kernel-list

> in file mm/slab.c and routine kmem_cache_init() I found there
> is no checking for allocated memory on line:
> 
> 	/* 4) Replace the bootstrap head arrays */
> 	{
> 		struct array_cache *ptr;
> 
> 		ptr = kmalloc(sizeof(struct arraycache_init), GFP_KERNEL);
> 
> --> no check for ptr == NULL <--
[...]
> is that OK? or it's a bug?

It's ok. If that allocation fails your machine won't come up anyway.

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

* Re: [QUESTION] check for mem in slab
  2007-03-30  6:56 ` Heiko Carstens
@ 2007-03-30 11:55   ` Pekka Enberg
  2007-03-30 16:41     ` Cyrill Gorcunov
  2007-04-02  9:50     ` [PATCH] Catch kmalloc failure in kmem_cache_init() (was: [QUESTION] check for mem in slab) Johannes Weiner
  0 siblings, 2 replies; 7+ messages in thread
From: Pekka Enberg @ 2007-03-30 11:55 UTC (permalink / raw)
  To: Heiko Carstens; +Cc: Cyrill Gorcunov, linux-kernel-list

On 3/30/07, Heiko Carstens <heiko.carstens@de.ibm.com> wrote:
> > in file mm/slab.c and routine kmem_cache_init() I found there
> > is no checking for allocated memory on line:
> >
> >       /* 4) Replace the bootstrap head arrays */
> >       {
> >               struct array_cache *ptr;
> >
> >               ptr = kmalloc(sizeof(struct arraycache_init), GFP_KERNEL);
> >
> > --> no check for ptr == NULL <--
> [...]
> > is that OK? or it's a bug?
>
> It's ok. If that allocation fails your machine won't come up anyway.

We ought to add a BUG_ON or comment at least there as this keeps
popping up again and again.

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

* Re: [QUESTION] check for mem in slab
  2007-03-30 11:55   ` Pekka Enberg
@ 2007-03-30 16:41     ` Cyrill Gorcunov
  2007-04-02  9:50     ` [PATCH] Catch kmalloc failure in kmem_cache_init() (was: [QUESTION] check for mem in slab) Johannes Weiner
  1 sibling, 0 replies; 7+ messages in thread
From: Cyrill Gorcunov @ 2007-03-30 16:41 UTC (permalink / raw)
  To: Pekka Enberg; +Cc: Heiko Carstens, Cyrill Gorcunov, linux-kernel-list

[Pekka Enberg - Fri, Mar 30, 2007 at 02:55:26PM +0300]
| On 3/30/07, Heiko Carstens <heiko.carstens@de.ibm.com> wrote:
| >> in file mm/slab.c and routine kmem_cache_init() I found there
| >> is no checking for allocated memory on line:
| >>
| >>       /* 4) Replace the bootstrap head arrays */
| >>       {
| >>               struct array_cache *ptr;
| >>
| >>               ptr = kmalloc(sizeof(struct arraycache_init), GFP_KERNEL);
| >>
| >> --> no check for ptr == NULL <--
| >[...]
| >> is that OK? or it's a bug?
| >
| >It's ok. If that allocation fails your machine won't come up anyway.
| 
| We ought to add a BUG_ON or comment at least there as this keeps
| popping up again and again.
| 

Thanks for answer

		Cyrill


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

* [PATCH] Catch kmalloc failure in kmem_cache_init() (was: [QUESTION] check for mem in slab)
  2007-03-30 11:55   ` Pekka Enberg
  2007-03-30 16:41     ` Cyrill Gorcunov
@ 2007-04-02  9:50     ` Johannes Weiner
  1 sibling, 0 replies; 7+ messages in thread
From: Johannes Weiner @ 2007-04-02  9:50 UTC (permalink / raw)
  To: Pekka Enberg; +Cc: linux-kernel, heiko.carstens, gorcunov

[-- Attachment #1: Type: text/plain, Size: 730 bytes --]

Hi,

> On 3/30/07, Heiko Carstens <heiko.carstens@de.ibm.com> wrote:
> >> in file mm/slab.c and routine kmem_cache_init() I found there
> >> is no checking for allocated memory on line:
> >>
> >>       /* 4) Replace the bootstrap head arrays */
> >>       {
> >>               struct array_cache *ptr;
> >>
> >>               ptr = kmalloc(sizeof(struct arraycache_init), GFP_KERNEL);
> >>
> >> --> no check for ptr == NULL <--
> >[...]
> >> is that OK? or it's a bug?
> >
> >It's ok. If that allocation fails your machine won't come up anyway.
> 
> We ought to add a BUG_ON or comment at least there as this keeps
> popping up again and again.

Done. Patch attached.

Signed-off-by: Johannes Weiner <hannes-kernel@saeurebad.de>


[-- Attachment #2: slab-cache-init-kmalloc-failure-catch.patch --]
[-- Type: text/plain, Size: 598 bytes --]

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)

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

* [PATCH] Catch kmalloc() failure in kmem_cache_init()
  2007-03-29 16:04 [QUESTION] check for mem in slab Cyrill Gorcunov
  2007-03-30  6:56 ` Heiko Carstens
@ 2007-04-02 10:18 ` Johannes Weiner
  2007-04-02 10:23   ` Pekka J Enberg
  1 sibling, 1 reply; 7+ messages in thread
From: Johannes Weiner @ 2007-04-02 10:18 UTC (permalink / raw)
  To: akpm; +Cc: linux-kernel, christoph, penberg

[-- Attachment #1: Type: text/plain, Size: 239 bytes --]

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@saeurebad.de>


[-- Attachment #2: slab-cache-init-kmalloc-failure-catch.patch --]
[-- Type: text/plain, Size: 598 bytes --]

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)

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

* Re: [PATCH] Catch kmalloc() failure in kmem_cache_init()
  2007-04-02 10:18 ` [PATCH] Catch kmalloc() failure in kmem_cache_init() Johannes Weiner
@ 2007-04-02 10:23   ` Pekka J Enberg
  0 siblings, 0 replies; 7+ messages in thread
From: Pekka J Enberg @ 2007-04-02 10:23 UTC (permalink / raw)
  To: Johannes Weiner; +Cc: akpm, linux-kernel, christoph

On Mon, 2 Apr 2007, Johannes Weiner wrote:
> 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.

Indeed. This keeps popping up again and again, so

Acked-by: Pekka Enberg <penberg@cs.helsinki.fi>

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

end of thread, other threads:[~2007-04-02 10:23 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-03-29 16:04 [QUESTION] check for mem in slab Cyrill Gorcunov
2007-03-30  6:56 ` Heiko Carstens
2007-03-30 11:55   ` Pekka Enberg
2007-03-30 16:41     ` Cyrill Gorcunov
2007-04-02  9:50     ` [PATCH] Catch kmalloc failure in kmem_cache_init() (was: [QUESTION] check for mem in slab) Johannes Weiner
2007-04-02 10:18 ` [PATCH] Catch kmalloc() failure in kmem_cache_init() Johannes Weiner
2007-04-02 10:23   ` Pekka J Enberg

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.