linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] UBIFS: Use kmemdup rather than duplicating its implementation
@ 2011-11-12 12:03 Thomas Meyer
  2011-11-17 22:29 ` Artem Bityutskiy
  0 siblings, 1 reply; 4+ messages in thread
From: Thomas Meyer @ 2011-11-12 12:03 UTC (permalink / raw)
  To: Artem Bityutskiy, adrian.hunter, linux-kernel

From: Thomas Meyer <thomas@m3y3r.de>

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>
---

diff -u -p a/fs/ubifs/tnc.c b/fs/ubifs/tnc.c
--- a/fs/ubifs/tnc.c 2011-11-07 19:38:24.250503228 +0100
+++ b/fs/ubifs/tnc.c 2011-11-08 10:35:18.593599122 +0100
@@ -344,12 +344,11 @@ static int lnc_add(struct ubifs_info *c,
 		return err;
 	}
 
-	lnc_node = kmalloc(zbr->len, GFP_NOFS);
+	lnc_node = kmemdup(node, zbr->len, GFP_NOFS);
 	if (!lnc_node)
 		/* We don't have to have the cache, so no error */
 		return 0;
 
-	memcpy(lnc_node, node, zbr->len);
 	zbr->leaf = lnc_node;
 	return 0;
 }

diff -u -p a/fs/ubifs/xattr.c b/fs/ubifs/xattr.c
--- a/fs/ubifs/xattr.c 2011-11-07 19:38:24.257169996 +0100
+++ b/fs/ubifs/xattr.c 2011-11-08 10:35:21.073632366 +0100
@@ -138,12 +138,11 @@ static int create_xattr(struct ubifs_inf
 	ui = ubifs_inode(inode);
 	ui->xattr = 1;
 	ui->flags |= UBIFS_XATTR_FL;
-	ui->data = kmalloc(size, GFP_NOFS);
+	ui->data = kmemdup(value, size, GFP_NOFS);
 	if (!ui->data) {
 		err = -ENOMEM;
 		goto out_free;
 	}
-	memcpy(ui->data, value, size);
 	inode->i_size = ui->ui_size = size;
 	ui->data_len = size;
 
@@ -204,12 +203,11 @@ static int change_xattr(struct ubifs_inf
 		return err;
 
 	kfree(ui->data);
-	ui->data = kmalloc(size, GFP_NOFS);
+	ui->data = kmemdup(value, size, GFP_NOFS);
 	if (!ui->data) {
 		err = -ENOMEM;
 		goto out_free;
 	}
-	memcpy(ui->data, value, size);
 	inode->i_size = ui->ui_size = size;
 	ui->data_len = size;
diff -u -p a/fs/ubifs/lpt.c b/fs/ubifs/lpt.c
--- a/fs/ubifs/lpt.c 2011-11-07 19:38:24.223836156 +0100
+++ b/fs/ubifs/lpt.c 2011-11-08 10:35:23.637000062 +0100
@@ -1986,12 +1986,11 @@ again:
 
 				if (path[h].in_tree)
 					continue;
-				nnode = kmalloc(sz, GFP_NOFS);
+				nnode = kmemdup(&path[h].nnode, sz, GFP_NOFS);
 				if (!nnode) {
 					err = -ENOMEM;
 					goto out;
 				}
-				memcpy(nnode, &path[h].nnode, sz);
 				parent = nnode->parent;
 				parent->nbranch[nnode->iip].nnode = nnode;
 				path[h].ptr.nnode = nnode;
@@ -2004,12 +2003,11 @@ again:
 				const size_t sz = sizeof(struct ubifs_pnode);
 				struct ubifs_nnode *parent;
 
-				pnode = kmalloc(sz, GFP_NOFS);
+				pnode = kmemdup(&path[h].pnode, sz, GFP_NOFS);
 				if (!pnode) {
 					err = -ENOMEM;
 					goto out;
 				}
-				memcpy(pnode, &path[h].pnode, sz);
 				parent = pnode->parent;
 				parent->nbranch[pnode->iip].pnode = pnode;
 				path[h].ptr.pnode = pnode;



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

* Re: [PATCH] UBIFS: Use kmemdup rather than duplicating its implementation
  2011-11-12 12:03 Thomas Meyer
@ 2011-11-17 22:29 ` Artem Bityutskiy
  0 siblings, 0 replies; 4+ messages in thread
From: Artem Bityutskiy @ 2011-11-17 22:29 UTC (permalink / raw)
  To: Thomas Meyer; +Cc: adrian.hunter, linux-kernel

On Sat, 2011-11-12 at 13:03 +0100, Thomas Meyer wrote:
> From: Thomas Meyer <thomas@m3y3r.de>
> 
> 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>

Thanks, but could you please send a patch which I can apply using git
am? This one does not apply:

[dedekind@koala ubifs-2.6 (master)]$ patch --dry-run -p1 < ~/tmp/x.mbox 
patching file fs/ubifs/tnc.c
patching file fs/ubifs/xattr.c
patch: **** malformed patch at line 94: diff -u -p a/fs/ubifs/lpt.c b/fs/ubifs/lpt.c

Artem.



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

* [PATCH] UBIFS: Use kmemdup rather than duplicating its implementation
@ 2011-11-17 23:00 Thomas Meyer
  2011-11-22 10:55 ` Artem Bityutskiy
  0 siblings, 1 reply; 4+ messages in thread
From: Thomas Meyer @ 2011-11-17 23:00 UTC (permalink / raw)
  To: dedekind1, adrian.hunter, linux-mtd, linux-kernel

The semantic patch that makes this change is available
in scripts/coccinelle/api/memdup.cocci.

Signed-off-by: Thomas Meyer <thomas@m3y3r.de>
---

diff -u -p a/fs/ubifs/lpt.c b/fs/ubifs/lpt.c
--- a/fs/ubifs/lpt.c 2011-11-07 19:38:24.223836156 +0100
+++ b/fs/ubifs/lpt.c 2011-11-08 10:35:23.637000062 +0100
@@ -1986,12 +1986,11 @@ again:
 
 				if (path[h].in_tree)
 					continue;
-				nnode = kmalloc(sz, GFP_NOFS);
+				nnode = kmemdup(&path[h].nnode, sz, GFP_NOFS);
 				if (!nnode) {
 					err = -ENOMEM;
 					goto out;
 				}
-				memcpy(nnode, &path[h].nnode, sz);
 				parent = nnode->parent;
 				parent->nbranch[nnode->iip].nnode = nnode;
 				path[h].ptr.nnode = nnode;
@@ -2004,12 +2003,11 @@ again:
 				const size_t sz = sizeof(struct ubifs_pnode);
 				struct ubifs_nnode *parent;
 
-				pnode = kmalloc(sz, GFP_NOFS);
+				pnode = kmemdup(&path[h].pnode, sz, GFP_NOFS);
 				if (!pnode) {
 					err = -ENOMEM;
 					goto out;
 				}
-				memcpy(pnode, &path[h].pnode, sz);
 				parent = pnode->parent;
 				parent->nbranch[pnode->iip].pnode = pnode;
 				path[h].ptr.pnode = pnode;
diff -u -p a/fs/ubifs/tnc.c b/fs/ubifs/tnc.c
--- a/fs/ubifs/tnc.c 2011-11-07 19:38:24.250503228 +0100
+++ b/fs/ubifs/tnc.c 2011-11-08 10:35:18.593599122 +0100
@@ -344,12 +344,11 @@ static int lnc_add(struct ubifs_info *c,
 		return err;
 	}
 
-	lnc_node = kmalloc(zbr->len, GFP_NOFS);
+	lnc_node = kmemdup(node, zbr->len, GFP_NOFS);
 	if (!lnc_node)
 		/* We don't have to have the cache, so no error */
 		return 0;
 
-	memcpy(lnc_node, node, zbr->len);
 	zbr->leaf = lnc_node;
 	return 0;
 }
diff -u -p a/fs/ubifs/xattr.c b/fs/ubifs/xattr.c
--- a/fs/ubifs/xattr.c 2011-11-07 19:38:24.257169996 +0100
+++ b/fs/ubifs/xattr.c 2011-11-08 10:35:21.073632366 +0100
@@ -138,12 +138,11 @@ static int create_xattr(struct ubifs_inf
 	ui = ubifs_inode(inode);
 	ui->xattr = 1;
 	ui->flags |= UBIFS_XATTR_FL;
-	ui->data = kmalloc(size, GFP_NOFS);
+	ui->data = kmemdup(value, size, GFP_NOFS);
 	if (!ui->data) {
 		err = -ENOMEM;
 		goto out_free;
 	}
-	memcpy(ui->data, value, size);
 	inode->i_size = ui->ui_size = size;
 	ui->data_len = size;
 
@@ -204,12 +203,11 @@ static int change_xattr(struct ubifs_inf
 		return err;
 
 	kfree(ui->data);
-	ui->data = kmalloc(size, GFP_NOFS);
+	ui->data = kmemdup(value, size, GFP_NOFS);
 	if (!ui->data) {
 		err = -ENOMEM;
 		goto out_free;
 	}
-	memcpy(ui->data, value, size);
 	inode->i_size = ui->ui_size = size;
 	ui->data_len = size;
 



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

* Re: [PATCH] UBIFS: Use kmemdup rather than duplicating its implementation
  2011-11-17 23:00 [PATCH] UBIFS: Use kmemdup rather than duplicating its implementation Thomas Meyer
@ 2011-11-22 10:55 ` Artem Bityutskiy
  0 siblings, 0 replies; 4+ messages in thread
From: Artem Bityutskiy @ 2011-11-22 10:55 UTC (permalink / raw)
  To: Thomas Meyer; +Cc: adrian.hunter, linux-mtd, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 294 bytes --]

On Fri, 2011-11-18 at 00:00 +0100, Thomas Meyer wrote:
> The semantic patch that makes this change is available
> in scripts/coccinelle/api/memdup.cocci.
> 
> Signed-off-by: Thomas Meyer <thomas@m3y3r.de>

Pushed to the UBIFS git tree, thank you!

-- 
Best Regards,
Artem Bityutskiy

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

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

end of thread, other threads:[~2011-11-22 10:54 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-11-17 23:00 [PATCH] UBIFS: Use kmemdup rather than duplicating its implementation Thomas Meyer
2011-11-22 10:55 ` Artem Bityutskiy
  -- strict thread matches above, loose matches on Subject: below --
2011-11-12 12:03 Thomas Meyer
2011-11-17 22:29 ` Artem Bityutskiy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).