From: Akinobu Mita <akinobu.mita@gmail.com>
To: linux-kernel@vger.kernel.org, akpm@linux-foundation.org
Cc: linux-mtd@lists.infradead.org,
David Woodhouse <dwmw2@infradead.org>,
Akinobu Mita <akinobu.mita@gmail.com>,
Artem Bityutskiy <dedekind1@gmail.com>
Subject: [PATCH] mtd/ubi: use memchr_inv
Date: Fri, 27 Jan 2012 23:24:51 +0900 [thread overview]
Message-ID: <1327674295-3700-4-git-send-email-akinobu.mita@gmail.com> (raw)
In-Reply-To: <1327674295-3700-1-git-send-email-akinobu.mita@gmail.com>
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 <akinobu.mita@gmail.com>
Cc: Artem Bityutskiy <dedekind1@gmail.com>
Cc: David Woodhouse <dwmw2@infradead.org>
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,
--
1.7.4.4
next prev parent reply other threads:[~2012-01-27 14:24 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1327674295-3700-1-git-send-email-akinobu.mita@gmail.com>
2012-01-27 14:24 ` [PATCH] mtd/nand: use string library Akinobu Mita
2012-01-27 17:16 ` Joe Perches
2012-01-27 18:52 ` Brian Norris
2012-01-27 23:52 ` Akinobu Mita
2012-01-31 17:57 ` Brian Norris
2012-02-01 13:11 ` Akinobu Mita
2012-01-27 14:24 ` [PATCH] mtd/onenand: " Akinobu Mita
2012-01-27 14:24 ` Akinobu Mita [this message]
2012-01-27 14:24 ` [PATCH] mtd/inftlmount: use memchr_inv Akinobu Mita
2012-01-27 14:24 ` [PATCH] mtd/nftlmount: " Akinobu Mita
2012-01-27 14:24 ` [PATCH] mtd/tests: " Akinobu Mita
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1327674295-3700-4-git-send-email-akinobu.mita@gmail.com \
--to=akinobu.mita@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=dedekind1@gmail.com \
--cc=dwmw2@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox