mirror of
https://github.com/torvalds/linux
synced 2024-09-20 02:57:25 +00:00
UBIFS: Use kmemdup rather than duplicating its implementation
The semantic patch that makes this change is available in scripts/coccinelle/api/memdup.cocci. Signed-off-by: Thomas Meyer <thomas@m3y3r.de> Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
This commit is contained in:
parent
cfcfc9eca2
commit
eaecf43a69
|
@ -1986,12 +1986,11 @@ int ubifs_lpt_scan_nolock(struct ubifs_info *c, int start_lnum, int end_lnum,
|
||||||
|
|
||||||
if (path[h].in_tree)
|
if (path[h].in_tree)
|
||||||
continue;
|
continue;
|
||||||
nnode = kmalloc(sz, GFP_NOFS);
|
nnode = kmemdup(&path[h].nnode, sz, GFP_NOFS);
|
||||||
if (!nnode) {
|
if (!nnode) {
|
||||||
err = -ENOMEM;
|
err = -ENOMEM;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
memcpy(nnode, &path[h].nnode, sz);
|
|
||||||
parent = nnode->parent;
|
parent = nnode->parent;
|
||||||
parent->nbranch[nnode->iip].nnode = nnode;
|
parent->nbranch[nnode->iip].nnode = nnode;
|
||||||
path[h].ptr.nnode = nnode;
|
path[h].ptr.nnode = nnode;
|
||||||
|
@ -2004,12 +2003,11 @@ int ubifs_lpt_scan_nolock(struct ubifs_info *c, int start_lnum, int end_lnum,
|
||||||
const size_t sz = sizeof(struct ubifs_pnode);
|
const size_t sz = sizeof(struct ubifs_pnode);
|
||||||
struct ubifs_nnode *parent;
|
struct ubifs_nnode *parent;
|
||||||
|
|
||||||
pnode = kmalloc(sz, GFP_NOFS);
|
pnode = kmemdup(&path[h].pnode, sz, GFP_NOFS);
|
||||||
if (!pnode) {
|
if (!pnode) {
|
||||||
err = -ENOMEM;
|
err = -ENOMEM;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
memcpy(pnode, &path[h].pnode, sz);
|
|
||||||
parent = pnode->parent;
|
parent = pnode->parent;
|
||||||
parent->nbranch[pnode->iip].pnode = pnode;
|
parent->nbranch[pnode->iip].pnode = pnode;
|
||||||
path[h].ptr.pnode = pnode;
|
path[h].ptr.pnode = pnode;
|
||||||
|
|
|
@ -344,12 +344,11 @@ static int lnc_add(struct ubifs_info *c, struct ubifs_zbranch *zbr,
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
lnc_node = kmalloc(zbr->len, GFP_NOFS);
|
lnc_node = kmemdup(node, zbr->len, GFP_NOFS);
|
||||||
if (!lnc_node)
|
if (!lnc_node)
|
||||||
/* We don't have to have the cache, so no error */
|
/* We don't have to have the cache, so no error */
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
memcpy(lnc_node, node, zbr->len);
|
|
||||||
zbr->leaf = lnc_node;
|
zbr->leaf = lnc_node;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -138,12 +138,11 @@ static int create_xattr(struct ubifs_info *c, struct inode *host,
|
||||||
ui = ubifs_inode(inode);
|
ui = ubifs_inode(inode);
|
||||||
ui->xattr = 1;
|
ui->xattr = 1;
|
||||||
ui->flags |= UBIFS_XATTR_FL;
|
ui->flags |= UBIFS_XATTR_FL;
|
||||||
ui->data = kmalloc(size, GFP_NOFS);
|
ui->data = kmemdup(value, size, GFP_NOFS);
|
||||||
if (!ui->data) {
|
if (!ui->data) {
|
||||||
err = -ENOMEM;
|
err = -ENOMEM;
|
||||||
goto out_free;
|
goto out_free;
|
||||||
}
|
}
|
||||||
memcpy(ui->data, value, size);
|
|
||||||
inode->i_size = ui->ui_size = size;
|
inode->i_size = ui->ui_size = size;
|
||||||
ui->data_len = size;
|
ui->data_len = size;
|
||||||
|
|
||||||
|
@ -204,12 +203,11 @@ static int change_xattr(struct ubifs_info *c, struct inode *host,
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
kfree(ui->data);
|
kfree(ui->data);
|
||||||
ui->data = kmalloc(size, GFP_NOFS);
|
ui->data = kmemdup(value, size, GFP_NOFS);
|
||||||
if (!ui->data) {
|
if (!ui->data) {
|
||||||
err = -ENOMEM;
|
err = -ENOMEM;
|
||||||
goto out_free;
|
goto out_free;
|
||||||
}
|
}
|
||||||
memcpy(ui->data, value, size);
|
|
||||||
inode->i_size = ui->ui_size = size;
|
inode->i_size = ui->ui_size = size;
|
||||||
ui->data_len = size;
|
ui->data_len = size;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue