From patchwork Mon Mar 19 22:46:29 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Reardon X-Patchwork-Id: 147671 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 7E90DB6EEE for ; Tue, 20 Mar 2012 09:47:32 +1100 (EST) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1S9lLX-00026L-1w; Mon, 19 Mar 2012 22:46:35 +0000 Received: from [78.46.68.141] (helo=eristoteles.iwoars.net) by merlin.infradead.org with smtp (Exim 4.76 #1 (Red Hat Linux)) id 1S9lLT-00024j-Q0 for linux-mtd@lists.infradead.org; Mon, 19 Mar 2012 22:46:33 +0000 Received: (qmail 26633 invoked by uid 5144); 19 Mar 2012 23:46:29 +0100 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 19 Mar 2012 23:46:29 +0100 Date: Mon, 19 Mar 2012 23:46:29 +0100 (CET) From: Joel Reardon X-X-Sender: joel@eristoteles.iwoars.net To: Artem Bityutskiy Subject: Re: [patch] Move CRC computation to separate function In-Reply-To: <1330531826.3545.128.camel@sauron.fi.intel.com> Message-ID: References: <1330531826.3545.128.camel@sauron.fi.intel.com> User-Agent: Alpine 2.00 (DEB 1167 2008-08-23) MIME-Version: 1.0 X-Spam-Note: CRM114 invocation failed X-Spam-Score: -1.1 (-) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-1.1 points) pts rule name description ---- ---------------------- -------------------------------------------------- -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.8 RDNS_NONE Delivered to internal network by a host with no rDNS Cc: linux-fsdevel@vger.kernel.org, linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org 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 This patch moves the computation of CRCs for data nodes from within ubifs_prepare_node to a separate function ubifs_set_datanode_crc, which takes a data node, and computes and sets the CRC. This is to avoid duplication of the CRC computation code in other places where it may be needed. Signed-off-by: Joel Reardon --- fs/ubifs/io.c | 16 +++++++++++++--- fs/ubifs/ubifs.h | 1 + 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c index 9228950..9d39b27 100644 --- a/fs/ubifs/io.c +++ b/fs/ubifs/io.c @@ -367,6 +367,18 @@ static unsigned long long next_sqnum(struct ubifs_info *c) } /** + * ubifs_set_datanode_crc - writes the crc for a data node to the common + * header. + * @node: the data node + */ +void ubifs_set_datanode_crc(void *node) +{ + struct ubifs_ch *ch = (struct ubifs_ch *) node; + int len = le32_to_cpu(ch->len); + ch->crc = cpu_to_le32(crc32(UBIFS_CRC32_INIT, node + 8, len - 8)); +} + +/** * ubifs_prepare_node - prepare node to be written to flash. * @c: UBIFS file-system description object * @node: the node to pad @@ -379,7 +391,6 @@ static unsigned long long next_sqnum(struct ubifs_info *c) */ void ubifs_prepare_node(struct ubifs_info *c, void *node, int len, int pad) { - uint32_t crc; struct ubifs_ch *ch = node; unsigned long long sqnum = next_sqnum(c); @@ -390,8 +401,7 @@ void ubifs_prepare_node(struct ubifs_info *c, void *node, int len, int pad) ch->group_type = UBIFS_NO_NODE_GROUP; ch->sqnum = cpu_to_le64(sqnum); ch->padding[0] = ch->padding[1] = 0; - crc = crc32(UBIFS_CRC32_INIT, node + 8, len - 8); - ch->crc = cpu_to_le32(crc); + ubifs_set_datanode_crc(node); if (pad) { len = ALIGN(len, 8); diff --git a/fs/ubifs/ubifs.h b/fs/ubifs/ubifs.h index 7c343e1..bfd0798 100644 --- a/fs/ubifs/ubifs.h +++ b/fs/ubifs/ubifs.h @@ -1486,6 +1486,7 @@ int ubifs_write_node(struct ubifs_info *c, void *node, int len, int lnum, int offs, int dtype); int ubifs_check_node(const struct ubifs_info *c, const void *buf, int lnum, int offs, int quiet, int must_chk_crc); +void ubifs_set_datanode_crc(void *node); void ubifs_prepare_node(struct ubifs_info *c, void *buf, int len, int pad); void ubifs_prep_grp_node(struct ubifs_info *c, void *node, int len, int last); int ubifs_io_init(struct ubifs_info *c);