Skip to content

Commit

Permalink
mtd: mtd_subpagetest: convert to use prandom library
Browse files Browse the repository at this point in the history
This removes home-brewed pseudo-random number generator and use
prandom library.

Signed-off-by: Akinobu Mita <[email protected]>
Cc: Artem Bityutskiy <[email protected]>
Cc: David Woodhouse <[email protected]>
Cc: "Theodore Ts'o" <[email protected]>
Cc: Adrian Hunter <[email protected]>
Cc: David Laight <[email protected]>
Cc: Eilon Greenstein <[email protected]>
Cc: Michel Lespinasse <[email protected]>
Cc: Robert Love <[email protected]>
Cc: Valdis Kletnieks <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
mita authored and torvalds committed Feb 28, 2013
1 parent 99672f3 commit a312b78
Showing 1 changed file with 12 additions and 30 deletions.
42 changes: 12 additions & 30 deletions drivers/mtd/tests/mtd_subpagetest.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <linux/mtd/mtd.h>
#include <linux/slab.h>
#include <linux/sched.h>
#include <linux/random.h>

static int dev = -EINVAL;
module_param(dev, int, S_IRUGO);
Expand All @@ -43,26 +44,7 @@ static int bufsize;
static int ebcnt;
static int pgcnt;
static int errcnt;
static unsigned long next = 1;

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 struct rnd_state rnd_state;

static inline void clear_data(unsigned char *buf, size_t len)
{
Expand Down Expand Up @@ -119,7 +101,7 @@ static int write_eraseblock(int ebnum)
int err = 0;
loff_t addr = ebnum * mtd->erasesize;

set_random_data(writebuf, subpgsize);
prandom_bytes_state(&rnd_state, writebuf, subpgsize);
err = mtd_write(mtd, addr, subpgsize, &written, writebuf);
if (unlikely(err || written != subpgsize)) {
pr_err("error: write failed at %#llx\n",
Expand All @@ -133,7 +115,7 @@ static int write_eraseblock(int ebnum)

addr += subpgsize;

set_random_data(writebuf, subpgsize);
prandom_bytes_state(&rnd_state, writebuf, subpgsize);
err = mtd_write(mtd, addr, subpgsize, &written, writebuf);
if (unlikely(err || written != subpgsize)) {
pr_err("error: write failed at %#llx\n",
Expand All @@ -157,7 +139,7 @@ static int write_eraseblock2(int ebnum)
for (k = 1; k < 33; ++k) {
if (addr + (subpgsize * k) > (ebnum + 1) * mtd->erasesize)
break;
set_random_data(writebuf, subpgsize * k);
prandom_bytes_state(&rnd_state, writebuf, subpgsize * k);
err = mtd_write(mtd, addr, subpgsize * k, &written, writebuf);
if (unlikely(err || written != subpgsize * k)) {
pr_err("error: write failed at %#llx\n",
Expand Down Expand Up @@ -193,7 +175,7 @@ static int verify_eraseblock(int ebnum)
int err = 0;
loff_t addr = ebnum * mtd->erasesize;

set_random_data(writebuf, subpgsize);
prandom_bytes_state(&rnd_state, writebuf, subpgsize);
clear_data(readbuf, subpgsize);
err = mtd_read(mtd, addr, subpgsize, &read, readbuf);
if (unlikely(err || read != subpgsize)) {
Expand All @@ -220,7 +202,7 @@ static int verify_eraseblock(int ebnum)

addr += subpgsize;

set_random_data(writebuf, subpgsize);
prandom_bytes_state(&rnd_state, writebuf, subpgsize);
clear_data(readbuf, subpgsize);
err = mtd_read(mtd, addr, subpgsize, &read, readbuf);
if (unlikely(err || read != subpgsize)) {
Expand Down Expand Up @@ -257,7 +239,7 @@ static int verify_eraseblock2(int ebnum)
for (k = 1; k < 33; ++k) {
if (addr + (subpgsize * k) > (ebnum + 1) * mtd->erasesize)
break;
set_random_data(writebuf, subpgsize * k);
prandom_bytes_state(&rnd_state, writebuf, subpgsize * k);
clear_data(readbuf, subpgsize * k);
err = mtd_read(mtd, addr, subpgsize * k, &read, readbuf);
if (unlikely(err || read != subpgsize * k)) {
Expand Down Expand Up @@ -430,7 +412,7 @@ static int __init mtd_subpagetest_init(void)
goto out;

pr_info("writing whole device\n");
simple_srand(1);
prandom_seed_state(&rnd_state, 1);
for (i = 0; i < ebcnt; ++i) {
if (bbt[i])
continue;
Expand All @@ -443,7 +425,7 @@ static int __init mtd_subpagetest_init(void)
}
pr_info("written %u eraseblocks\n", i);

simple_srand(1);
prandom_seed_state(&rnd_state, 1);
pr_info("verifying all eraseblocks\n");
for (i = 0; i < ebcnt; ++i) {
if (bbt[i])
Expand All @@ -466,7 +448,7 @@ static int __init mtd_subpagetest_init(void)
goto out;

/* Write all eraseblocks */
simple_srand(3);
prandom_seed_state(&rnd_state, 3);
pr_info("writing whole device\n");
for (i = 0; i < ebcnt; ++i) {
if (bbt[i])
Expand All @@ -481,7 +463,7 @@ static int __init mtd_subpagetest_init(void)
pr_info("written %u eraseblocks\n", i);

/* Check all eraseblocks */
simple_srand(3);
prandom_seed_state(&rnd_state, 3);
pr_info("verifying all eraseblocks\n");
for (i = 0; i < ebcnt; ++i) {
if (bbt[i])
Expand Down

0 comments on commit a312b78

Please sign in to comment.