diff options
author | Akinobu Mita <akinobu.mita@gmail.com> | 2013-02-27 20:05:33 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2013-02-27 22:10:22 -0500 |
commit | 8dad049884e6d09aec5859c5bff5d2c36ea621a7 (patch) | |
tree | 2725f237170131c166cd0fb127d579344049c7ac | |
parent | 459a86d83dce6641f66311d37fbfe1419c477a5a (diff) |
mtd: mtd_oobtest: 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>
-rw-r--r-- | drivers/mtd/tests/mtd_oobtest.c | 49 |
1 files changed, 16 insertions, 33 deletions
diff --git a/drivers/mtd/tests/mtd_oobtest.c b/drivers/mtd/tests/mtd_oobtest.c index e827fa8cd844..3e24b379ffa4 100644 --- a/drivers/mtd/tests/mtd_oobtest.c +++ b/drivers/mtd/tests/mtd_oobtest.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 | ||
33 | static int dev = -EINVAL; | 34 | static int dev = -EINVAL; |
34 | module_param(dev, int, S_IRUGO); | 35 | module_param(dev, int, S_IRUGO); |
@@ -46,26 +47,7 @@ static int use_offset; | |||
46 | static int use_len; | 47 | static int use_len; |
47 | static int use_len_max; | 48 | static int use_len_max; |
48 | static int vary_offset; | 49 | static int vary_offset; |
49 | static unsigned long next = 1; | 50 | static struct rnd_state rnd_state; |
50 | |||
51 | static inline unsigned int simple_rand(void) | ||
52 | { | ||
53 | next = next * 1103515245 + 12345; | ||
54 | return (unsigned int)((next / 65536) % 32768); | ||
55 | } | ||
56 | |||
57 | static inline void simple_srand(unsigned long seed) | ||
58 | { | ||
59 | next = seed; | ||
60 | } | ||
61 | |||
62 | static void set_random_data(unsigned char *buf, size_t len) | ||
63 | { | ||
64 | size_t i; | ||
65 | |||
66 | for (i = 0; i < len; ++i) | ||
67 | buf[i] = simple_rand(); | ||
68 | } | ||
69 | 51 | ||
70 | static int erase_eraseblock(int ebnum) | 52 | static int erase_eraseblock(int ebnum) |
71 | { | 53 | { |
@@ -129,7 +111,7 @@ static int write_eraseblock(int ebnum) | |||
129 | loff_t addr = ebnum * mtd->erasesize; | 111 | loff_t addr = ebnum * mtd->erasesize; |
130 | 112 | ||
131 | for (i = 0; i < pgcnt; ++i, addr += mtd->writesize) { | 113 | for (i = 0; i < pgcnt; ++i, addr += mtd->writesize) { |
132 | set_random_data(writebuf, use_len); | 114 | prandom_bytes_state(&rnd_state, writebuf, use_len); |
133 | ops.mode = MTD_OPS_AUTO_OOB; | 115 | ops.mode = MTD_OPS_AUTO_OOB; |
134 | ops.len = 0; | 116 | ops.len = 0; |
135 | ops.retlen = 0; | 117 | ops.retlen = 0; |
@@ -182,7 +164,7 @@ static int verify_eraseblock(int ebnum) | |||
182 | loff_t addr = ebnum * mtd->erasesize; | 164 | loff_t addr = ebnum * mtd->erasesize; |
183 | 165 | ||
184 | for (i = 0; i < pgcnt; ++i, addr += mtd->writesize) { | 166 | for (i = 0; i < pgcnt; ++i, addr += mtd->writesize) { |
185 | set_random_data(writebuf, use_len); | 167 | prandom_bytes_state(&rnd_state, writebuf, use_len); |
186 | ops.mode = MTD_OPS_AUTO_OOB; | 168 | ops.mode = MTD_OPS_AUTO_OOB; |
187 | ops.len = 0; | 169 | ops.len = 0; |
188 | ops.retlen = 0; | 170 | ops.retlen = 0; |
@@ -273,7 +255,7 @@ static int verify_eraseblock_in_one_go(int ebnum) | |||
273 | loff_t addr = ebnum * mtd->erasesize; | 255 | loff_t addr = ebnum * mtd->erasesize; |
274 | size_t len = mtd->ecclayout->oobavail * pgcnt; | 256 | size_t len = mtd->ecclayout->oobavail * pgcnt; |
275 | 257 | ||
276 | set_random_data(writebuf, len); | 258 | prandom_bytes_state(&rnd_state, writebuf, len); |
277 | ops.mode = MTD_OPS_AUTO_OOB; | 259 | ops.mode = MTD_OPS_AUTO_OOB; |
278 | ops.len = 0; | 260 | ops.len = 0; |
279 | ops.retlen = 0; | 261 | ops.retlen = 0; |
@@ -424,12 +406,12 @@ static int __init mtd_oobtest_init(void) | |||
424 | if (err) | 406 | if (err) |
425 | goto out; | 407 | goto out; |
426 | 408 | ||
427 | simple_srand(1); | 409 | prandom_seed_state(&rnd_state, 1); |
428 | err = write_whole_device(); | 410 | err = write_whole_device(); |
429 | if (err) | 411 | if (err) |
430 | goto out; | 412 | goto out; |
431 | 413 | ||
432 | simple_srand(1); | 414 | prandom_seed_state(&rnd_state, 1); |
433 | err = verify_all_eraseblocks(); | 415 | err = verify_all_eraseblocks(); |
434 | if (err) | 416 | if (err) |
435 | goto out; | 417 | goto out; |
@@ -444,13 +426,13 @@ static int __init mtd_oobtest_init(void) | |||
444 | if (err) | 426 | if (err) |
445 | goto out; | 427 | goto out; |
446 | 428 | ||
447 | simple_srand(3); | 429 | prandom_seed_state(&rnd_state, 3); |
448 | err = write_whole_device(); | 430 | err = write_whole_device(); |
449 | if (err) | 431 | if (err) |
450 | goto out; | 432 | goto out; |
451 | 433 | ||
452 | /* Check all eraseblocks */ | 434 | /* Check all eraseblocks */ |
453 | simple_srand(3); | 435 | prandom_seed_state(&rnd_state, 3); |
454 | pr_info("verifying all eraseblocks\n"); | 436 | pr_info("verifying all eraseblocks\n"); |
455 | for (i = 0; i < ebcnt; ++i) { | 437 | for (i = 0; i < ebcnt; ++i) { |
456 | if (bbt[i]) | 438 | if (bbt[i]) |
@@ -479,7 +461,7 @@ static int __init mtd_oobtest_init(void) | |||
479 | use_len = mtd->ecclayout->oobavail; | 461 | use_len = mtd->ecclayout->oobavail; |
480 | use_len_max = mtd->ecclayout->oobavail; | 462 | use_len_max = mtd->ecclayout->oobavail; |
481 | vary_offset = 1; | 463 | vary_offset = 1; |
482 | simple_srand(5); | 464 | prandom_seed_state(&rnd_state, 5); |
483 | 465 | ||
484 | err = write_whole_device(); | 466 | err = write_whole_device(); |
485 | if (err) | 467 | if (err) |
@@ -490,7 +472,7 @@ static int __init mtd_oobtest_init(void) | |||
490 | use_len = mtd->ecclayout->oobavail; | 472 | use_len = mtd->ecclayout->oobavail; |
491 | use_len_max = mtd->ecclayout->oobavail; | 473 | use_len_max = mtd->ecclayout->oobavail; |
492 | vary_offset = 1; | 474 | vary_offset = 1; |
493 | simple_srand(5); | 475 | prandom_seed_state(&rnd_state, 5); |
494 | err = verify_all_eraseblocks(); | 476 | err = verify_all_eraseblocks(); |
495 | if (err) | 477 | if (err) |
496 | goto out; | 478 | goto out; |
@@ -649,7 +631,7 @@ static int __init mtd_oobtest_init(void) | |||
649 | goto out; | 631 | goto out; |
650 | 632 | ||
651 | /* Write all eraseblocks */ | 633 | /* Write all eraseblocks */ |
652 | simple_srand(11); | 634 | prandom_seed_state(&rnd_state, 11); |
653 | pr_info("writing OOBs of whole device\n"); | 635 | pr_info("writing OOBs of whole device\n"); |
654 | for (i = 0; i < ebcnt - 1; ++i) { | 636 | for (i = 0; i < ebcnt - 1; ++i) { |
655 | int cnt = 2; | 637 | int cnt = 2; |
@@ -659,7 +641,7 @@ static int __init mtd_oobtest_init(void) | |||
659 | continue; | 641 | continue; |
660 | addr = (i + 1) * mtd->erasesize - mtd->writesize; | 642 | addr = (i + 1) * mtd->erasesize - mtd->writesize; |
661 | for (pg = 0; pg < cnt; ++pg) { | 643 | for (pg = 0; pg < cnt; ++pg) { |
662 | set_random_data(writebuf, sz); | 644 | prandom_bytes_state(&rnd_state, writebuf, sz); |
663 | ops.mode = MTD_OPS_AUTO_OOB; | 645 | ops.mode = MTD_OPS_AUTO_OOB; |
664 | ops.len = 0; | 646 | ops.len = 0; |
665 | ops.retlen = 0; | 647 | ops.retlen = 0; |
@@ -680,12 +662,13 @@ static int __init mtd_oobtest_init(void) | |||
680 | pr_info("written %u eraseblocks\n", i); | 662 | pr_info("written %u eraseblocks\n", i); |
681 | 663 | ||
682 | /* Check all eraseblocks */ | 664 | /* Check all eraseblocks */ |
683 | simple_srand(11); | 665 | prandom_seed_state(&rnd_state, 11); |
684 | pr_info("verifying all eraseblocks\n"); | 666 | pr_info("verifying all eraseblocks\n"); |
685 | for (i = 0; i < ebcnt - 1; ++i) { | 667 | for (i = 0; i < ebcnt - 1; ++i) { |
686 | if (bbt[i] || bbt[i + 1]) | 668 | if (bbt[i] || bbt[i + 1]) |
687 | continue; | 669 | continue; |
688 | set_random_data(writebuf, mtd->ecclayout->oobavail * 2); | 670 | prandom_bytes_state(&rnd_state, writebuf, |
671 | mtd->ecclayout->oobavail * 2); | ||
689 | addr = (i + 1) * mtd->erasesize - mtd->writesize; | 672 | addr = (i + 1) * mtd->erasesize - mtd->writesize; |
690 | ops.mode = MTD_OPS_AUTO_OOB; | 673 | ops.mode = MTD_OPS_AUTO_OOB; |
691 | ops.len = 0; | 674 | ops.len = 0; |