aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd/tests
diff options
context:
space:
mode:
authorAkinobu Mita <akinobu.mita@gmail.com>2013-08-03 05:52:14 -0400
committerDavid Woodhouse <David.Woodhouse@intel.com>2013-08-30 16:34:23 -0400
commit725cd71c0245d1ac7e4441799e2d32fe4b68be8f (patch)
treee4e62f37d832730d14f3b824cc75f6ba5d0b9c16 /drivers/mtd/tests
parent5a78df69eeb34b560a92f64170625083018383de (diff)
mtd: mtd_subpagetest: use mtd_test helpers
Use mtdtest_scan_for_bad_eraseblocks() and mtdtest_erase_good_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/subpagetest.c87
1 files changed, 9 insertions, 78 deletions
diff --git a/drivers/mtd/tests/subpagetest.c b/drivers/mtd/tests/subpagetest.c
index e41a04f5caab..e2c0adf24cfc 100644
--- a/drivers/mtd/tests/subpagetest.c
+++ b/drivers/mtd/tests/subpagetest.c
@@ -30,6 +30,8 @@
30#include <linux/sched.h> 30#include <linux/sched.h>
31#include <linux/random.h> 31#include <linux/random.h>
32 32
33#include "mtd_test.h"
34
33static int dev = -EINVAL; 35static int dev = -EINVAL;
34module_param(dev, int, S_IRUGO); 36module_param(dev, int, S_IRUGO);
35MODULE_PARM_DESC(dev, "MTD device number to use"); 37MODULE_PARM_DESC(dev, "MTD device number to use");
@@ -51,50 +53,6 @@ static inline void clear_data(unsigned char *buf, size_t len)
51 memset(buf, 0, len); 53 memset(buf, 0, len);
52} 54}
53 55
54static int erase_eraseblock(int ebnum)
55{
56 int err;
57 struct erase_info ei;
58 loff_t addr = ebnum * mtd->erasesize;
59
60 memset(&ei, 0, sizeof(struct erase_info));
61 ei.mtd = mtd;
62 ei.addr = addr;
63 ei.len = mtd->erasesize;
64
65 err = mtd_erase(mtd, &ei);
66 if (err) {
67 pr_err("error %d while erasing EB %d\n", err, ebnum);
68 return err;
69 }
70
71 if (ei.state == MTD_ERASE_FAILED) {
72 pr_err("some erase error occurred at EB %d\n",
73 ebnum);
74 return -EIO;
75 }
76
77 return 0;
78}
79
80static int erase_whole_device(void)
81{
82 int err;
83 unsigned int i;
84
85 pr_info("erasing whole device\n");
86 for (i = 0; i < ebcnt; ++i) {
87 if (bbt[i])
88 continue;
89 err = erase_eraseblock(i);
90 if (err)
91 return err;
92 cond_resched();
93 }
94 pr_info("erased %u eraseblocks\n", i);
95 return 0;
96}
97
98static int write_eraseblock(int ebnum) 56static int write_eraseblock(int ebnum)
99{ 57{
100 size_t written; 58 size_t written;
@@ -317,36 +275,6 @@ static int verify_all_eraseblocks_ff(void)
317 return 0; 275 return 0;
318} 276}
319 277
320static int is_block_bad(int ebnum)
321{
322 loff_t addr = ebnum * mtd->erasesize;
323 int ret;
324
325 ret = mtd_block_isbad(mtd, addr);
326 if (ret)
327 pr_info("block %d is bad\n", ebnum);
328 return ret;
329}
330
331static int scan_for_bad_eraseblocks(void)
332{
333 int i, bad = 0;
334
335 bbt = kzalloc(ebcnt, GFP_KERNEL);
336 if (!bbt)
337 return -ENOMEM;
338
339 pr_info("scanning for bad eraseblocks\n");
340 for (i = 0; i < ebcnt; ++i) {
341 bbt[i] = is_block_bad(i) ? 1 : 0;
342 if (bbt[i])
343 bad += 1;
344 cond_resched();
345 }
346 pr_info("scanned %d eraseblocks, %d are bad\n", i, bad);
347 return 0;
348}
349
350static int __init mtd_subpagetest_init(void) 278static int __init mtd_subpagetest_init(void)
351{ 279{
352 int err = 0; 280 int err = 0;
@@ -396,12 +324,15 @@ static int __init mtd_subpagetest_init(void)
396 readbuf = kmalloc(bufsize, GFP_KERNEL); 324 readbuf = kmalloc(bufsize, GFP_KERNEL);
397 if (!readbuf) 325 if (!readbuf)
398 goto out; 326 goto out;
327 bbt = kzalloc(ebcnt, GFP_KERNEL);
328 if (!bbt)
329 goto out;
399 330
400 err = scan_for_bad_eraseblocks(); 331 err = mtdtest_scan_for_bad_eraseblocks(mtd, bbt, 0, ebcnt);
401 if (err) 332 if (err)
402 goto out; 333 goto out;
403 334
404 err = erase_whole_device(); 335 err = mtdtest_erase_good_eraseblocks(mtd, bbt, 0, ebcnt);
405 if (err) 336 if (err)
406 goto out; 337 goto out;
407 338
@@ -433,7 +364,7 @@ static int __init mtd_subpagetest_init(void)
433 } 364 }
434 pr_info("verified %u eraseblocks\n", i); 365 pr_info("verified %u eraseblocks\n", i);
435 366
436 err = erase_whole_device(); 367 err = mtdtest_erase_good_eraseblocks(mtd, bbt, 0, ebcnt);
437 if (err) 368 if (err)
438 goto out; 369 goto out;
439 370
@@ -471,7 +402,7 @@ static int __init mtd_subpagetest_init(void)
471 } 402 }
472 pr_info("verified %u eraseblocks\n", i); 403 pr_info("verified %u eraseblocks\n", i);
473 404
474 err = erase_whole_device(); 405 err = mtdtest_erase_good_eraseblocks(mtd, bbt, 0, ebcnt);
475 if (err) 406 if (err)
476 goto out; 407 goto out;
477 408