fs/ocfs2/dlm/dlmlock.c: free kmem_cache_zalloc'd data using kmem_cache_free
authorJulia Lawall <julia@diku.dk>
Sat, 9 Jul 2011 16:04:39 +0000 (18:04 +0200)
committerJoel Becker <jlbec@evilplan.org>
Thu, 17 Nov 2011 09:46:46 +0000 (01:46 -0800)
Memory allocated using kmem_cache_zalloc should be freed using
kmem_cache_free, not kfree.

The semantic patch that fixes this problem is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@@
expression x,e,e1,e2;
@@

x = kmem_cache_zalloc(e1,e2)
... when != x = e
?-kfree(x)
+kmem_cache_free(e1,x)
// </smpl>

Signed-off-by: Julia Lawall <julia@diku.dk>
Signed-off-by: Joel Becker <jlbec@evilplan.org>
fs/ocfs2/dlm/dlmlock.c

index f32fcba04923dba44c6bc35fdeb0c7e1da428cc5..975810b98492a34f4576b9d3d3ac3e4421fb18c1 100644 (file)
@@ -438,7 +438,7 @@ struct dlm_lock * dlm_new_lock(int type, u8 node, u64 cookie,
                /* zero memory only if kernel-allocated */
                lksb = kzalloc(sizeof(*lksb), GFP_NOFS);
                if (!lksb) {
-                       kfree(lock);
+                       kmem_cache_free(dlm_lock_cache, lock);
                        return NULL;
                }
                kernel_allocated = 1;