Skip to contentSkip to conversation

dlm: NULL dereference on failure in kmem_cache_create()

PATCH New Dan Carpenter 2 participants 2 messages May 15, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dlm: NULL dereference on failure in kmem_cache_create()

We aren't allowed to pass NULL pointers to kmem_cache_destroy() so if both allocations fail, it leads to a NULL dereference.

fs/dlm/memory.c +3 -5
index da64df7..7cd24bc 100644
@@ -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)
maintainer
#1 lore raw

PATCH 1/1 dlm: NULL dereference on failure in kmem_cache_create()

Quoted 2 lines · Dan Carpenter

We aren't allowed to pass NULL pointers to kmem_cache_destroy() so if both allocations fail, it leads to a NULL dereference.

thanks, added that to next branch.