Skip to content

Commit

Permalink
dlm: NULL dereference on failure in kmem_cache_create()
Browse files Browse the repository at this point in the history
We aren't allowed to pass NULL pointers to kmem_cache_destroy() so if
both allocations fail, it leads to a NULL dereference.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: David Teigland <teigland@redhat.com>
  • Loading branch information
Dan Carpenter authored and David Teigland committed May 15, 2012
1 parent 1a058f5 commit 75af271
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions fs/dlm/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,19 @@ static struct kmem_cache *rsb_cache;

int __init dlm_memory_init(void)
{
int ret = 0;

lkb_cache = kmem_cache_create("dlm_lkb", sizeof(struct dlm_lkb),
__alignof__(struct dlm_lkb), 0, NULL);
if (!lkb_cache)
ret = -ENOMEM;
return -ENOMEM;

rsb_cache = kmem_cache_create("dlm_rsb", sizeof(struct dlm_rsb),
__alignof__(struct dlm_rsb), 0, NULL);
if (!rsb_cache) {
kmem_cache_destroy(lkb_cache);
ret = -ENOMEM;
return -ENOMEM;
}

return ret;
return 0;
}

void dlm_memory_exit(void)
Expand Down

0 comments on commit 75af271

Please sign in to comment.