aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorAkinobu Mita <akinobu.mita@gmail.com>2013-02-27 20:05:39 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2013-02-27 22:10:23 -0500
commita312b78b0ad6abb38f606ef5dd31e2a1b4469989 (patch)
tree570eb9be969aafeb7f46a8b253cccddde9b985cb /drivers
parent99672f32aa4ba0f0cc3e8a15f3c0614e63c2851b (diff)
mtd: mtd_subpagetest: 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')
-rw-r--r--drivers/mtd/tests/mtd_subpagetest.c42
1 files changed, 12 insertions, 30 deletions
diff --git a/drivers/mtd/tests/mtd_subpagetest.c b/drivers/mtd/tests/mtd_subpagetest.c
index c880c2229c59..aade56f27945 100644
--- a/drivers/mtd/tests/mtd_subpagetest.c
+++ b/drivers/mtd/tests/mtd_subpagetest.c
@@ -28,6 +28,7 @@
28#include <linux/mtd/mtd.h> 28#include <linux/mtd/mtd.h>
29#include <linux/slab.h> 29#include <linux/slab.h>
30#include <linux/sched.h> 30#include <linux/sched.h>
31#include <linux/random.h>
31 32
32static int dev = -EINVAL; 33static int dev = -EINVAL;
33module_param(dev, int, S_IRUGO); 34module_param(dev, int, S_IRUGO);
@@ -43,26 +44,7 @@ static int bufsize;
43static int ebcnt; 44static int ebcnt;
44static int pgcnt; 45static int pgcnt;
45static int errcnt; 46static int errcnt;
46static unsigned long next = 1; 47static struct rnd_state rnd_state;
47
48static inline unsigned int simple_rand(void)
49{
50 next = next * 1103515245 + 12345;
51 return (unsigned int)((next / 65536) % 32768);
52}
53
54static inline void simple_srand(unsigned long seed)
55{
56 next = seed;
57}
58
59static void set_random_data(unsigned char *buf, size_t len)
60{
61 size_t i;
62
63 for (i = 0; i < len; ++i)
64 buf[i] = simple_rand();
65}
66 48
67static inline void clear_data(unsigned char *buf, size_t len) 49static inline void clear_data(unsigned char *buf, size_t len)
68{ 50{
@@ -119,7 +101,7 @@ static int write_eraseblock(int ebnum)
119 int err = 0; 101 int err = 0;
120 loff_t addr = ebnum * mtd->erasesize; 102 loff_t addr = ebnum * mtd->erasesize;
121 103
122 set_random_data(writebuf, subpgsize); 104 prandom_bytes_state(&rnd_state, writebuf, subpgsize);
123 err = mtd_write(mtd, addr, subpgsize, &written, writebuf); 105 err = mtd_write(mtd, addr, subpgsize, &written, writebuf);
124 if (unlikely(err || written != subpgsize)) { 106 if (unlikely(err || written != subpgsize)) {
125 pr_err("error: write failed at %#llx\n", 107 pr_err("error: write failed at %#llx\n",
@@ -133,7 +115,7 @@ static int write_eraseblock(int ebnum)
133 115
134 addr += subpgsize; 116 addr += subpgsize;
135 117
136 set_random_data(writebuf, subpgsize); 118 prandom_bytes_state(&rnd_state, writebuf, subpgsize);
137 err = mtd_write(mtd, addr, subpgsize, &written, writebuf); 119 err = mtd_write(mtd, addr, subpgsize, &written, writebuf);
138 if (unlikely(err || written != subpgsize)) { 120 if (unlikely(err || written != subpgsize)) {
139 pr_err("error: write failed at %#llx\n", 121 pr_err("error: write failed at %#llx\n",
@@ -157,7 +139,7 @@ static int write_eraseblock2(int ebnum)
157 for (k = 1; k < 33; ++k) { 139 for (k = 1; k < 33; ++k) {
158 if (addr + (subpgsize * k) > (ebnum + 1) * mtd->erasesize) 140 if (addr + (subpgsize * k) > (ebnum + 1) * mtd->erasesize)
159 break; 141 break;
160 set_random_data(writebuf, subpgsize * k); 142 prandom_bytes_state(&rnd_state, writebuf, subpgsize * k);
161 err = mtd_write(mtd, addr, subpgsize * k, &written, writebuf); 143 err = mtd_write(mtd, addr, subpgsize * k, &written, writebuf);
162 if (unlikely(err || written != subpgsize * k)) { 144 if (unlikely(err || written != subpgsize * k)) {
163 pr_err("error: write failed at %#llx\n", 145 pr_err("error: write failed at %#llx\n",
@@ -193,7 +175,7 @@ static int verify_eraseblock(int ebnum)
193 int err = 0; 175 int err = 0;
194 loff_t addr = ebnum * mtd->erasesize; 176 loff_t addr = ebnum * mtd->erasesize;
195 177
196 set_random_data(writebuf, subpgsize); 178 prandom_bytes_state(&rnd_state, writebuf, subpgsize);
197 clear_data(readbuf, subpgsize); 179 clear_data(readbuf, subpgsize);
198 err = mtd_read(mtd, addr, subpgsize, &read, readbuf); 180 err = mtd_read(mtd, addr, subpgsize, &read, readbuf);
199 if (unlikely(err || read != subpgsize)) { 181 if (unlikely(err || read != subpgsize)) {
@@ -220,7 +202,7 @@ static int verify_eraseblock(int ebnum)
220 202
221 addr += subpgsize; 203 addr += subpgsize;
222 204
223 set_random_data(writebuf, subpgsize); 205 prandom_bytes_state(&rnd_state, writebuf, subpgsize);
224 clear_data(readbuf, subpgsize); 206 clear_data(readbuf, subpgsize);
225 err = mtd_read(mtd, addr, subpgsize, &read, readbuf); 207 err = mtd_read(mtd, addr, subpgsize, &read, readbuf);
226 if (unlikely(err || read != subpgsize)) { 208 if (unlikely(err || read != subpgsize)) {
@@ -257,7 +239,7 @@ static int verify_eraseblock2(int ebnum)
257 for (k = 1; k < 33; ++k) { 239 for (k = 1; k < 33; ++k) {
258 if (addr + (subpgsize * k) > (ebnum + 1) * mtd->erasesize) 240 if (addr + (subpgsize * k) > (ebnum + 1) * mtd->erasesize)
259 break; 241 break;
260 set_random_data(writebuf, subpgsize * k); 242 prandom_bytes_state(&rnd_state, writebuf, subpgsize * k);
261 clear_data(readbuf, subpgsize * k); 243 clear_data(readbuf, subpgsize * k);
262 err = mtd_read(mtd, addr, subpgsize * k, &read, readbuf); 244 err = mtd_read(mtd, addr, subpgsize * k, &read, readbuf);
263 if (unlikely(err || read != subpgsize * k)) { 245 if (unlikely(err || read != subpgsize * k)) {
@@ -430,7 +412,7 @@ static int __init mtd_subpagetest_init(void)
430 goto out; 412 goto out;
431 413
432 pr_info("writing whole device\n"); 414 pr_info("writing whole device\n");
433 simple_srand(1); 415 prandom_seed_state(&rnd_state, 1);
434 for (i = 0; i < ebcnt; ++i) { 416 for (i = 0; i < ebcnt; ++i) {
435 if (bbt[i]) 417 if (bbt[i])
436 continue; 418 continue;
@@ -443,7 +425,7 @@ static int __init mtd_subpagetest_init(void)
443 } 425 }
444 pr_info("written %u eraseblocks\n", i); 426 pr_info("written %u eraseblocks\n", i);
445 427
446 simple_srand(1); 428 prandom_seed_state(&rnd_state, 1);
447 pr_info("verifying all eraseblocks\n"); 429 pr_info("verifying all eraseblocks\n");
448 for (i = 0; i < ebcnt; ++i) { 430 for (i = 0; i < ebcnt; ++i) {
449 if (bbt[i]) 431 if (bbt[i])
@@ -466,7 +448,7 @@ static int __init mtd_subpagetest_init(void)
466 goto out; 448 goto out;
467 449
468 /* Write all eraseblocks */ 450 /* Write all eraseblocks */
469 simple_srand(3); 451 prandom_seed_state(&rnd_state, 3);
470 pr_info("writing whole device\n"); 452 pr_info("writing whole device\n");
471 for (i = 0; i < ebcnt; ++i) { 453 for (i = 0; i < ebcnt; ++i) {
472 if (bbt[i]) 454 if (bbt[i])
@@ -481,7 +463,7 @@ static int __init mtd_subpagetest_init(void)
481 pr_info("written %u eraseblocks\n", i); 463 pr_info("written %u eraseblocks\n", i);
482 464
483 /* Check all eraseblocks */ 465 /* Check all eraseblocks */
484 simple_srand(3); 466 prandom_seed_state(&rnd_state, 3);
485 pr_info("verifying all eraseblocks\n"); 467 pr_info("verifying all eraseblocks\n");
486 for (i = 0; i < ebcnt; ++i) { 468 for (i = 0; i < ebcnt; ++i) {
487 if (bbt[i]) 469 if (bbt[i])