Skip to content

Commit

Permalink
mm/slab_common: Improve error handling in kmem_cache_create
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Christoph Lameter authored and Pekka Enberg committed Sep 5, 2012
1 parent 208c435 commit 686d550
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions mm/slab_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,36 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size, size_t align
unsigned long flags, void (*ctor)(void *))
{
struct kmem_cache *s = NULL;
int err = 0;

get_online_cpus();
mutex_lock(&slab_mutex);
if (kmem_cache_sanity_check(name, size) == 0)
s = __kmem_cache_create(name, size, align, flags, ctor);

if (!kmem_cache_sanity_check(name, size) == 0)
goto out_locked;


s = __kmem_cache_create(name, size, align, flags, ctor);
if (!s)
err = -ENOSYS; /* Until __kmem_cache_create returns code */

out_locked:
mutex_unlock(&slab_mutex);
put_online_cpus();

if (!s && (flags & SLAB_PANIC))
panic("kmem_cache_create: Failed to create slab '%s'\n", name);
if (err) {

if (flags & SLAB_PANIC)
panic("kmem_cache_create: Failed to create slab '%s'. Error %d\n",
name, err);
else {
printk(KERN_WARNING "kmem_cache_create(%s) failed with error %d",
name, err);
dump_stack();
}

return NULL;
}

return s;
}
Expand Down

0 comments on commit 686d550

Please sign in to comment.