From patchwork Fri Jan 27 14:24:51 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akinobu Mita X-Patchwork-Id: 138230 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 A1C2B1007D2 for ; Sat, 28 Jan 2012 01:26:04 +1100 (EST) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1Rqmjg-0007No-TA; Fri, 27 Jan 2012 14:25:04 +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 1RqmjX-0007KX-J0 for linux-mtd@lists.infradead.org; Fri, 27 Jan 2012 14:24:56 +0000 Received: by mail-pw0-f49.google.com with SMTP id x9so2050943pbd.36 for ; Fri, 27 Jan 2012 06:24:55 -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=eNVIlLtRhMeKwC1O4FUYHoWaSjAqWPi5DZDdJ70Fqxc=; b=NB1K49nPQS98qyIgTl1uAVzGkPQ5HDot4OKRYOvPa5NCsD/w/i8DVz+Z0xBs0hqMF5 2AqjIAG5VS97HEnWQ8rdZX+t7yQTS+oqTesNK6gYAX7v7pcao1DHmofy9NfAjRBTjUm9 HyxBIUWIvTyy05oz33YoZB+893wRrUeWzglEE= Received: by 10.68.232.202 with SMTP id tq10mr14844577pbc.68.1327674295293; Fri, 27 Jan 2012 06:24:55 -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.52 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 27 Jan 2012 06:24:54 -0800 (PST) From: Akinobu Mita To: linux-kernel@vger.kernel.org, akpm@linux-foundation.org Subject: [PATCH] mtd/ubi: use memchr_inv Date: Fri, 27 Jan 2012 23:24:51 +0900 Message-Id: <1327674295-3700-4-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, David Woodhouse , Akinobu Mita , Artem Bityutskiy 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 ubi_check_pattern which is no longer used. Signed-off-by: Akinobu Mita Cc: Artem Bityutskiy Cc: David Woodhouse Cc: linux-mtd@lists.infradead.org --- drivers/mtd/ubi/io.c | 14 +++++--------- drivers/mtd/ubi/misc.c | 19 ------------------- drivers/mtd/ubi/scan.c | 2 +- drivers/mtd/ubi/ubi.h | 1 - 4 files changed, 6 insertions(+), 30 deletions(-) diff --git a/drivers/mtd/ubi/io.c b/drivers/mtd/ubi/io.c index 5cde4e5..9fc27d3 100644 --- a/drivers/mtd/ubi/io.c +++ b/drivers/mtd/ubi/io.c @@ -435,8 +435,7 @@ static int torture_peb(struct ubi_device *ubi, int pnum) if (err) goto out; - err = ubi_check_pattern(ubi->peb_buf1, 0xFF, ubi->peb_size); - if (err == 0) { + if (memchr_inv(ubi->peb_buf1, 0xFF, ubi->peb_size)) { ubi_err("erased PEB %d, but a non-0xFF byte found", pnum); err = -EIO; @@ -454,9 +453,7 @@ static int torture_peb(struct ubi_device *ubi, int pnum) if (err) goto out; - err = ubi_check_pattern(ubi->peb_buf1, patterns[i], - ubi->peb_size); - if (err == 0) { + if (memchr_inv(ubi->peb_buf1, patterns[i], ubi->peb_size)) { ubi_err("pattern %x checking failed for PEB %d", patterns[i], pnum); err = -EIO; @@ -783,7 +780,7 @@ int ubi_io_read_ec_hdr(struct ubi_device *ubi, int pnum, * 0xFF. If yes, this physical eraseblock is assumed to be * empty. */ - if (ubi_check_pattern(ec_hdr, 0xFF, UBI_EC_HDR_SIZE)) { + if (!memchr_inv(ec_hdr, 0xFF, UBI_EC_HDR_SIZE)) { /* The physical eraseblock is supposedly empty */ if (verbose) ubi_warn("no EC header found at PEB %d, " @@ -1039,7 +1036,7 @@ int ubi_io_read_vid_hdr(struct ubi_device *ubi, int pnum, if (mtd_is_eccerr(read_err)) return UBI_IO_BAD_HDR_EBADMSG; - if (ubi_check_pattern(vid_hdr, 0xFF, UBI_VID_HDR_SIZE)) { + if (!memchr_inv(vid_hdr, 0xFF, UBI_VID_HDR_SIZE)) { if (verbose) ubi_warn("no VID header found at PEB %d, " "only 0xFF bytes", pnum); @@ -1427,8 +1424,7 @@ int ubi_dbg_check_all_ff(struct ubi_device *ubi, int pnum, int offset, int len) goto error; } - err = ubi_check_pattern(buf, 0xFF, len); - if (err == 0) { + if (memchr_inv(buf, 0xFF, len)) { ubi_err("flash region at PEB %d:%d, length %d does not " "contain all 0xFF bytes", pnum, offset, len); goto fail; diff --git a/drivers/mtd/ubi/misc.c b/drivers/mtd/ubi/misc.c index f6a7d7a..0e4b9a2 100644 --- a/drivers/mtd/ubi/misc.c +++ b/drivers/mtd/ubi/misc.c @@ -103,22 +103,3 @@ void ubi_calculate_reserved(struct ubi_device *ubi) if (ubi->beb_rsvd_level < MIN_RESEVED_PEBS) ubi->beb_rsvd_level = MIN_RESEVED_PEBS; } - -/** - * ubi_check_pattern - check if buffer contains only a certain byte pattern. - * @buf: buffer to check - * @patt: the pattern to check - * @size: buffer size in bytes - * - * This function returns %1 in there are only @patt bytes in @buf, and %0 if - * something else was also found. - */ -int ubi_check_pattern(const void *buf, uint8_t patt, int size) -{ - int i; - - for (i = 0; i < size; i++) - if (((const uint8_t *)buf)[i] != patt) - return 0; - return 1; -} diff --git a/drivers/mtd/ubi/scan.c b/drivers/mtd/ubi/scan.c index 0cb17d9..54a56acc 100644 --- a/drivers/mtd/ubi/scan.c +++ b/drivers/mtd/ubi/scan.c @@ -808,7 +808,7 @@ static int check_corruption(struct ubi_device *ubi, struct ubi_vid_hdr *vid_hdr, if (err) goto out_unlock; - if (ubi_check_pattern(ubi->peb_buf1, 0xFF, ubi->leb_size)) + if (!memchr_inv(ubi->peb_buf1, 0xFF, ubi->leb_size)) goto out_unlock; ubi_err("PEB %d contains corrupted VID header, and the data does not " diff --git a/drivers/mtd/ubi/ubi.h b/drivers/mtd/ubi/ubi.h index d51d75d..2ff1eb6 100644 --- a/drivers/mtd/ubi/ubi.h +++ b/drivers/mtd/ubi/ubi.h @@ -519,7 +519,6 @@ int ubi_calc_data_len(const struct ubi_device *ubi, const void *buf, int length); int ubi_check_volume(struct ubi_device *ubi, int vol_id); void ubi_calculate_reserved(struct ubi_device *ubi); -int ubi_check_pattern(const void *buf, uint8_t patt, int size); /* eba.c */ int ubi_eba_unmap_leb(struct ubi_device *ubi, struct ubi_volume *vol,