From patchwork Fri Jan 27 14:24:52 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akinobu Mita X-Patchwork-Id: 138229 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 A524D1007D2 for ; Sat, 28 Jan 2012 01:26:00 +1100 (EST) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1Rqmjr-0007R3-Qe; Fri, 27 Jan 2012 14:25:15 +0000 Received: from mail-pz0-f49.google.com ([209.85.210.49]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1Rqmjc-0007Ma-4K for linux-mtd@lists.infradead.org; Fri, 27 Jan 2012 14:25:01 +0000 Received: by dadz9 with SMTP id z9so564831dad.36 for ; Fri, 27 Jan 2012 06:24:59 -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=VkMV4lpZDfDFSKtssn5lBC3aWUojb4GOcemedifXJ1Y=; b=E/zCT9r6+FW2dWajCAUKRMyuCi8gqFbIFOve8NkL/vNPJZMPMZ1frC0ZyupdZQVr6g gdl8wliXq1oqEbpgjcWpKtNZFRg0zMAYWOEI2Y1T2MO68sysbMSAOMAzjfoBFXlOBeBD FGFOFtX7hmkRV/gB9KaJ5MNruc4sJelyOimAg= Received: by 10.68.236.39 with SMTP id ur7mr1139708pbc.98.1327674298935; Fri, 27 Jan 2012 06:24:58 -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.55 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 27 Jan 2012 06:24:58 -0800 (PST) From: Akinobu Mita To: linux-kernel@vger.kernel.org, akpm@linux-foundation.org Subject: [PATCH] mtd/inftlmount: use memchr_inv Date: Fri, 27 Jan 2012 23:24:52 +0900 Message-Id: <1327674295-3700-5-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.210.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, David Woodhouse , Akinobu Mita 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. This also removes memcmpb which is no longer used. Signed-off-by: Akinobu Mita Cc: David Woodhouse Cc: linux-mtd@lists.infradead.org --- drivers/mtd/inftlmount.c | 14 ++------------ 1 files changed, 2 insertions(+), 12 deletions(-) diff --git a/drivers/mtd/inftlmount.c b/drivers/mtd/inftlmount.c index 4adc037..419b1c9 100644 --- a/drivers/mtd/inftlmount.c +++ b/drivers/mtd/inftlmount.c @@ -320,16 +320,6 @@ static int find_boot_record(struct INFTLrecord *inftl) return -1; } -static int memcmpb(void *a, int c, int n) -{ - int i; - for (i = 0; i < n; i++) { - if (c != ((unsigned char *)a)[i]) - return 1; - } - return 0; -} - /* * check_free_sector: check if a free sector is actually FREE, * i.e. All 0xff in data and oob area. @@ -345,14 +335,14 @@ static int check_free_sectors(struct INFTLrecord *inftl, unsigned int address, for (i = 0; i < len; i += SECTORSIZE) { if (mtd_read(mtd, address, SECTORSIZE, &retlen, buf)) return -1; - if (memcmpb(buf, 0xff, SECTORSIZE) != 0) + if (memchr_inv(buf, 0xff, SECTORSIZE)) return -1; if (check_oob) { if(inftl_read_oob(mtd, address, mtd->oobsize, &retlen, &buf[SECTORSIZE]) < 0) return -1; - if (memcmpb(buf + SECTORSIZE, 0xff, mtd->oobsize) != 0) + if (memchr_inv(buf + SECTORSIZE, 0xff, mtd->oobsize)) return -1; } address += SECTORSIZE;