mtd: mtd_oobtest: generate consitent data for verification
PATCH 1/1 mtd: mtd_oobtest: generate consitent 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.
--- drivers/mtd/tests/oobtest.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-)
drivers/mtd/tests/oobtest.c +10 -7
@@ -69,8 +69,8 @@ static int write_eraseblock(int ebnum)int err =0 ;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) { -prandom_bytes_state (&rnd_state, writebuf, use_len); ops.mode =MTD_OPS_AUTO_OOB ; ops.len =0 ; ops.retlen =0 ;
@@ -78,7 +78,7 @@ static int write_eraseblock(int ebnum) ops.oobretlen =0 ; ops.ooboffs = use_offset; ops.datbuf =NULL ; - ops.oobbuf = writebuf; + ops.oobbuf = writebuf + use_len_max * i + use_offset; err =mtd_write_oob (mtd, addr, &ops);if (err || ops.oobretlen != use_len) { pr_err("error: writeoob failed at %#llx\n",
@@ -120,8 +120,8 @@ static int verify_eraseblock(int ebnum)int err =0 ;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) { -prandom_bytes_state (&rnd_state, writebuf, use_len); ops.mode =MTD_OPS_AUTO_OOB ; ops.len =0 ; ops.retlen =0 ;
@@ -137,7 +137,8 @@ static int verify_eraseblock(int ebnum) errcnt +=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" , (long long )addr); errcnt +=1 ;
@@ -164,7 +165,9 @@ static int verify_eraseblock(int ebnum) errcnt +=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" , (long long )addr); errcnt +=1 ;
@@ -559,8 +562,8 @@ static int __init mtd_oobtest_init(void)if (test_bit (i, bbt) ||test_bit (i +1 , bbt))continue ; addr = (i +1 ) * mtd->erasesize - mtd->writesize; +prandom_bytes_state (&rnd_state, writebuf, sz * cnt);for (pg =0 ; pg < cnt; ++pg) { -prandom_bytes_state (&rnd_state, writebuf, sz); ops.mode =MTD_OPS_AUTO_OOB ; ops.len =0 ; ops.retlen =0 ;
@@ -568,7 +571,7 @@ static int __init mtd_oobtest_init(void) ops.oobretlen =0 ; ops.ooboffs =0 ; ops.datbuf =NULL ; - ops.oobbuf = writebuf; + ops.oobbuf = writebuf + pg * sz; err =mtd_write_oob (mtd, addr, &ops);if (err) goto out;
Signature · 1 line
1.8.3.2
Quoted 12 lines · Akinobu Mita
mtd_oobtestwrites 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 severalprandom_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.
Quoted 8 lines
Reported-by George Cherian <[email protected]>Reported-by Lothar Waßmann <[email protected]>Cc George Cherian <[email protected]>Cc Lothar Waßmann <[email protected]>Cc David Woodhouse <[email protected]>Cc Brian Norris <[email protected]>Signed-off-by Akinobu Mita <[email protected]>
This patch does not apply for me. Are you based on l2-mtd.git?
Brian
2014-03-06 18:25 GMT+09:00 Brian Norris <[email protected]>:
Quoted 22 lines · Akinobu Mita
Quoted 12 lines
mtd_oobtestwrites 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 severalprandom_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.Quoted 8 lines
Reported-by George Cherian <[email protected]>Reported-by Lothar Waßmann <[email protected]>Cc George Cherian <[email protected]>Cc Lothar Waßmann <[email protected]>Cc David Woodhouse <[email protected]>Cc Brian Norris <[email protected]>Signed-off-by Akinobu Mita <[email protected]>
Quoted 1 line
This patch does not apply for me. Are you based on l2-mtd.git?
Oops, this patch depends on a cleanup patch which I haven't submitted yet. I'll send a correct patch soon.