aboutsummaryrefslogtreecommitdiffstats
path: root/mm/slab_common.c
diff options
context:
space:
mode:
authorChristoph Lameter <cl@linux.com>2012-09-04 20:20:33 -0400
committerPekka Enberg <penberg@kernel.org>2012-09-05 05:00:35 -0400
commit686d550d222e8f83f6e709debbedf9d8ef77aec7 (patch)
treeeb1a33c0a401c7fd9c22464a88c3c87fbfc8808d /mm/slab_common.c
parent208c4358dc4a8f0fe99e49eb8d21a869b01e7d34 (diff)
mm/slab_common: Improve error handling in kmem_cache_create
Instead of using s == NULL use an errorcode. This allows much more detailed diagnostics as to what went wrong. As we add more functionality from the slab allocators to the common kmem_cache_create() function we will also add more error conditions. Print the error code during the panic as well as in a warning if the module can handle failure. The API for kmem_cache_create() currently does not allow the returning of an error code. Return NULL but log the cause of the problem in the syslog. Reviewed-by: Glauber Costa <glommer@parallels.com> Acked-by: David Rientjes <rientjes@google.com> Signed-off-by: Christoph Lameter <cl@linux.com> Signed-off-by: Pekka Enberg <penberg@kernel.org>
Diffstat (limited to 'mm/slab_common.c')
-rw-r--r--mm/slab_common.c28
1 files changed, 24 insertions, 4 deletions
diff --git a/mm/slab_common.c b/mm/slab_common.c
index 8cf8b4962d6c..fe8dc943c285 100644
--- a/mm/slab_common.c
+++ b/mm/slab_common.c
@@ -98,16 +98,36 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size, size_t align
98 unsigned long flags, void (*ctor)(void *)) 98 unsigned long flags, void (*ctor)(void *))
99{ 99{
100 struct kmem_cache *s = NULL; 100 struct kmem_cache *s = NULL;
101 int err = 0;
101 102
102 get_online_cpus(); 103 get_online_cpus();
103 mutex_lock(&slab_mutex); 104 mutex_lock(&slab_mutex);
104 if (kmem_cache_sanity_check(name, size) == 0) 105
105 s = __kmem_cache_create(name, size, align, flags, ctor); 106 if (!kmem_cache_sanity_check(name, size) == 0)
107 goto out_locked;
108
109
110 s = __kmem_cache_create(name, size, align, flags, ctor);
111 if (!s)
112 err = -ENOSYS; /* Until __kmem_cache_create returns code */
113
114out_locked:
106 mutex_unlock(&slab_mutex); 115 mutex_unlock(&slab_mutex);
107 put_online_cpus(); 116 put_online_cpus();
108 117
109 if (!s && (flags & SLAB_PANIC)) 118 if (err) {
110 panic("kmem_cache_create: Failed to create slab '%s'\n", name); 119
120 if (flags & SLAB_PANIC)
121 panic("kmem_cache_create: Failed to create slab '%s'. Error %d\n",
122 name, err);
123 else {
124 printk(KERN_WARNING "kmem_cache_create(%s) failed with error %d",
125 name, err);
126 dump_stack();
127 }
128
129 return NULL;
130 }
111 131
112 return s; 132 return s;
113} 133}