Commit 8dad0498 authored by Akinobu Mita's avatar Akinobu Mita Committed by Linus Torvalds

mtd: mtd_oobtest: convert to use prandom library

This removes home-brewed pseudo-random number generator and use
prandom library.
Signed-off-by: default avatarAkinobu 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: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 459a86d8
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include <linux/mtd/mtd.h> #include <linux/mtd/mtd.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/sched.h> #include <linux/sched.h>
#include <linux/random.h>
static int dev = -EINVAL; static int dev = -EINVAL;
module_param(dev, int, S_IRUGO); module_param(dev, int, S_IRUGO);
...@@ -46,26 +47,7 @@ static int use_offset; ...@@ -46,26 +47,7 @@ static int use_offset;
static int use_len; static int use_len;
static int use_len_max; static int use_len_max;
static int vary_offset; static int vary_offset;
static unsigned long next = 1; static struct rnd_state rnd_state;
static inline unsigned int simple_rand(void)
{
next = next * 1103515245 + 12345;
return (unsigned int)((next / 65536) % 32768);
}
static inline void simple_srand(unsigned long seed)
{
next = seed;
}
static void set_random_data(unsigned char *buf, size_t len)
{
size_t i;
for (i = 0; i < len; ++i)
buf[i] = simple_rand();
}
static int erase_eraseblock(int ebnum) static int erase_eraseblock(int ebnum)
{ {
...@@ -129,7 +111,7 @@ static int write_eraseblock(int ebnum) ...@@ -129,7 +111,7 @@ static int write_eraseblock(int ebnum)
loff_t addr = ebnum * mtd->erasesize; loff_t addr = ebnum * mtd->erasesize;
for (i = 0; i < pgcnt; ++i, addr += mtd->writesize) { for (i = 0; i < pgcnt; ++i, addr += mtd->writesize) {
set_random_data(writebuf, use_len); prandom_bytes_state(&rnd_state, writebuf, use_len);
ops.mode = MTD_OPS_AUTO_OOB; ops.mode = MTD_OPS_AUTO_OOB;
ops.len = 0; ops.len = 0;
ops.retlen = 0; ops.retlen = 0;
...@@ -182,7 +164,7 @@ static int verify_eraseblock(int ebnum) ...@@ -182,7 +164,7 @@ static int verify_eraseblock(int ebnum)
loff_t addr = ebnum * mtd->erasesize; loff_t addr = ebnum * mtd->erasesize;
for (i = 0; i < pgcnt; ++i, addr += mtd->writesize) { for (i = 0; i < pgcnt; ++i, addr += mtd->writesize) {
set_random_data(writebuf, use_len); prandom_bytes_state(&rnd_state, writebuf, use_len);
ops.mode = MTD_OPS_AUTO_OOB; ops.mode = MTD_OPS_AUTO_OOB;
ops.len = 0; ops.len = 0;
ops.retlen = 0; ops.retlen = 0;
...@@ -273,7 +255,7 @@ static int verify_eraseblock_in_one_go(int ebnum) ...@@ -273,7 +255,7 @@ static int verify_eraseblock_in_one_go(int ebnum)
loff_t addr = ebnum * mtd->erasesize; loff_t addr = ebnum * mtd->erasesize;
size_t len = mtd->ecclayout->oobavail * pgcnt; size_t len = mtd->ecclayout->oobavail * pgcnt;
set_random_data(writebuf, len); prandom_bytes_state(&rnd_state, writebuf, len);
ops.mode = MTD_OPS_AUTO_OOB; ops.mode = MTD_OPS_AUTO_OOB;
ops.len = 0; ops.len = 0;
ops.retlen = 0; ops.retlen = 0;
...@@ -424,12 +406,12 @@ static int __init mtd_oobtest_init(void) ...@@ -424,12 +406,12 @@ static int __init mtd_oobtest_init(void)
if (err) if (err)
goto out; goto out;
simple_srand(1); prandom_seed_state(&rnd_state, 1);
err = write_whole_device(); err = write_whole_device();
if (err) if (err)
goto out; goto out;
simple_srand(1); prandom_seed_state(&rnd_state, 1);
err = verify_all_eraseblocks(); err = verify_all_eraseblocks();
if (err) if (err)
goto out; goto out;
...@@ -444,13 +426,13 @@ static int __init mtd_oobtest_init(void) ...@@ -444,13 +426,13 @@ static int __init mtd_oobtest_init(void)
if (err) if (err)
goto out; goto out;
simple_srand(3); prandom_seed_state(&rnd_state, 3);
err = write_whole_device(); err = write_whole_device();
if (err) if (err)
goto out; goto out;
/* Check all eraseblocks */ /* Check all eraseblocks */
simple_srand(3); prandom_seed_state(&rnd_state, 3);
pr_info("verifying all eraseblocks\n"); pr_info("verifying all eraseblocks\n");
for (i = 0; i < ebcnt; ++i) { for (i = 0; i < ebcnt; ++i) {
if (bbt[i]) if (bbt[i])
...@@ -479,7 +461,7 @@ static int __init mtd_oobtest_init(void) ...@@ -479,7 +461,7 @@ static int __init mtd_oobtest_init(void)
use_len = mtd->ecclayout->oobavail; use_len = mtd->ecclayout->oobavail;
use_len_max = mtd->ecclayout->oobavail; use_len_max = mtd->ecclayout->oobavail;
vary_offset = 1; vary_offset = 1;
simple_srand(5); prandom_seed_state(&rnd_state, 5);
err = write_whole_device(); err = write_whole_device();
if (err) if (err)
...@@ -490,7 +472,7 @@ static int __init mtd_oobtest_init(void) ...@@ -490,7 +472,7 @@ static int __init mtd_oobtest_init(void)
use_len = mtd->ecclayout->oobavail; use_len = mtd->ecclayout->oobavail;
use_len_max = mtd->ecclayout->oobavail; use_len_max = mtd->ecclayout->oobavail;
vary_offset = 1; vary_offset = 1;
simple_srand(5); prandom_seed_state(&rnd_state, 5);
err = verify_all_eraseblocks(); err = verify_all_eraseblocks();
if (err) if (err)
goto out; goto out;
...@@ -649,7 +631,7 @@ static int __init mtd_oobtest_init(void) ...@@ -649,7 +631,7 @@ static int __init mtd_oobtest_init(void)
goto out; goto out;
/* Write all eraseblocks */ /* Write all eraseblocks */
simple_srand(11); prandom_seed_state(&rnd_state, 11);
pr_info("writing OOBs of whole device\n"); pr_info("writing OOBs of whole device\n");
for (i = 0; i < ebcnt - 1; ++i) { for (i = 0; i < ebcnt - 1; ++i) {
int cnt = 2; int cnt = 2;
...@@ -659,7 +641,7 @@ static int __init mtd_oobtest_init(void) ...@@ -659,7 +641,7 @@ static int __init mtd_oobtest_init(void)
continue; continue;
addr = (i + 1) * mtd->erasesize - mtd->writesize; addr = (i + 1) * mtd->erasesize - mtd->writesize;
for (pg = 0; pg < cnt; ++pg) { for (pg = 0; pg < cnt; ++pg) {
set_random_data(writebuf, sz); prandom_bytes_state(&rnd_state, writebuf, sz);
ops.mode = MTD_OPS_AUTO_OOB; ops.mode = MTD_OPS_AUTO_OOB;
ops.len = 0; ops.len = 0;
ops.retlen = 0; ops.retlen = 0;
...@@ -680,12 +662,13 @@ static int __init mtd_oobtest_init(void) ...@@ -680,12 +662,13 @@ static int __init mtd_oobtest_init(void)
pr_info("written %u eraseblocks\n", i); pr_info("written %u eraseblocks\n", i);
/* Check all eraseblocks */ /* Check all eraseblocks */
simple_srand(11); prandom_seed_state(&rnd_state, 11);
pr_info("verifying all eraseblocks\n"); pr_info("verifying all eraseblocks\n");
for (i = 0; i < ebcnt - 1; ++i) { for (i = 0; i < ebcnt - 1; ++i) {
if (bbt[i] || bbt[i + 1]) if (bbt[i] || bbt[i + 1])
continue; continue;
set_random_data(writebuf, mtd->ecclayout->oobavail * 2); prandom_bytes_state(&rnd_state, writebuf,
mtd->ecclayout->oobavail * 2);
addr = (i + 1) * mtd->erasesize - mtd->writesize; addr = (i + 1) * mtd->erasesize - mtd->writesize;
ops.mode = MTD_OPS_AUTO_OOB; ops.mode = MTD_OPS_AUTO_OOB;
ops.len = 0; ops.len = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment