From patchwork Thu Nov 17 23:00:52 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Meyer X-Patchwork-Id: 126329 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:4978:20e::2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 7244DB7258 for ; Fri, 18 Nov 2011 10:03:21 +1100 (EST) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1RRAxg-0005Nh-NQ; Thu, 17 Nov 2011 23:01:40 +0000 Received: from bombadil.infradead.org ([2001:4830:2446:ff00:4687:fcff:fea6:5117]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1RRAxe-0005Nc-6v for linux-mtd@merlin.infradead.org; Thu, 17 Nov 2011 23:01:38 +0000 Received: from www17.your-server.de ([213.133.104.17]) by bombadil.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1RRAxb-0003te-2o for linux-mtd@lists.infradead.org; Thu, 17 Nov 2011 23:01:36 +0000 Received: from [84.59.135.73] (helo=[192.168.2.108]) by www17.your-server.de with esmtpsa (SSLv3:AES256-SHA:256) (Exim 4.72) (envelope-from ) id 1RRAx0-0005nj-Bk; Fri, 18 Nov 2011 00:01:11 +0100 Message-ID: <1321570852.1624.312.camel@localhost.localdomain> Subject: [PATCH] UBIFS: Use kmemdup rather than duplicating its implementation From: Thomas Meyer To: dedekind1@gmail.com, adrian.hunter@intel.com, linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org Date: Fri, 18 Nov 2011 00:00:52 +0100 X-Mailer: Evolution 3.2.1 (3.2.1-2.fc16) Mime-Version: 1.0 X-Authenticated-Sender: thomas@m3y3r.de X-Virus-Scanned: Clear (ClamAV 0.97.3/13904/Tue Nov 8 04:31:35 2011) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20111117_180135_295489_DC10F583 X-CRM114-Status: UNSURE ( 6.96 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -1.9 (-) X-Spam-Report: SpamAssassin version 3.3.2 on bombadil.infradead.org summary: Content analysis details: (-1.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-mtd-bounces@lists.infradead.org Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org The semantic patch that makes this change is available in scripts/coccinelle/api/memdup.cocci. Signed-off-by: Thomas Meyer 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;