slub: Check kasprintf results in kmem_cache_init()
authorChristoph Lameter <cl@linux-foundation.org>
Fri, 9 Jul 2010 19:07:12 +0000 (14:07 -0500)
committerPekka Enberg <penberg@cs.helsinki.fi>
Fri, 16 Jul 2010 08:13:07 +0000 (11:13 +0300)
Small allocations may fail during slab bringup which is fatal. Add a BUG_ON()
so that we fail immediately rather than failing later during sysfs
processing.

Acked-by: David Rientjes <rientjes@google.com>
Signed-off-by: Christoph Lameter <cl@linux-foundation.org>
Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
mm/slub.c

index 2c11903517267c0f4776ce819b9cc8bba59b9211..8655be5b7404982cf153c623af445f0e20966db3 100644 (file)
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -3118,9 +3118,12 @@ void __init kmem_cache_init(void)
        slab_state = UP;
 
        /* Provide the correct kmalloc names now that the caches are up */
-       for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++)
-               kmalloc_caches[i]. name =
-                       kasprintf(GFP_NOWAIT, "kmalloc-%d", 1 << i);
+       for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
+               char *s = kasprintf(GFP_NOWAIT, "kmalloc-%d", 1 << i);
+
+               BUG_ON(!s);
+               kmalloc_caches[i].name = s;
+       }
 
 #ifdef CONFIG_SMP
        register_cpu_notifier(&slab_notifier);