aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd
diff options
context:
space:
mode:
authorAkinobu Mita <akinobu.mita@gmail.com>2013-02-27 20:05:35 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2013-02-27 22:10:22 -0500
commit825b8ccb7450c805da7055a33fde032f2f0ed3ae (patch)
tree6e631d031537639303391271da24451172f087de /drivers/mtd
parent8dad049884e6d09aec5859c5bff5d2c36ea621a7 (diff)
mtd: mtd_pagetest: convert to use prandom library
This removes home-brewed pseudo-random number generator and use prandom library. Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com> Cc: Artem Bityutskiy <dedekind1@gmail.com> Cc: David Woodhouse <dwmw2@infradead.org> Cc: "Theodore Ts'o" <tytso@mit.edu> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: David Laight <david.laight@aculab.com> Cc: Eilon Greenstein <eilong@broadcom.com> Cc: Michel Lespinasse <walken@google.com> Cc: Robert Love <robert.w.love@intel.com> Cc: Valdis Kletnieks <valdis.kletnieks@vt.edu> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/mtd')
-rw-r--r--drivers/mtd/tests/mtd_pagetest.c43
1 files changed, 13 insertions, 30 deletions
diff --git a/drivers/mtd/tests/mtd_pagetest.c b/drivers/mtd/tests/mtd_pagetest.c
index f93a76f88113..0c1140b6c286 100644
--- a/drivers/mtd/tests/mtd_pagetest.c
+++ b/drivers/mtd/tests/mtd_pagetest.c
@@ -29,6 +29,7 @@
29#include <linux/mtd/mtd.h> 29#include <linux/mtd/mtd.h>
30#include <linux/slab.h> 30#include <linux/slab.h>
31#include <linux/sched.h> 31#include <linux/sched.h>
32#include <linux/random.h>
32 33
33static int dev = -EINVAL; 34static int dev = -EINVAL;
34module_param(dev, int, S_IRUGO); 35module_param(dev, int, S_IRUGO);
@@ -45,26 +46,7 @@ static int bufsize;
45static int ebcnt; 46static int ebcnt;
46static int pgcnt; 47static int pgcnt;
47static int errcnt; 48static int errcnt;
48static unsigned long next = 1; 49static struct rnd_state rnd_state;
49
50static inline unsigned int simple_rand(void)
51{
52 next = next * 1103515245 + 12345;
53 return (unsigned int)((next / 65536) % 32768);
54}
55
56static inline void simple_srand(unsigned long seed)
57{
58 next = seed;
59}
60
61static void set_random_data(unsigned char *buf, size_t len)
62{
63 size_t i;
64
65 for (i = 0; i < len; ++i)
66 buf[i] = simple_rand();
67}
68 50
69static int erase_eraseblock(int ebnum) 51static int erase_eraseblock(int ebnum)
70{ 52{
@@ -98,7 +80,7 @@ static int write_eraseblock(int ebnum)
98 size_t written; 80 size_t written;
99 loff_t addr = ebnum * mtd->erasesize; 81 loff_t addr = ebnum * mtd->erasesize;
100 82
101 set_random_data(writebuf, mtd->erasesize); 83 prandom_bytes_state(&rnd_state, writebuf, mtd->erasesize);
102 cond_resched(); 84 cond_resched();
103 err = mtd_write(mtd, addr, mtd->erasesize, &written, writebuf); 85 err = mtd_write(mtd, addr, mtd->erasesize, &written, writebuf);
104 if (err || written != mtd->erasesize) 86 if (err || written != mtd->erasesize)
@@ -124,7 +106,7 @@ static int verify_eraseblock(int ebnum)
124 for (i = 0; i < ebcnt && bbt[ebcnt - i - 1]; ++i) 106 for (i = 0; i < ebcnt && bbt[ebcnt - i - 1]; ++i)
125 addrn -= mtd->erasesize; 107 addrn -= mtd->erasesize;
126 108
127 set_random_data(writebuf, mtd->erasesize); 109 prandom_bytes_state(&rnd_state, writebuf, mtd->erasesize);
128 for (j = 0; j < pgcnt - 1; ++j, addr += pgsize) { 110 for (j = 0; j < pgcnt - 1; ++j, addr += pgsize) {
129 /* Do a read to set the internal dataRAMs to different data */ 111 /* Do a read to set the internal dataRAMs to different data */
130 err = mtd_read(mtd, addr0, bufsize, &read, twopages); 112 err = mtd_read(mtd, addr0, bufsize, &read, twopages);
@@ -160,7 +142,8 @@ static int verify_eraseblock(int ebnum)
160 } 142 }
161 /* Check boundary between eraseblocks */ 143 /* Check boundary between eraseblocks */
162 if (addr <= addrn - pgsize - pgsize && !bbt[ebnum + 1]) { 144 if (addr <= addrn - pgsize - pgsize && !bbt[ebnum + 1]) {
163 unsigned long oldnext = next; 145 struct rnd_state old_state = rnd_state;
146
164 /* Do a read to set the internal dataRAMs to different data */ 147 /* Do a read to set the internal dataRAMs to different data */
165 err = mtd_read(mtd, addr0, bufsize, &read, twopages); 148 err = mtd_read(mtd, addr0, bufsize, &read, twopages);
166 if (mtd_is_bitflip(err)) 149 if (mtd_is_bitflip(err))
@@ -188,13 +171,13 @@ static int verify_eraseblock(int ebnum)
188 return err; 171 return err;
189 } 172 }
190 memcpy(boundary, writebuf + mtd->erasesize - pgsize, pgsize); 173 memcpy(boundary, writebuf + mtd->erasesize - pgsize, pgsize);
191 set_random_data(boundary + pgsize, pgsize); 174 prandom_bytes_state(&rnd_state, boundary + pgsize, pgsize);
192 if (memcmp(twopages, boundary, bufsize)) { 175 if (memcmp(twopages, boundary, bufsize)) {
193 pr_err("error: verify failed at %#llx\n", 176 pr_err("error: verify failed at %#llx\n",
194 (long long)addr); 177 (long long)addr);
195 errcnt += 1; 178 errcnt += 1;
196 } 179 }
197 next = oldnext; 180 rnd_state = old_state;
198 } 181 }
199 return err; 182 return err;
200} 183}
@@ -326,7 +309,7 @@ static int erasecrosstest(void)
326 return err; 309 return err;
327 310
328 pr_info("writing 1st page of block %d\n", ebnum); 311 pr_info("writing 1st page of block %d\n", ebnum);
329 set_random_data(writebuf, pgsize); 312 prandom_bytes_state(&rnd_state, writebuf, pgsize);
330 strcpy(writebuf, "There is no data like this!"); 313 strcpy(writebuf, "There is no data like this!");
331 err = mtd_write(mtd, addr0, pgsize, &written, writebuf); 314 err = mtd_write(mtd, addr0, pgsize, &written, writebuf);
332 if (err || written != pgsize) { 315 if (err || written != pgsize) {
@@ -359,7 +342,7 @@ static int erasecrosstest(void)
359 return err; 342 return err;
360 343
361 pr_info("writing 1st page of block %d\n", ebnum); 344 pr_info("writing 1st page of block %d\n", ebnum);
362 set_random_data(writebuf, pgsize); 345 prandom_bytes_state(&rnd_state, writebuf, pgsize);
363 strcpy(writebuf, "There is no data like this!"); 346 strcpy(writebuf, "There is no data like this!");
364 err = mtd_write(mtd, addr0, pgsize, &written, writebuf); 347 err = mtd_write(mtd, addr0, pgsize, &written, writebuf);
365 if (err || written != pgsize) { 348 if (err || written != pgsize) {
@@ -417,7 +400,7 @@ static int erasetest(void)
417 return err; 400 return err;
418 401
419 pr_info("writing 1st page of block %d\n", ebnum); 402 pr_info("writing 1st page of block %d\n", ebnum);
420 set_random_data(writebuf, pgsize); 403 prandom_bytes_state(&rnd_state, writebuf, pgsize);
421 err = mtd_write(mtd, addr0, pgsize, &written, writebuf); 404 err = mtd_write(mtd, addr0, pgsize, &written, writebuf);
422 if (err || written != pgsize) { 405 if (err || written != pgsize) {
423 pr_err("error: write failed at %#llx\n", 406 pr_err("error: write failed at %#llx\n",
@@ -565,7 +548,7 @@ static int __init mtd_pagetest_init(void)
565 pr_info("erased %u eraseblocks\n", i); 548 pr_info("erased %u eraseblocks\n", i);
566 549
567 /* Write all eraseblocks */ 550 /* Write all eraseblocks */
568 simple_srand(1); 551 prandom_seed_state(&rnd_state, 1);
569 pr_info("writing whole device\n"); 552 pr_info("writing whole device\n");
570 for (i = 0; i < ebcnt; ++i) { 553 for (i = 0; i < ebcnt; ++i) {
571 if (bbt[i]) 554 if (bbt[i])
@@ -580,7 +563,7 @@ static int __init mtd_pagetest_init(void)
580 pr_info("written %u eraseblocks\n", i); 563 pr_info("written %u eraseblocks\n", i);
581 564
582 /* Check all eraseblocks */ 565 /* Check all eraseblocks */
583 simple_srand(1); 566 prandom_seed_state(&rnd_state, 1);
584 pr_info("verifying all eraseblocks\n"); 567 pr_info("verifying all eraseblocks\n");
585 for (i = 0; i < ebcnt; ++i) { 568 for (i = 0; i < ebcnt; ++i) {
586 if (bbt[i]) 569 if (bbt[i])