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

mtd: mtd_torturetest: 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
6cf78358 725cd71c

+7 -59
+7 -59
drivers/mtd/tests/torturetest.c
··· 32 32 #include <linux/mtd/mtd.h> 33 33 #include <linux/slab.h> 34 34 #include <linux/sched.h> 35 + #include "mtd_test.h" 35 36 36 37 #define RETRIES 3 37 38 ··· 91 90 static inline void stop_timing(void) 92 91 { 93 92 do_gettimeofday(&finish); 94 - } 95 - 96 - /* 97 - * Erase eraseblock number @ebnum. 98 - */ 99 - static inline int erase_eraseblock(int ebnum) 100 - { 101 - int err; 102 - struct erase_info ei; 103 - loff_t addr = ebnum * mtd->erasesize; 104 - 105 - memset(&ei, 0, sizeof(struct erase_info)); 106 - ei.mtd = mtd; 107 - ei.addr = addr; 108 - ei.len = mtd->erasesize; 109 - 110 - err = mtd_erase(mtd, &ei); 111 - if (err) { 112 - pr_err("error %d while erasing EB %d\n", err, ebnum); 113 - return err; 114 - } 115 - 116 - if (ei.state == MTD_ERASE_FAILED) { 117 - pr_err("some erase error occurred at EB %d\n", 118 - ebnum); 119 - return -EIO; 120 - } 121 - 122 - return 0; 123 93 } 124 94 125 95 /* ··· 180 208 static int __init tort_init(void) 181 209 { 182 210 int err = 0, i, infinite = !cycles_count; 183 - int *bad_ebs; 211 + unsigned char *bad_ebs; 184 212 185 213 printk(KERN_INFO "\n"); 186 214 printk(KERN_INFO "=================================================\n"); ··· 237 265 if (!check_buf) 238 266 goto out_patt_FF; 239 267 240 - bad_ebs = kcalloc(ebcnt, sizeof(*bad_ebs), GFP_KERNEL); 268 + bad_ebs = kzalloc(ebcnt, GFP_KERNEL); 241 269 if (!bad_ebs) 242 270 goto out_check_buf; 243 271 ··· 255 283 } 256 284 } 257 285 258 - /* 259 - * Check if there is a bad eraseblock among those we are going to test. 260 - */ 261 - if (mtd_can_have_bb(mtd)) { 262 - for (i = eb; i < eb + ebcnt; i++) { 263 - err = mtd_block_isbad(mtd, (loff_t)i * mtd->erasesize); 264 - 265 - if (err < 0) { 266 - pr_info("block_isbad() returned %d " 267 - "for EB %d\n", err, i); 268 - goto out; 269 - } 270 - 271 - if (err) { 272 - pr_err("EB %d is bad. Skip it.\n", i); 273 - bad_ebs[i - eb] = 1; 274 - } 275 - } 276 - } 286 + err = mtdtest_scan_for_bad_eraseblocks(mtd, bad_ebs, eb, ebcnt); 287 + if (err) 288 + goto out; 277 289 278 290 start_timing(); 279 291 while (1) { 280 292 int i; 281 293 void *patt; 282 294 283 - /* Erase all eraseblocks */ 284 - for (i = eb; i < eb + ebcnt; i++) { 285 - if (bad_ebs[i - eb]) 286 - continue; 287 - err = erase_eraseblock(i); 288 - if (err) 289 - goto out; 290 - cond_resched(); 291 - } 295 + mtdtest_erase_good_eraseblocks(mtd, bad_ebs, eb, ebcnt); 292 296 293 297 /* Check if the eraseblocks contain only 0xFF bytes */ 294 298 if (check) {