UBIFS: use kmemdup rather than duplicating its implementation
authorAndrzej Hajda <a.hajda@samsung.com>
Fri, 7 Aug 2015 07:59:31 +0000 (09:59 +0200)
committerRichard Weinberger <richard@nod.at>
Sat, 3 Oct 2015 18:03:14 +0000 (20:03 +0200)
The patch was generated using fixed coccinelle semantic patch
scripts/coccinelle/api/memdup.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2014320

Signed-off-by: Andrzej Hajda <a.hajda@samsung.com>
Reviewed-by: Richard Weinberger <richard@nod.at>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
fs/ubifs/lpt.c
fs/ubifs/tnc.c

index dc9f27e9d61be5b8586af0025d95a0dc305afecc..9a517109da0feda2ac19ba4781072ab4ab4aad31 100644 (file)
@@ -1498,11 +1498,10 @@ static struct ubifs_nnode *dirty_cow_nnode(struct ubifs_info *c,
        }
 
        /* nnode is being committed, so copy it */
-       n = kmalloc(sizeof(struct ubifs_nnode), GFP_NOFS);
+       n = kmemdup(nnode, sizeof(struct ubifs_nnode), GFP_NOFS);
        if (unlikely(!n))
                return ERR_PTR(-ENOMEM);
 
-       memcpy(n, nnode, sizeof(struct ubifs_nnode));
        n->cnext = NULL;
        __set_bit(DIRTY_CNODE, &n->flags);
        __clear_bit(COW_CNODE, &n->flags);
@@ -1549,11 +1548,10 @@ static struct ubifs_pnode *dirty_cow_pnode(struct ubifs_info *c,
        }
 
        /* pnode is being committed, so copy it */
-       p = kmalloc(sizeof(struct ubifs_pnode), GFP_NOFS);
+       p = kmemdup(pnode, sizeof(struct ubifs_pnode), GFP_NOFS);
        if (unlikely(!p))
                return ERR_PTR(-ENOMEM);
 
-       memcpy(p, pnode, sizeof(struct ubifs_pnode));
        p->cnext = NULL;
        __set_bit(DIRTY_CNODE, &p->flags);
        __clear_bit(COW_CNODE, &p->flags);
index 957f5757f3742bf07cdb6747b27b60b8ff2bf97a..fa9a20cc60d6744e13ef7cc2f788f0fda0861d58 100644 (file)
@@ -198,11 +198,10 @@ static struct ubifs_znode *copy_znode(struct ubifs_info *c,
 {
        struct ubifs_znode *zn;
 
-       zn = kmalloc(c->max_znode_sz, GFP_NOFS);
+       zn = kmemdup(znode, c->max_znode_sz, GFP_NOFS);
        if (unlikely(!zn))
                return ERR_PTR(-ENOMEM);
 
-       memcpy(zn, znode, c->max_znode_sz);
        zn->cnext = NULL;
        __set_bit(DIRTY_ZNODE, &zn->flags);
        __clear_bit(COW_ZNODE, &zn->flags);