Skip to content

Commit c1e854e

Browse files
rostedtpenberg
authored andcommitted
slob: Check for NULL pointer before calling ctor()
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>
1 parent 345c905 commit c1e854e

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

mm/slob.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
554554
flags, node);
555555
}
556556

557-
if (c->ctor)
557+
if (b && c->ctor)
558558
c->ctor(b);
559559

560560
kmemleak_alloc_recursive(b, c->size, 1, c->flags, flags);

0 commit comments

Comments
 (0)