]> Pileus Git - ~andy/linux/commitdiff
slob: Check for NULL pointer before calling ctor()
authorSteven Rostedt <rostedt@goodmis.org>
Thu, 17 Jan 2013 17:13:46 +0000 (12:13 -0500)
committerPekka Enberg <penberg@kernel.org>
Sun, 7 Jul 2013 16:19:23 +0000 (19:19 +0300)
While doing some code inspection, I noticed that the slob constructor
method can be called with a NULL pointer. If memory is tight and slob
fails to allocate with slob_alloc() or slob_new_pages() it still calls
the ctor() method with a NULL pointer. Looking at the first ctor()
method I found, I noticed that it can not handle a NULL pointer (I'm
sure others probably can't either):

static void sighand_ctor(void *data)
{
        struct sighand_struct *sighand = data;

        spin_lock_init(&sighand->siglock);
        init_waitqueue_head(&sighand->signalfd_wqh);
}

The solution is to only call the ctor() method if allocation succeeded.

Acked-by: Christoph Lameter <cl@linux.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
mm/slob.c

index f729c46639fa6606a9591d1f9891a928f801f47d..3d73b3b8fb1dcba18cfde8f088e9c6d974ce4508 100644 (file)
--- a/mm/slob.c
+++ b/mm/slob.c
@@ -554,7 +554,7 @@ void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
                                            flags, node);
        }
 
-       if (c->ctor)
+       if (b && c->ctor)
                c->ctor(b);
 
        kmemleak_alloc_recursive(b, c->size, 1, c->flags, flags);