From: Johannes Weiner <hannes-kernel@saeurebad.de>
To: Pekka Enberg <penberg@cs.helsinki.fi>
Cc: linux-kernel@vger.kernel.org, heiko.carstens@de.ibm.com,
gorcunov@gmail.com
Subject: [PATCH] Catch kmalloc failure in kmem_cache_init() (was: [QUESTION] check for mem in slab)
Date: Mon, 2 Apr 2007 11:50:49 +0200 [thread overview]
Message-ID: <20070402095049.GA5831@saeurebad.de> (raw)
In-Reply-To: <84144f020703300455i4fe6bdc5yf4389c2105487bb0@mail.gmail.com>
[-- 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)
next prev parent reply other threads:[~2007-04-02 9:50 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
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 ` Johannes Weiner [this message]
2007-04-02 10:18 ` [PATCH] Catch kmalloc() failure in kmem_cache_init() Johannes Weiner
2007-04-02 10:23 ` Pekka J Enberg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20070402095049.GA5831@saeurebad.de \
--to=hannes-kernel@saeurebad.de \
--cc=gorcunov@gmail.com \
--cc=heiko.carstens@de.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=penberg@cs.helsinki.fi \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox