From patchwork Fri Jan 27 14:24:49 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akinobu Mita X-Patchwork-Id: 138231 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 D07161007D2 for ; Sat, 28 Jan 2012 01:26:05 +1100 (EST) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1RqmjU-0007Ky-Tr; Fri, 27 Jan 2012 14:24:52 +0000 Received: from mail-pw0-f49.google.com ([209.85.160.49]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1RqmjR-0007KX-S9 for linux-mtd@lists.infradead.org; Fri, 27 Jan 2012 14:24:50 +0000 Received: by pbdx9 with SMTP id x9so2050943pbd.36 for ; Fri, 27 Jan 2012 06:24:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=uHumX2zVnE3shCHHpNM1AgWiMAzZluzryFFo9f0dkdw=; b=j5PGx7QpL89d9rSLeCiTWpFVCTRwvQNL4KwYaLuMP4yPNxQKpM+GJ7bleu1s4ojKqU 8mMEYwxeWYRt/DPaTizVDv3dvN5mifKk6qLbTwvOV/Ze8MqWQzqjFu/ZAhQiom7sxlBA N8hSKWPY1SFdModnvmAPPUTw8CloHZKUg1fwE= Received: by 10.68.135.1 with SMTP id po1mr15129726pbb.16.1327674288281; Fri, 27 Jan 2012 06:24:48 -0800 (PST) Received: from localhost.localdomain (p2046-adsao01yokonib2-acca.kanagawa.ocn.ne.jp. [61.214.148.46]) by mx.google.com with ESMTPS id lk11sm20385743pbb.0.2012.01.27.06.24.44 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 27 Jan 2012 06:24:47 -0800 (PST) From: Akinobu Mita To: linux-kernel@vger.kernel.org, akpm@linux-foundation.org Subject: [PATCH] mtd/nand: use string library Date: Fri, 27 Jan 2012 23:24:49 +0900 Message-Id: <1327674295-3700-2-git-send-email-akinobu.mita@gmail.com> X-Mailer: git-send-email 1.7.4.4 In-Reply-To: <1327674295-3700-1-git-send-email-akinobu.mita@gmail.com> References: <1327674295-3700-1-git-send-email-akinobu.mita@gmail.com> X-Spam-Note: CRM114 invocation failed X-Spam-Score: -2.7 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.160.49 listed in list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (akinobu.mita[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature Cc: linux-mtd@lists.infradead.org, Scott Branden , David Woodhouse , Akinobu Mita , Jiandong Zheng 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: , MIME-Version: 1.0 Sender: linux-mtd-bounces@lists.infradead.org Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org - Use memchr_inv to check if the data contains all 0xFF bytes. It is faster than looping for each byte. - Use memcmp to compare memory areas Signed-off-by: Akinobu Mita Cc: Jiandong Zheng Cc: Scott Branden Cc: David Woodhouse Cc: linux-mtd@lists.infradead.org Acked-by: Brian Norris --- drivers/mtd/nand/davinci_nand.c | 7 +++---- drivers/mtd/nand/denali.c | 7 +++---- drivers/mtd/nand/diskonchip.c | 18 +++--------------- drivers/mtd/nand/nand_bbt.c | 16 +++++----------- drivers/mtd/nand/nand_bcm_umi.c | 10 +++------- 5 files changed, 17 insertions(+), 41 deletions(-) diff --git a/drivers/mtd/nand/davinci_nand.c b/drivers/mtd/nand/davinci_nand.c index 6e56615..423a7cc 100644 --- a/drivers/mtd/nand/davinci_nand.c +++ b/drivers/mtd/nand/davinci_nand.c @@ -315,10 +315,9 @@ static int nand_davinci_correct_4bit(struct mtd_info *mtd, unsigned long timeo; /* All bytes 0xff? It's an erased page; ignore its ECC. */ - for (i = 0; i < 10; i++) { - if (ecc_code[i] != 0xff) - goto compare; - } + if (memchr_inv(ecc_code, 0xff, 10)) + goto compare; + return 0; compare: diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c index 3984d48..a87e3a4 100644 --- a/drivers/mtd/nand/denali.c +++ b/drivers/mtd/nand/denali.c @@ -908,10 +908,9 @@ static void read_oob_data(struct mtd_info *mtd, uint8_t *buf, int page) */ bool is_erased(uint8_t *buf, int len) { - int i = 0; - for (i = 0; i < len; i++) - if (buf[i] != 0xFF) - return false; + if (memchr_inv(buf, 0xFF, len)) + return false; + return true; } #define ECC_SECTOR_SIZE 512 diff --git a/drivers/mtd/nand/diskonchip.c b/drivers/mtd/nand/diskonchip.c index df921e7..bf0602e 100644 --- a/drivers/mtd/nand/diskonchip.c +++ b/drivers/mtd/nand/diskonchip.c @@ -945,12 +945,8 @@ static int doc200x_calculate_ecc(struct mtd_info *mtd, const u_char *dat, unsign /* Note: this somewhat expensive test should not be triggered often. It could be optimized away by examining the data in the writebuf routine, and remembering the result. */ - for (i = 0; i < 512; i++) { - if (dat[i] == 0xff) - continue; + if (memchr_inv(dat, 0xff, 512)) emptymatch = 0; - break; - } } /* If emptymatch still =1, we do have an all-0xff data buffer. Return all-0xff ecc value instead of the computed one, so @@ -1000,24 +996,16 @@ static int doc200x_correct_data(struct mtd_info *mtd, u_char *dat, /* If emptymatch=1, the read syndrome is consistent with an all-0xff data and stored ecc block. Check the stored ecc. */ if (emptymatch) { - for (i = 0; i < 6; i++) { - if (read_ecc[i] == 0xff) - continue; + if (memchr_inv(read_ecc, 0xff, 6)) emptymatch = 0; - break; - } } /* If emptymatch still =1, check the data block. */ if (emptymatch) { /* Note: this somewhat expensive test should not be triggered often. It could be optimized away by examining the data in the readbuf routine, and remembering the result. */ - for (i = 0; i < 512; i++) { - if (dat[i] == 0xff) - continue; + if (memchr_inv(dat, 0xff, 512)) emptymatch = 0; - break; - } } /* If emptymatch still =1, this is almost certainly a freshly- erased block, in which case the ECC will not come out right. diff --git a/drivers/mtd/nand/nand_bbt.c b/drivers/mtd/nand/nand_bbt.c index 20a112f..a1b2dd5 100644 --- a/drivers/mtd/nand/nand_bbt.c +++ b/drivers/mtd/nand/nand_bbt.c @@ -100,10 +100,8 @@ static int check_pattern(uint8_t *buf, int len, int paglen, struct nand_bbt_desc end = paglen + td->offs; if (td->options & NAND_BBT_SCANEMPTY) { - for (i = 0; i < end; i++) { - if (p[i] != 0xff) - return -1; - } + if (memchr_inv(p, 0xff, end)) + return -1; } p += end; @@ -133,14 +131,10 @@ static int check_pattern(uint8_t *buf, int len, int paglen, struct nand_bbt_desc */ static int check_short_pattern(uint8_t *buf, struct nand_bbt_descr *td) { - int i; - uint8_t *p = buf; - /* Compare the pattern */ - for (i = 0; i < td->len; i++) { - if (p[td->offs + i] != td->pattern[i]) - return -1; - } + if (memcmp(buf + td->offs, td->pattern, td->len)) + return -1; + return 0; } diff --git a/drivers/mtd/nand/nand_bcm_umi.c b/drivers/mtd/nand/nand_bcm_umi.c index 46a6bc9..ad51dad 100644 --- a/drivers/mtd/nand/nand_bcm_umi.c +++ b/drivers/mtd/nand/nand_bcm_umi.c @@ -109,13 +109,9 @@ int nand_bcm_umi_bch_correct_page(uint8_t *datap, uint8_t *readEccData, * see if errors are correctible */ if ((regValue & REG_UMI_BCH_CTRL_STATUS_UNCORR_ERR) > 0) { - int i; - - for (i = 0; i < numEccBytes; i++) { - if (readEccData[i] != 0xff) { - /* errors cannot be fixed, return -1 */ - return -1; - } + if (memchr_inv(readEccData, 0xff, numEccBytes)) { + /* errors cannot be fixed, return -1 */ + return -1; } /* If ECC is unprogrammed then we can't correct, * assume everything OK */