aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd/tests
diff options
context:
space:
mode:
authorAkinobu Mita <akinobu.mita@gmail.com>2013-08-03 05:52:11 -0400
committerDavid Woodhouse <David.Woodhouse@intel.com>2013-08-30 16:34:18 -0400
commitbf9c223664e6f5fdf538919c715c45c26dbb4268 (patch)
tree5ae7296f62750375c2dded9d348914a8b2b33e72 /drivers/mtd/tests
parent66b28183eeba83998a52bd6e598aa2abbe877ef3 (diff)
mtd: mtd_readtest: use mtd_test helpers
Use mtdtest_read() and mtdtest_scan_for_bad_eraseblocks() in mtd_test helpers. Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com> Cc: Brian Norris <computersforpeace@gmail.com> Cc: Vikram Narayanan <vikram186@gmail.com> Cc: Adrian Hunter <adrian.hunter@intel.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/tests')
-rw-r--r--drivers/mtd/tests/readtest.c49
1 files changed, 8 insertions, 41 deletions
diff --git a/drivers/mtd/tests/readtest.c b/drivers/mtd/tests/readtest.c
index 2cdd0c47cac1..ffd50d628219 100644
--- a/drivers/mtd/tests/readtest.c
+++ b/drivers/mtd/tests/readtest.c
@@ -29,6 +29,8 @@
29#include <linux/slab.h> 29#include <linux/slab.h>
30#include <linux/sched.h> 30#include <linux/sched.h>
31 31
32#include "mtd_test.h"
33
32static int dev = -EINVAL; 34static int dev = -EINVAL;
33module_param(dev, int, S_IRUGO); 35module_param(dev, int, S_IRUGO);
34MODULE_PARM_DESC(dev, "MTD device number to use"); 36MODULE_PARM_DESC(dev, "MTD device number to use");
@@ -44,7 +46,6 @@ static int pgcnt;
44 46
45static int read_eraseblock_by_page(int ebnum) 47static int read_eraseblock_by_page(int ebnum)
46{ 48{
47 size_t read;
48 int i, ret, err = 0; 49 int i, ret, err = 0;
49 loff_t addr = ebnum * mtd->erasesize; 50 loff_t addr = ebnum * mtd->erasesize;
50 void *buf = iobuf; 51 void *buf = iobuf;
@@ -52,16 +53,12 @@ static int read_eraseblock_by_page(int ebnum)
52 53
53 for (i = 0; i < pgcnt; i++) { 54 for (i = 0; i < pgcnt; i++) {
54 memset(buf, 0 , pgsize); 55 memset(buf, 0 , pgsize);
55 ret = mtd_read(mtd, addr, pgsize, &read, buf); 56 ret = mtdtest_read(mtd, addr, pgsize, buf);
56 if (ret == -EUCLEAN) 57 if (ret) {
57 ret = 0;
58 if (ret || read != pgsize) {
59 pr_err("error: read failed at %#llx\n", 58 pr_err("error: read failed at %#llx\n",
60 (long long)addr); 59 (long long)addr);
61 if (!err) 60 if (!err)
62 err = ret; 61 err = ret;
63 if (!err)
64 err = -EINVAL;
65 } 62 }
66 if (mtd->oobsize) { 63 if (mtd->oobsize) {
67 struct mtd_oob_ops ops; 64 struct mtd_oob_ops ops;
@@ -127,39 +124,6 @@ static void dump_eraseblock(int ebnum)
127 } 124 }
128} 125}
129 126
130static int is_block_bad(int ebnum)
131{
132 loff_t addr = ebnum * mtd->erasesize;
133 int ret;
134
135 ret = mtd_block_isbad(mtd, addr);
136 if (ret)
137 pr_info("block %d is bad\n", ebnum);
138 return ret;
139}
140
141static int scan_for_bad_eraseblocks(void)
142{
143 int i, bad = 0;
144
145 bbt = kzalloc(ebcnt, GFP_KERNEL);
146 if (!bbt)
147 return -ENOMEM;
148
149 if (!mtd_can_have_bb(mtd))
150 return 0;
151
152 pr_info("scanning for bad eraseblocks\n");
153 for (i = 0; i < ebcnt; ++i) {
154 bbt[i] = is_block_bad(i) ? 1 : 0;
155 if (bbt[i])
156 bad += 1;
157 cond_resched();
158 }
159 pr_info("scanned %d eraseblocks, %d are bad\n", i, bad);
160 return 0;
161}
162
163static int __init mtd_readtest_init(void) 127static int __init mtd_readtest_init(void)
164{ 128{
165 uint64_t tmp; 129 uint64_t tmp;
@@ -208,7 +172,10 @@ static int __init mtd_readtest_init(void)
208 if (!iobuf1) 172 if (!iobuf1)
209 goto out; 173 goto out;
210 174
211 err = scan_for_bad_eraseblocks(); 175 bbt = kzalloc(ebcnt, GFP_KERNEL);
176 if (!bbt)
177 goto out;
178 err = mtdtest_scan_for_bad_eraseblocks(mtd, bbt, 0, ebcnt);
212 if (err) 179 if (err)
213 goto out; 180 goto out;
214 181