Commit 491ed06f authored by Brian Norris's avatar Brian Norris Committed by David Woodhouse

mtd: nand_bbt: use string library

Some nand_bbt code can be shortened by using memcmp() and memchr_inv().
As an added bonus, there is a possible performance benefit.

Borrowed some code from Akinobu Mita.
Signed-off-by: default avatarBrian Norris <computersforpeace@gmail.com>
Signed-off-by: default avatarArtem Bityutskiy <artem.bityutskiy@linux.intel.com>
Signed-off-by: default avatarDavid Woodhouse <David.Woodhouse@intel.com>
parent 7b5a2d40
...@@ -68,6 +68,7 @@ ...@@ -68,6 +68,7 @@
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/vmalloc.h> #include <linux/vmalloc.h>
#include <linux/export.h> #include <linux/export.h>
#include <linux/string.h>
static int check_pattern_no_oob(uint8_t *buf, struct nand_bbt_descr *td) static int check_pattern_no_oob(uint8_t *buf, struct nand_bbt_descr *td)
{ {
...@@ -89,19 +90,16 @@ static int check_pattern_no_oob(uint8_t *buf, struct nand_bbt_descr *td) ...@@ -89,19 +90,16 @@ static int check_pattern_no_oob(uint8_t *buf, struct nand_bbt_descr *td)
*/ */
static int check_pattern(uint8_t *buf, int len, int paglen, struct nand_bbt_descr *td) static int check_pattern(uint8_t *buf, int len, int paglen, struct nand_bbt_descr *td)
{ {
int i, end = 0; int end = 0;
uint8_t *p = buf; uint8_t *p = buf;
if (td->options & NAND_BBT_NO_OOB) if (td->options & NAND_BBT_NO_OOB)
return check_pattern_no_oob(buf, td); return check_pattern_no_oob(buf, td);
end = paglen + td->offs; end = paglen + td->offs;
if (td->options & NAND_BBT_SCANEMPTY) { if (td->options & NAND_BBT_SCANEMPTY)
for (i = 0; i < end; i++) { if (memchr_inv(p, 0xff, end))
if (p[i] != 0xff) return -1;
return -1;
}
}
p += end; p += end;
/* Compare the pattern */ /* Compare the pattern */
...@@ -111,10 +109,8 @@ static int check_pattern(uint8_t *buf, int len, int paglen, struct nand_bbt_desc ...@@ -111,10 +109,8 @@ static int check_pattern(uint8_t *buf, int len, int paglen, struct nand_bbt_desc
if (td->options & NAND_BBT_SCANEMPTY) { if (td->options & NAND_BBT_SCANEMPTY) {
p += td->len; p += td->len;
end += td->len; end += td->len;
for (i = end; i < len; i++) { if (memchr_inv(p, 0xff, len - end))
if (*p++ != 0xff) return -1;
return -1;
}
} }
return 0; return 0;
} }
...@@ -130,14 +126,9 @@ static int check_pattern(uint8_t *buf, int len, int paglen, struct nand_bbt_desc ...@@ -130,14 +126,9 @@ 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) static int check_short_pattern(uint8_t *buf, struct nand_bbt_descr *td)
{ {
int i;
uint8_t *p = buf;
/* Compare the pattern */ /* Compare the pattern */
for (i = 0; i < td->len; i++) { if (memcmp(buf + td->offs, td->pattern, td->len))
if (p[td->offs + i] != td->pattern[i]) return -1;
return -1;
}
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment