Commit be54f8f1 authored by Akinobu Mita's avatar Akinobu Mita Committed by Brian Norris

mtd: mtd_oobtest: generate consistent data for verification

mtd_oobtest writes OOB, read it back and verify.  The verification is
not correctly done if oobsize is not multiple of 4.  Although the data
to be written and the data to be compared are generated by several
prandom_byte_state() calls starting with the same seed, these two are
generated with the different size and different number of calls.

Due to the implementation of prandom_byte_state() if the size on each
call is not multiple of 4, the resulting data is not always same.

This fixes it by just calling prandom_byte_state() once and using
correct range instead of calling it multiple times for each.
Reported-by: default avatarGeorge Cherian <george.cherian@ti.com>
Reported-by: default avatarLothar Waßmann <LW@KARO-electronics.de>
Tested-by: default avatarLothar Waßmann <LW@KARO-electronics.de>
Cc: George Cherian <george.cherian@ti.com>
Cc: Lothar Waßmann <LW@KARO-electronics.de>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: Lee Jones <lee.jones@linaro.org>
Cc: linux-mtd@lists.infradead.org
Signed-off-by: default avatarAkinobu Mita <akinobu.mita@gmail.com>
Signed-off-by: default avatarBrian Norris <computersforpeace@gmail.com>
parent d66d3519
...@@ -69,8 +69,8 @@ static int write_eraseblock(int ebnum) ...@@ -69,8 +69,8 @@ static int write_eraseblock(int ebnum)
int err = 0; int err = 0;
loff_t addr = ebnum * mtd->erasesize; loff_t addr = ebnum * mtd->erasesize;
prandom_bytes_state(&rnd_state, writebuf, use_len_max * pgcnt);
for (i = 0; i < pgcnt; ++i, addr += mtd->writesize) { for (i = 0; i < pgcnt; ++i, addr += mtd->writesize) {
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;
...@@ -78,7 +78,7 @@ static int write_eraseblock(int ebnum) ...@@ -78,7 +78,7 @@ static int write_eraseblock(int ebnum)
ops.oobretlen = 0; ops.oobretlen = 0;
ops.ooboffs = use_offset; ops.ooboffs = use_offset;
ops.datbuf = NULL; ops.datbuf = NULL;
ops.oobbuf = writebuf; ops.oobbuf = writebuf + (use_len_max * i) + use_offset;
err = mtd_write_oob(mtd, addr, &ops); err = mtd_write_oob(mtd, addr, &ops);
if (err || ops.oobretlen != use_len) { if (err || ops.oobretlen != use_len) {
pr_err("error: writeoob failed at %#llx\n", pr_err("error: writeoob failed at %#llx\n",
...@@ -122,8 +122,8 @@ static int verify_eraseblock(int ebnum) ...@@ -122,8 +122,8 @@ static int verify_eraseblock(int ebnum)
int err = 0; int err = 0;
loff_t addr = ebnum * mtd->erasesize; loff_t addr = ebnum * mtd->erasesize;
prandom_bytes_state(&rnd_state, writebuf, use_len_max * pgcnt);
for (i = 0; i < pgcnt; ++i, addr += mtd->writesize) { for (i = 0; i < pgcnt; ++i, addr += mtd->writesize) {
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;
...@@ -139,7 +139,8 @@ static int verify_eraseblock(int ebnum) ...@@ -139,7 +139,8 @@ static int verify_eraseblock(int ebnum)
errcnt += 1; errcnt += 1;
return err ? err : -1; return err ? err : -1;
} }
if (memcmp(readbuf, writebuf, use_len)) { if (memcmp(readbuf, writebuf + (use_len_max * i) + use_offset,
use_len)) {
pr_err("error: verify failed at %#llx\n", pr_err("error: verify failed at %#llx\n",
(long long)addr); (long long)addr);
errcnt += 1; errcnt += 1;
...@@ -166,7 +167,9 @@ static int verify_eraseblock(int ebnum) ...@@ -166,7 +167,9 @@ static int verify_eraseblock(int ebnum)
errcnt += 1; errcnt += 1;
return err ? err : -1; return err ? err : -1;
} }
if (memcmp(readbuf + use_offset, writebuf, use_len)) { if (memcmp(readbuf + use_offset,
writebuf + (use_len_max * i) + use_offset,
use_len)) {
pr_err("error: verify failed at %#llx\n", pr_err("error: verify failed at %#llx\n",
(long long)addr); (long long)addr);
errcnt += 1; errcnt += 1;
...@@ -566,8 +569,8 @@ static int __init mtd_oobtest_init(void) ...@@ -566,8 +569,8 @@ static int __init mtd_oobtest_init(void)
if (bbt[i] || bbt[i + 1]) if (bbt[i] || bbt[i + 1])
continue; continue;
addr = (i + 1) * mtd->erasesize - mtd->writesize; addr = (i + 1) * mtd->erasesize - mtd->writesize;
prandom_bytes_state(&rnd_state, writebuf, sz * cnt);
for (pg = 0; pg < cnt; ++pg) { for (pg = 0; pg < cnt; ++pg) {
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;
...@@ -575,7 +578,7 @@ static int __init mtd_oobtest_init(void) ...@@ -575,7 +578,7 @@ static int __init mtd_oobtest_init(void)
ops.oobretlen = 0; ops.oobretlen = 0;
ops.ooboffs = 0; ops.ooboffs = 0;
ops.datbuf = NULL; ops.datbuf = NULL;
ops.oobbuf = writebuf; ops.oobbuf = writebuf + pg * sz;
err = mtd_write_oob(mtd, addr, &ops); err = mtd_write_oob(mtd, addr, &ops);
if (err) if (err)
goto out; goto out;
......
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