public inbox for kernel-janitors@vger.kernel.org
 help / color / mirror / Atom feed
* [patch] dlm: NULL dereference on failure in kmem_cache_create()
@ 2012-05-15  8:58 Dan Carpenter
  2012-05-15 15:40 ` David Teigland
  0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2012-05-15  8:58 UTC (permalink / raw)
  To: kernel-janitors

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>

diff --git a/fs/dlm/memory.c b/fs/dlm/memory.c
index da64df7..7cd24bc 100644
--- a/fs/dlm/memory.c
+++ b/fs/dlm/memory.c
@@ -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)

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [patch] dlm: NULL dereference on failure in kmem_cache_create()
  2012-05-15  8:58 [patch] dlm: NULL dereference on failure in kmem_cache_create() Dan Carpenter
@ 2012-05-15 15:40 ` David Teigland
  0 siblings, 0 replies; 2+ messages in thread
From: David Teigland @ 2012-05-15 15:40 UTC (permalink / raw)
  To: kernel-janitors

On Tue, May 15, 2012 at 11:58:12AM +0300, Dan Carpenter wrote:
> 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.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-05-15 15:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-15  8:58 [patch] dlm: NULL dereference on failure in kmem_cache_create() Dan Carpenter
2012-05-15 15:40 ` David Teigland

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox