diff options
author | Brian Norris <computersforpeace@gmail.com> | 2012-06-22 19:35:44 -0400 |
---|---|---|
committer | David Woodhouse <David.Woodhouse@intel.com> | 2012-09-29 09:51:13 -0400 |
commit | 491ed06f334955578f0c43d298c46ea1a7ea9e1b (patch) | |
tree | 0522c7baadf16d60488c1861eef084b91c0b9b6f /drivers/mtd/nand | |
parent | 7b5a2d40978fbb046b99b4030ce2785b66a451a5 (diff) |
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: Brian Norris <computersforpeace@gmail.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Diffstat (limited to 'drivers/mtd/nand')
-rw-r--r-- | drivers/mtd/nand/nand_bbt.c | 27 |
1 files changed, 9 insertions, 18 deletions
diff --git a/drivers/mtd/nand/nand_bbt.c b/drivers/mtd/nand/nand_bbt.c index e23115be079e..f5839f06cece 100644 --- a/drivers/mtd/nand/nand_bbt.c +++ b/drivers/mtd/nand/nand_bbt.c | |||
@@ -68,6 +68,7 @@ | |||
68 | #include <linux/delay.h> | 68 | #include <linux/delay.h> |
69 | #include <linux/vmalloc.h> | 69 | #include <linux/vmalloc.h> |
70 | #include <linux/export.h> | 70 | #include <linux/export.h> |
71 | #include <linux/string.h> | ||
71 | 72 | ||
72 | static int check_pattern_no_oob(uint8_t *buf, struct nand_bbt_descr *td) | 73 | static int check_pattern_no_oob(uint8_t *buf, struct nand_bbt_descr *td) |
73 | { | 74 | { |
@@ -89,19 +90,16 @@ static int check_pattern_no_oob(uint8_t *buf, struct nand_bbt_descr *td) | |||
89 | */ | 90 | */ |
90 | static int check_pattern(uint8_t *buf, int len, int paglen, struct nand_bbt_descr *td) | 91 | static int check_pattern(uint8_t *buf, int len, int paglen, struct nand_bbt_descr *td) |
91 | { | 92 | { |
92 | int i, end = 0; | 93 | int end = 0; |
93 | uint8_t *p = buf; | 94 | uint8_t *p = buf; |
94 | 95 | ||
95 | if (td->options & NAND_BBT_NO_OOB) | 96 | if (td->options & NAND_BBT_NO_OOB) |
96 | return check_pattern_no_oob(buf, td); | 97 | return check_pattern_no_oob(buf, td); |
97 | 98 | ||
98 | end = paglen + td->offs; | 99 | end = paglen + td->offs; |
99 | if (td->options & NAND_BBT_SCANEMPTY) { | 100 | if (td->options & NAND_BBT_SCANEMPTY) |
100 | for (i = 0; i < end; i++) { | 101 | if (memchr_inv(p, 0xff, end)) |
101 | if (p[i] != 0xff) | 102 | return -1; |
102 | return -1; | ||
103 | } | ||
104 | } | ||
105 | p += end; | 103 | p += end; |
106 | 104 | ||
107 | /* Compare the pattern */ | 105 | /* Compare the pattern */ |
@@ -111,10 +109,8 @@ static int check_pattern(uint8_t *buf, int len, int paglen, struct nand_bbt_desc | |||
111 | if (td->options & NAND_BBT_SCANEMPTY) { | 109 | if (td->options & NAND_BBT_SCANEMPTY) { |
112 | p += td->len; | 110 | p += td->len; |
113 | end += td->len; | 111 | end += td->len; |
114 | for (i = end; i < len; i++) { | 112 | if (memchr_inv(p, 0xff, len - end)) |
115 | if (*p++ != 0xff) | 113 | return -1; |
116 | return -1; | ||
117 | } | ||
118 | } | 114 | } |
119 | return 0; | 115 | return 0; |
120 | } | 116 | } |
@@ -130,14 +126,9 @@ static int check_pattern(uint8_t *buf, int len, int paglen, struct nand_bbt_desc | |||
130 | */ | 126 | */ |
131 | static int check_short_pattern(uint8_t *buf, struct nand_bbt_descr *td) | 127 | static int check_short_pattern(uint8_t *buf, struct nand_bbt_descr *td) |
132 | { | 128 | { |
133 | int i; | ||
134 | uint8_t *p = buf; | ||
135 | |||
136 | /* Compare the pattern */ | 129 | /* Compare the pattern */ |
137 | for (i = 0; i < td->len; i++) { | 130 | if (memcmp(buf + td->offs, td->pattern, td->len)) |
138 | if (p[td->offs + i] != td->pattern[i]) | 131 | return -1; |
139 | return -1; | ||
140 | } | ||
141 | return 0; | 132 | return 0; |
142 | } | 133 | } |
143 | 134 | ||