Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Akinobu Mita and committed by
David Woodhouse
725cd71c 5a78df69

+9 -78
+9 -78
drivers/mtd/tests/subpagetest.c
··· 30 30 #include <linux/sched.h> 31 31 #include <linux/random.h> 32 32 33 + #include "mtd_test.h" 34 + 33 35 static int dev = -EINVAL; 34 36 module_param(dev, int, S_IRUGO); 35 37 MODULE_PARM_DESC(dev, "MTD device number to use"); ··· 51 49 static inline void clear_data(unsigned char *buf, size_t len) 52 50 { 53 51 memset(buf, 0, len); 54 - } 55 - 56 - static int erase_eraseblock(int ebnum) 57 - { 58 - int err; 59 - struct erase_info ei; 60 - loff_t addr = ebnum * mtd->erasesize; 61 - 62 - memset(&ei, 0, sizeof(struct erase_info)); 63 - ei.mtd = mtd; 64 - ei.addr = addr; 65 - ei.len = mtd->erasesize; 66 - 67 - err = mtd_erase(mtd, &ei); 68 - if (err) { 69 - pr_err("error %d while erasing EB %d\n", err, ebnum); 70 - return err; 71 - } 72 - 73 - if (ei.state == MTD_ERASE_FAILED) { 74 - pr_err("some erase error occurred at EB %d\n", 75 - ebnum); 76 - return -EIO; 77 - } 78 - 79 - return 0; 80 - } 81 - 82 - static int erase_whole_device(void) 83 - { 84 - int err; 85 - unsigned int i; 86 - 87 - pr_info("erasing whole device\n"); 88 - for (i = 0; i < ebcnt; ++i) { 89 - if (bbt[i]) 90 - continue; 91 - err = erase_eraseblock(i); 92 - if (err) 93 - return err; 94 - cond_resched(); 95 - } 96 - pr_info("erased %u eraseblocks\n", i); 97 - return 0; 98 52 } 99 53 100 54 static int write_eraseblock(int ebnum) ··· 275 317 return 0; 276 318 } 277 319 278 - static int is_block_bad(int ebnum) 279 - { 280 - loff_t addr = ebnum * mtd->erasesize; 281 - int ret; 282 - 283 - ret = mtd_block_isbad(mtd, addr); 284 - if (ret) 285 - pr_info("block %d is bad\n", ebnum); 286 - return ret; 287 - } 288 - 289 - static int scan_for_bad_eraseblocks(void) 290 - { 291 - int i, bad = 0; 292 - 293 - bbt = kzalloc(ebcnt, GFP_KERNEL); 294 - if (!bbt) 295 - return -ENOMEM; 296 - 297 - pr_info("scanning for bad eraseblocks\n"); 298 - for (i = 0; i < ebcnt; ++i) { 299 - bbt[i] = is_block_bad(i) ? 1 : 0; 300 - if (bbt[i]) 301 - bad += 1; 302 - cond_resched(); 303 - } 304 - pr_info("scanned %d eraseblocks, %d are bad\n", i, bad); 305 - return 0; 306 - } 307 - 308 320 static int __init mtd_subpagetest_init(void) 309 321 { 310 322 int err = 0; ··· 324 396 readbuf = kmalloc(bufsize, GFP_KERNEL); 325 397 if (!readbuf) 326 398 goto out; 399 + bbt = kzalloc(ebcnt, GFP_KERNEL); 400 + if (!bbt) 401 + goto out; 327 402 328 - err = scan_for_bad_eraseblocks(); 403 + err = mtdtest_scan_for_bad_eraseblocks(mtd, bbt, 0, ebcnt); 329 404 if (err) 330 405 goto out; 331 406 332 - err = erase_whole_device(); 407 + err = mtdtest_erase_good_eraseblocks(mtd, bbt, 0, ebcnt); 333 408 if (err) 334 409 goto out; 335 410 ··· 364 433 } 365 434 pr_info("verified %u eraseblocks\n", i); 366 435 367 - err = erase_whole_device(); 436 + err = mtdtest_erase_good_eraseblocks(mtd, bbt, 0, ebcnt); 368 437 if (err) 369 438 goto out; 370 439 ··· 402 471 } 403 472 pr_info("verified %u eraseblocks\n", i); 404 473 405 - err = erase_whole_device(); 474 + err = mtdtest_erase_good_eraseblocks(mtd, bbt, 0, ebcnt); 406 475 if (err) 407 476 goto out; 408 477